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.
Sensor.
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.

Program.
ORG 000H
SJMP INIT
ORG 003H // starting address of interrupt service routine (ISR)
ACALL ISR // calls interrupt service routine
RETI
INIT: MOV P0,#00000000B
MOV P3,#11111111B
MOV P1,#00000000B
MOV R6,#00000000B
MOV DPTR,#LUT
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
MAIN: MOV A,R6
MOV B,#100D
DIV AB
ACALL DISPLAY
SETB P1.0
ACALL DELAY
ACALL DELAY
MOV A,B
MOV B,#10D
DIV AB
ACALL DISPLAY
CLR P1.0
SETB P1.1
ACALL DELAY
ACALL DELAY
MOV A,B
ACALL DISPLAY
CLR P1.1
SETB P1.2
ACALL DELAY
ACALL DELAY
CLR P1.2
SJMP MAIN
ISR: INC R6 //interrupt service routine
RET
DISPLAY: MOVC A,@A+DPTR // display sub routine
CPL A
MOV P0,A
RET
DELAY: MOV R3,#255D // 1mS delay
LABEL: DJNZ R3,LABEL
RET
LUT: DB 3FH
DB 06H
DB 5BH
DB 4FH
DB 66H
DB 6DH
DB 7DH
DB 07H
DB 7FH
DB 6FH
END
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.
Notes.
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.

I used IR sensors and my project is automatically counting with any objects when power is given can u tell me the possible errors
which software can be used to compile the code
Which type of seven segment it os??anode or cathode?
can u provide me the block diagram for this project
can anyone please explain the circuit diagram briefly say the functions of the components used especially the resistors. will be very grateful. regards
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
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 ?
Can I see your code
Plz help me to convert this program into c language …
Hello Sir I am using Proteus isis 7 simulator.
my counter is not working, displaying 000 plz give me some advice
Sir, plzzz suggest software for this program.
which seven seg display is used?common anode or cathode
can i use IR sensor for this?
itz not working…..please help
it was good
sir plz tell me which 7 segment display can i use in the project common anode or common cathode
Which type of seven segment it os??anode or cathode?
What type of 7 segment display is used? Please tell asap. I really need it.
Can anyone please send a report on this circuit if they have made?
Thanks a lot..it’s working just fine.
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
which type of led…common anode or cathode
its not working….. comparator is not changing its state from low to high or from high to low.. please help… as soon as possible..
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?
Thanks.which software can be used to compile the code
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
Safoor