So I'm planning to build a sort of light switch for my Philips Hue bulbs with an Arduino. This project will be mounted on a shelf next to my door to the room, parallel to the walking direction. In order to detect the movement direction to either turn on or off the lights when a person is entering or leaving the room, I need one or two sensors. I've tried HC sr04 before but got inaccurate results which resulted in random changes of the lightstate.

So what sensors will be best for my application? I was thinking about the Sharp IR sensors (i.e. Sharp GP2Y0A60SZLF) but I'm not sure about any possible interference that comes with it when I mount to of these right next to each other. Any ideas?

Thanks in advance!

  • What "Sharp IR sensors"? Please provide a link or a part number
    – chrisl
    Sep 25, 2019 at 19:55
  • @chrisl yeah I forgot to add the part number, edited my question
    – Janik
    Sep 25, 2019 at 19:57
  • Usually for "light" applications you use cheap PIR movement sensors. Two of them with some paper guards that limit their field of vision in two locations. You can check which is triggered first to deduce direction. Sep 25, 2019 at 22:08
  • @FilipFranik wait, the PIR are based on infrared aren't they? So they won't detect a moving door when there is no human or ir emitting source nearby? Is it possible to mask the sensor in such a way that there is only a vertical line where the sensor detects a movement? Because that would be great to avoid any light changes when only the door moves but no person is nearby
    – Janik
    Sep 26, 2019 at 20:19

2 Answers 2


The PIR sensors can work in your case. They are passive and detect only moving objects that emit IR radiation. So anything that's hotter than background like people, cats, dogs but not doors.

The raw sensor looks like this:

PIR sensor

But it's usually available as a part of an IC that includes a plastic lens that focuses IR rays from broader area on the sensor.


Remove that lens (or not) and add something made of cardboard to limit the area that sensor sees and you have a directional sensor that detects moving hot things.

Technically you can completely hack the raw sensor and get info if the hot object is moving left or right. Read this article and look at the sensor response graph.

  1. I guess you want to use 2 IR sensors with a little distance, so that you can check the direction by checking, which one detected an object first. You surely can do this with the mentioned sensor. To avoid interference, you can measure by one one, deactivating the other over it's enable pin during that time. It should be fast enough, so that you can do this sufficiently.

  2. I would say using a distance sensor is overkill here. For checking, if someone comes in or out, you don't need distance information. Just 2 light barriers would be sufficient. For example a little laser pointer (could also be IR), a little mirror at the other side and a fitting photodiode. I think there are ready made modules to buy. Their output would only be digital, not analog.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.