-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminorsen1.ino
73 lines (66 loc) · 1.39 KB
/
minorsen1.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
#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
#define in 8
#define out 9
#define led 13 // the pin the LED is connected to
/*
#define relay 7
*/
unsigned count=0;
int Contrast=120;
void setup()
{
lcd.clear();
pinMode(led, OUTPUT); // Declare the LED as an output
digitalWrite(led, LOW); // Turn the LED off
analogWrite(6,Contrast);
lcd.begin(16,2);
lcd.print("Visitor Counter");
delay(2000);
pinMode(in, INPUT);
pinMode(out, INPUT);
//pinMode(relay, OUTPUT);
lcd.clear();
lcd.print("Person In Room:");
lcd.setCursor(0,1);
lcd.print(count);
}
void loop()
{
int in_value = digitalRead(in);
int out_value = digitalRead(out);
if(in_value == LOW)
{
count++;
lcd.clear();
lcd.print("Person In Room:");
lcd.setCursor(0,1);
lcd.print(count);
delay(1000);
}
if((out_value == LOW) && (count!=0))
{
count--;
lcd.clear();
lcd.print("Person In Room:");
lcd.setCursor(0,1);
lcd.print(count);
delay(1000);
}
if(count==0)
{
lcd.clear();
//digitalWrite(relay, HIGH);
digitalWrite(led, LOW); // Turn the LED off
lcd.clear();
lcd.print("Nobody in Room");
lcd.setCursor(0,1);
lcd.print("Light is Off");
delay(200);
}
else
{
//digitalWrite(relay, LOW);
digitalWrite(led, HIGH); // Turn the LED on
}
}