Introduction: Arduino-DIY Laser / IR Person Counter

Picture of Arduino-DIY Laser / IR Person Counter

A Bi-Directional person / object counter is a device which can be used to monitor the number of objects entering / exiting through it. It has a wide range of applications including automatic parking slots monitoring , number of people entering / exiting a mall , number of students in a class , et cetera.

It has two variants :

1. Laser diode and LDR combination

2. IR led and photodiode combination

The laserdiode-LDR version can be used where the distance between the source ( laserdiode ) and the sensor ( LDR ) is large whereas the IR-PhotoDiode can only be used for short distances and is comparatively less accurate.

Step 1: Part List

Picture of Part List

Parts you'll need for making this project :

1.2 x Laser-Diodes ( I've used a laser-diode from a red laser pointer - 635nm and <1mW )

2. 2 x Small LDRs

3. 2 x 10k ohm resistors

4. 1 x 7805 - 5v voltage reg.

5. Arduino ( any microcontroller would serve the purpose )

6. Heat Shrink tubing ( 4mm )

7. PerfBoard

8. 9v battries and battery connectors

Step 2: Schematics

Picture of Schematics

Circuit # 1 :

Two LDRs are connected to the A0 and A1 analog pins of arduino . One leg of the LDR is grounded and the other end is connected to +5v through a 10k ohm pull-up resistor. The Junction of the LDR's leg and the resistor is connected to the analog pin.

When the resistance of the LDR goes below 10k ohm , the analog pin reads 0 v and if it goes above 10k ohm , the analog values will be displayed accordingly.

Circuit # 2 :

This circuit just converts 9v to 5v using 7805 voltage regulator to drive the Laser Diodes. A 10k ohm pot is added to protect the Laser Diodes. Two laser diodes are connected in parallel to the power source.

Display Circuit :

If you don't want to use the serial monitor to display the counter values then you can add 2 x seven segment displays to the arduino's digital pins as shown ( you can also use a multiplexer if you want ).

Step 3: Layout and Working

Picture of Layout and Working

There're two parts of the counter :

1. Laser source

2. Sensor plate


The two laser diodes are connected in parallel to a +5v regulated power source. On the other side , two LDRs are connected to arduino . They are placed such that both the laser beams fall directly on the LDRs.

A 2 x 7 segment display is connected to the arduino to display ( total no. of objects entering - total no. of objects leaving ). This can also be done by using the Arduino serial monitor.


In normal position , the beams fall directly on the LDRs and hence the resistance of the LDRs drops down drastically . As the resistance goes below 10k Ohm , the analog pin will read a lower analog value. When an object enters , the first beam ( beam A ) breaks before second beam ( beam B ) , the counter will increase by 1 . As beam B breaks before beam A , the counter will decrease by 1.

Step 4: Programming Part

There are two programs in the Archive

1. For Serial monitor

2. For 7-segment display


Download the archive and choose your program ,

Upload it to your arduino and open the serial monitor to check the value of both the sensors in normal and breached positions and set the threshold accordingly.

After you've checked the counter and calibrated the sensors , you can now attach your LCD / seven-seg display.


The program reads the sensor values and compares them with the threshold value , in normal state the counter will be constant. As one of the beam breaks , the counter is increased or decreased by 1 . The program also calculates the time for which the object stays between the source and the sensors and suspends the program for that time duration to avoid false readings.


Feel free to ask questions and if you like my ible , please vote for me !


LeonardoV40 (author)2017-11-15

I need help, i wan tu upload the progam in the arduino and say:

Sketch uses 2272 bytes (7%) of program storage space. Maximum is 32256 bytes.

Global variables use 260 bytes (12%) of dynamic memory, leaving 1788 bytes for local variables. Maximum is 2048 bytes.

avrdude: ser_open(): can't open device "COM1": No such file or directory

Problem uploading to board. See for suggestions.

thanks for this project.

Also be free to email back:

jgupta6 (author)2017-03-23

for Laser diode and LDR combination, what can be the max distance between the two?

Mayannk (author)jgupta62017-08-15

it depends on the laser light to maintain the intensity and max distance

RaveenaG (author)2017-05-01

Hiya, ive made the entire circuit, ive made the seven segment display version. But im having problems with the programming. Random segments on the seven segment displays show up, and they don't change :( HELP

olsonb2 (author)2017-02-26


I was curious if you would be willing to make a couple of these for me? I am trying to figure out a way to monitor the number of people that pass in front of my table at a conference. There are a couple of modifications, but we can talk more about that if you are interested. Shoot me an email at



सतिशल (author)2017-02-06

friend i need help

i made ir base project using arduino uno

how to define when first time sensor output on then then off after 5 sec..

i made project when counter = 2 then do condition & counter = 3 then other condition.but problem is i want to check how many time my hand in front of ir sensor within 10 second ..also problem is when counter =3 when ir detect 3 motion but before that counter =2 condition is satisfy then this loop run after then counter = 3 condition to solve ...please help ...any expert

niketdoshi (author)2016-07-24

I would like to send count on my server and php script is runnig over there to accept the count so how could I do the same?

How can I make internet available to arduino?

thenextpro (author)niketdoshi2016-12-02

I hope you found the answer. If not, check out Arduino ethernet shield (costly option) or check out ESP8266 (extremely cheap option). PM me if you still needs more help

sahilt_75 (author)2016-07-27

will this system work without using a photodiode? we can just use the IR sensors for the detection. if sensor A gets notified first, increment the counter. if sensor B gets notified first then decrement. is that possible?

charlesl86 (author)2016-06-07

the 7 seg still not working correctly.. help?? whats the problem?

electro18 (author)charlesl862016-06-11

I need a bit more specific information about the problem that you're encountering. Did the 7 segment fry up ? and did you check the connections properly ? Try using a DMM and figure out whether it is a common anode or common cathode.

raammv made it! (author)2015-12-14

Counter is working very fine in arduino serial monitor, but there was a problem when I tried to display using LED 7 segment. Anyhow I made it and enjoyed the work.

MohamedK125 (author)raammv2016-06-08

can you help me with the ciruit to connect it ? please

raammv (author)MohamedK1252016-06-09

Yeah sure tell me where you are struck .

SagarP38 (author)raammv2016-01-04

hey ... can u tell me how to make the 7 segment work .. urgent

raammv (author)SagarP382016-01-21

Sorry for the delay. Parts Arduino board, laser light and LDR is only needed. 7405 voltage is necessary if you are using 9 v battery. Go through the instructable and you don't even need 7 segment display. You can view it in console itself.

BijanC (author)2016-04-20

I have a confussion, if some one cuts the first beam but don't cut the second beam, then returns again cutting the 1st beam, then the counter will be increased or decreased by 2,, how you have solved this problem??

Adhiambo (author)2016-03-18

How can i program write a program to allow only a set no of visitors in the room if the number is exceeded a warning is displayed?

electro18 (author)Adhiambo2016-03-30

Just add an "if" statement in the "void loop ()" function.
Something like,

if (count >= max )
*add the action you want to do after count exceeds max count*

I hope it helps :)

