Object counter using 8051 microcontroller.

This article is about a simple object counter/visitor counter using 8051 microcontroller . AT89S51 belonging to the 8051 family is the microcontroller used here. This circuit can count the number of objects passing across a line , number of persons passing through a gate/door and so on. The can be simply divided into two sections i.e. the sensor section and the display section.


The sensor part consists of a ultra bright led (with focus), and LDR, opamp LM324 and the associated passive components. The LED is placed on one side of the door and the LDR is placed on the other side so that the light from the LED falls directly on the LDR.As you know, the resistance of the LDR has an inverse relationship with the intensity of the light falling on it. The preset resistor R14 is so adjusted that the voltage across the LDR is below 1.5V when it is illuminated. This voltage (labelled A in the circuit diagram) is connected to the inverting input of the opamp which is wired as a comparator with reference voltage 1.5V (set using R15 and R16).Capacitor C1 is meant for bypassing noise or anything like that which may cause false triggering.Resistor R13 is meant to control the current through the LED.

When the light is falling on the LDR the voltage across it will be less than the reference voltage and so the output of the opamp remains high. When the light beam is interrupted, the voltage across the LDR goes above the reference voltage and so the opamp output goes low and it indicates a pass.

Display section.

The output of the opamp is fed to the INTO (interrupt 0) pin of the microcontroller. The microcontroller is programmed to count the number of negative edge pulses received at the INT0 pin and displays it on the three digit seven segment display.

Circuit diagram.

visitor counter using 8051
Object counter using 8051


ORG 000H
ORG 003H  // starting address of interrupt service routine (ISR)
ACALL ISR // calls interrupt service routine

INIT: MOV P0,#00000000B
      MOV P3,#11111111B
      MOV P1,#00000000B
      MOV R6,#00000000B
      SETB IP.0     // sets highest priority for the interrupt INT0
      SETB TCON.0   // interrupt generated by a falling edge signal at INT0 pin
      SETB IE.0     //enables the external interrupt
      SETB IE.7     //enables the global interrupt control

      MOV B,#100D
      DIV AB
      SETB P1.0
      MOV A,B
      MOV B,#10D
      DIV AB
      CLR P1.0
      SETB P1.1
      MOV A,B
      CLR P1.1
      SETB P1.2
      CLR P1.2

ISR: INC R6     //interrupt service routine

DISPLAY: MOVC A,@A+DPTR // display sub routine
         CPL A
         MOV P0,A

DELAY: MOV R3,#255D  // 1mS delay
     DB 06H
     DB 5BH
     DB 4FH
     DB 66H
     DB 6DH
     DB 7DH
     DB 07H
     DB 7FH
     DB 6FH

About the program.

The program is written so that, it keeps displaying the current value in register R6 on the three digit seven segment display. When ever there is a valid negative going pulse (interrupt) at the INT0 pin, the program branches to the interrupt service routine (sub routine ISR). Subroutine ISR increments the value in register R6, then jumps back to the MAIN loop and the display gets updated by the new value.


Entire circuit can be powered from a 5V DC supply.

LDR must be placed in an enclosure so that the light from LED alone falls on it.





  1. I used IR sensors and my project is automatically counting with any objects when power is given can u tell me the possible errors

  2. which software can be used to compile the code

  3. Which type of seven segment it os??anode or cathode?

  4. sharnitha

    can u provide me the block diagram for this project

  5. Sajor Barrie

    can anyone please explain the circuit diagram briefly say the functions of the components used especially the resistors. will be very grateful. regards

  6. Sajor Barrie

    hello helper. please i want to know the specific componenets to be used say for example the 7-segment display type and also the type of programming language used.regards

  7. Umang khatri

    Thanks, It’s working.
    I’ve used Common Anode 7 segment for this. Only problem i faced was- Reset function at pin9. Project started working when i removed all connections from pin9 of 8051.
    Thanks again.

    • if you remove the connections from pin 9 , then where did you connect the reset button ?

  8. Plz help me to convert this program into c language …

  9. Hello Sir I am using Proteus isis 7 simulator.
    my counter is not working, displaying 000 plz give me some advice

  10. Sir, plzzz suggest software for this program.

  11. sagar khandale

    which seven seg display is used?common anode or cathode

  12. asif ali khan

    sir plz tell me which 7 segment display can i use in the project common anode or common cathode

  13. Which type of seven segment it os??anode or cathode?

  14. Ankit DHall

    What type of 7 segment display is used? Please tell asap. I really need it.

  15. Can anyone please send a report on this circuit if they have made?

    • really?? how can you do that? please i need your help for my final year project. i you can reply my amail as soon as posibble, really2 appriciate it. thanks

  16. ratnesh thepade

    its not working….. comparator is not changing its state from low to high or from high to low.. please help… as soon as possible..

  17. Kornell Azih

    I am relatively new in programming, what type compiler did you use for the writing of this program, because I tried to build it with mide-51 ut gave ne 9 errors?

  18. Thanks.which software can be used to compile the code

  19. Dear sir,
    Its an interesting circuit to put in practice thanks for that, but I would like to understand how the programming is done and to load it. Also to learn how to program it, so that we can create our own.
    Thanks And regards