Counting persons coming in or going out of a Room / Building

GP2Y0A21YK0F Infrared Distance Sensor_bb

We all are aware of Home Automation and love the idea of actions to be performed automatically in our Homes without hurting our Economy.

Have you ever wished that the lights should automatically switches on while entering the room and vice versa? Off course you do. Ummm, One might suggest using mobile phone presence for this event to occur? Yea, It’s a good idea but lets have a look on this option. We may use WiFi or Bluetooth but If We enter our living room and it may turn our bedroom lights on or off. And if we add specific WiFi access point or Bluetooth modules in all rooms? Let’s suppose We do practice this idea, It would be less accurate due to intermingled WiFi or Bluetooth signals. Moreover, not every person enters the room may have smart phone or If we forget our smart phone in our bedroom and go to living room then? Oops!.

Hey, If we register the entry or exit of a person in or out of the room, then We can make out system more accurate, is not it? So here it comes the idea of counting person. I am so sorry for heavy weight start 😛 , so lets get started  😉 .

Hardware Needed:

Hardware Connections:

GP2Y0A21YK0F Infrared Distance Sensor comes with connector which has three wires, Red, Black and Yellow. Connect Red wire to +5V, Black to Ground and Yellow wire goes to analog pin of Arduino Nano. Connect both of sensors to Arduino Nano on Analog Pin A0 and A1 as shown in picture above. Don’t forget to add decoupling capacitors of at least 10µF across sensor power supply somewhere near to the sensors to get stable reading out of the sensors.


A very basic sketch to have an idea to accomplish above mentioned task is as follows.


A more comprehensive and applicable version of this sensor is coming soon, Stay tuned!!

Leave a Reply

Your email address will not be published. Required fields are marked *

All orders confirmed by 3:00 PM will be shipped on same day. Estimated delivery time is 24-48 hrs. Dismiss