SagarP38 (author)2016-01-04

7 segmnt not working :( please help ...urgent

shashidattt (author)2015-11-07

where and how to place this project because we can't determine the body language and walking style of that person..............

KimC29 (author)2015-09-03

can a Raspberry Pi replace the Adruino in this case?

AbhishekR1 (author)2015-07-27

or how to attach LCD instead of 7 segment display

AbhishekR1 (author)2015-07-27

how to attach 3 or 4 digit 7 segment display

TimilehinA (author)2015-06-24

please can i get the block diagram, or can you please send it to my mail

aidil1 (author)TimilehinA2015-07-01

did you get the diagram? if you do can send it to my mail please.

shri ganesh (author)2015-06-17

how do u make ambient compensation ?

ridwanceefce (author)2015-05-18

can i ask the pin configuration if using 16 x 2 display and codes too ?

i've used the 2 of 7-segment display but it's not displaying correctly

ArchwayJourneys (author)2015-04-05

Here's a general question I'm not sure where to ask. How do I extract the "BI-Directional Couter.rar" code ?

tribosta (author)2015-03-31

I have a question about the combinations.. can i use laser diode and LDR combination in short range?

ralphmark (author)2015-03-06

I have a question about the 7seg display if i want to use anode or cathode. Does it matter either way ? My instructor said it needs a driver to connect in my arduino or sumtn ?

electro18 (author)ralphmark2015-03-06

Yes, it does matter. I've used a common cathode 7 Segment display in this project. I preferred not to use a driver because I had sufficient amount of pins for two 7 segments, though you may use a multiplexer if you want to use more than one 7 segments !

ralphmark (author)electro182015-03-10


ralphmark (author)2015-03-06

Also the 10k ohm resistor. 1/4th , 1/8th or does it matter ? Sorry for my noobish question, i'm not really that knowledgable

electro18 (author)ralphmark2015-03-06

The power of the resistor doesn't matter here because the 10K resistor and the LDR form a voltage divider. The current that passes through the network is very less so a 1/4 watt or any other 10K should work fine.

ralphmark (author)electro182015-03-10


ralphmark (author)2015-03-10

Can I ask what's the use of heat shrink tubing in this project ?

oldsesk (author)2015-03-08

heloo,i have a raspberry pi model b+,can you help me do this project using it?

Dale AllenS (author)2015-03-08

I've tried this with the serial monitor, but I didn't get it to work right. :( Also, may I ask what are these variables for? Thanks!
int lights=9;

int sens_cutoff=A2;

int relay=2;

priyankavenkat (author)2015-02-01

I want the coding for this project

electro18 (author)priyankavenkat2015-03-05

The codes are already uploaded on the page !

rishavs (author)2015-02-19

hii i am trying to make this project. i have a question that how will we load the program to arduino

electro18 (author)rishavs2015-03-05

To upload the program, you'll need a USB-B type cable ( in case of UNO ) or a micro USB ( in case of Leonardo )
Then you can easily use the official IDE to upload the code !

bivesh.shah (author)2014-12-06

please help me to do this project using more than two 7-segment display that can count above 99 persons.

electro18 (author)bivesh.shah2014-12-07

For doing that, you've got two options- either use a 16 x 2 LCD or multiplex the outputs so that they can drive 3 or more seven segments. Using an LCD is the best and the easiest way that would serve the purpose.

electronicz guy (author)2014-12-05

I love this project, I want to build it but I need it to count down, is that possible? Also how accurately would it count objects moving at fast speeds?

Yes you can do that ! It is pretty accurate in counting fast moving objects too ( specially the LASER version ).

electro18 (author)2014-10-26

Well, I've checked the program and it works fine for me. Can you please describe the error that you're exactly getting while running this program ?

techno18 (author)2014-10-20

Hi sir! Im a fan of your work. I tried making this project. But i encounter some problem. Im using two 7segment display but the display is not workiing properly. The rx and tx or pin 0 and pin 1 is usually on. The digit on the tens place

electro18 (author)techno182014-10-21

Thanks :)

It seems that you're using Serial.begin() or any other function that uses Serial monitor. That's why the segments on pin 0 and pin 1 are always 'on'. Try removing the instances from your program. If it still doesn't work , then send me the program through PM.

About This Instructable




Bio: Hey there ! I'm Tanay , a hobbyist interested in making robots and sharing stuff. I hope that my instructables help you in solving your problems ... More »
More by electro18:USB Chameleon Lamp ( Color replicating )Your Own Color Sensor using LEDsMeasure RPM - Optical Tachometer
Add instructable to: