int ledPin = 13; // declare pin for led int sensorPin1 = 7; // declare pin sensor output int sensorPin2 = 8; int sensorState1 = 1; // sensor state when line of sight is not broken is HIGH int sensorState2 = 1; int count = 0; // variable to keep track of how many time button was pushed int previousState1 = 1; // variable to remember what previous state the sensor was int previousState2 = 1; void print_to_lcd(int number) { // function to display number to lcd } void setup(){ // put your setup code here, to run once: pinMode (ledPin, OUTPUT); // to control the led pinMode (sensorPin1, INPUT); // to read the button state pinMode (sensorPin2, INPUT); Serial.begin(9600); // start communication with PC } void loop() { // put your main code here, to run repeatedly: previousState1 = sensorState1; // save the previous state before reading the new state previousState2 = sensorState2; sensorState1 = digitalRead(sensorPin1); // read the new state of sensor sensorState2 = digitalRead(sensorPin2); if (sensorState1 == HIGH && previousState1 == LOW) { // if sensor 1 was covered, then see again, means a person entered count = count + 1; delay(200); // debounce Serial.println(count); print_to_lcd(count); } if (sensorState2 == HIGH && previousState2 == LOW) { // if sensor 2 was covered, then see again, means a person exited count = count - 1; delay(200); // debounce Serial.println(count); print_to_lcd(count); } }