-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch_dec03e.ino
79 lines (67 loc) · 1.55 KB
/
sketch_dec03e.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#define sensorPin1 7
#define sensorPin2 8
//#define relay 3
int sensorState1 = 0;
int sensorState2 = 0;
int count=0;
void setup()
{
lcd.init(); // initialize the lcd
lcd.init();
Serial.begin(9600);
pinMode (sensorPin1,INPUT_PULLUP);
pinMode (sensorPin2,INPUT_PULLUP);
// pinMode(relay, OUTPUT);
// lcd.begin(16,2);
lcd.backlight();
lcd.setCursor(4,0);
lcd.print("COUNTER");
Serial.print("COUNTER");
lcd.setCursor(0,1);
lcd.print("No Visitors ");
Serial.print("No Visitors ");
delay(200);
}
void loop()
{
sensorState1 = digitalRead(sensorPin1);
sensorState2 = digitalRead(sensorPin2);
if(sensorState1 == LOW){
count++;
delay(500);
}
if(sensorState2 == LOW){
count--;
delay(500);
}
if(count<=0)
{
// digitalWrite(relay, LOW);
lcd.setCursor(0,1);
lcd.print("No visitors ");
Serial.println("No visitors ");
}
else if (count>0 && count<10){
// digitalWrite(relay, HIGH);
lcd.setCursor(0,1);
lcd.print("Visitors: ");
Serial.println("Visitors:");
lcd.setCursor(12,1);
lcd.print(count);
Serial.println(count);
lcd.setCursor(13,1);
lcd.print(" ");
}
else {
// digitalWrite(relay, HIGH);
lcd.setCursor(0,1);
lcd.print("Visitors: ");
Serial.println("Visitors:");
lcd.setCursor(12,1);
lcd.print(count);
Serial.println(count);
}
}