CIRCUIT DIAGRAM :-
CODE :-
#include <LiquidCrystal.h>
int rs=7;
int en=8;
int d4=9;
int d5=10;
int d6=11;
int d7=12;
int ir1=4;
int ir2=2;
int val1;
int val2;
int count=0;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
void setup() {
// put your setup code here, to run once:
pinMode(ir1,INPUT);
pinMode(ir2,INPUT);
Serial.begin(9600);
lcd.begin(16,2);
lcd.print("Person In Room:");
lcd.setCursor(0,1);
lcd.print(count);
}
void loop() {
// put your main code here, to run repeatedly:
val1=digitalRead(ir1);
val2=digitalRead(ir2);
if (val1==0) {
count=count+1;
Serial.println(count);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Person In Room:");
lcd.setCursor(0,1);
lcd.print(count);
delay(1000);
}
if (val2==0) {
count=count-1;
Serial.println(count);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Person In Room:");
lcd.setCursor(0,1);
lcd.print(count);
delay(1000);
}
}
0 Comments