code:-
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int Sensora = 2;
const int sensorB = 3;
const int output = 13;
int count = 0;
boolean sensorATriggered = false;
unsigned long sensorATime;
byte currStateA;
byte prevStateA = HIGH;
boolean sensorBTriggered = false;
unsigned long sensorBTime;
byte currStateB ;
byte prevStateB = HIGH;
void setup () {
lcd.begin();
lcd.backlight();
Serial.begin (9600);
pinMode (Sensora, INPUT);
pinMode (sensorB, INPUT);
pinMode (output, OUTPUT);
lcd.print(" No of visitors ");
}
void loop () {
lcd.setCursor(8,1);
currStateA = digitalRead (Sensora);
if (currStateA != prevStateA)
{
if (currStateA == LOW)
{
sensorATriggered = true;
sensorATime = millis ();
}
}
// prevStateA = currStateA;
currStateB = digitalRead (sensorB);
if (currStateB != prevStateB)
{
if (currStateB == LOW)
{
sensorBTriggered = true;
sensorBTime = millis ();
}
}
// prevStateB = currStateB;
if (sensorBTriggered && sensorATriggered)
{
if (sensorATime> sensorBTime)
{
count ++;
Serial.println(count);
delay(500);
}
if (sensorBTime> sensorATime)
{
count--;
Serial.println(count);
delay(500);
}
sensorATriggered = false;
sensorBTriggered = false;
}
lcd.print(count);
lcd.print(" ");
}
Circuit diagram and all ppt send
ReplyDeleteCan you send updated code
ReplyDelete