This circuit can count number of persons entering a premise or number of objects passing in front of an IR sensor. The code works very nicely and fully tested in our lab.
Note that a buzzer for short beeps is connected at pin-2 and the IR sensor is connected at pin-5. The delay in second “if” conditional statement is used to avoid accidental triggering of the sensor.
You can check the output of the counter on SERIAL MONITOR of Arduino IDE. First burn the code in your Arduino kit and then click on “Tools” menu in Arduino IDE and then click Serial Monitor to check the output of the counter.
The Code
/* * Object counter using Arduino * Code designed by Vidyasagar Academy * www.vsa.edu.in */ int counter=0; // variable to count the objects void setup() { Serial.begin(9600); pinMode(1,OUTPUT); // buzzer at pin-1 pinMode(5,INPUT); // IR sensor at pin-5 } void loop() { if(digitalRead(5)==HIGH) { digitalWrite(1,LOW); } if(digitalRead(5)==LOW) { digitalWrite(1,HIGH); counter++; delay(100); digitalWrite(1,LOW); Serial.print("Total Objects: "); Serial.println(counter); delay(1000); } }