Arduino powered occupancy sensor

Hi all. I want to use a 328 in my ceiling to work as an occupancy sensor for lighting and also to control the extractor fan by measuring humidity.

Everything seems straight forward, I have some of the bargain PIR sensors from eBay which should do the job, but I'm not sure how to measure ambient light because I would want to mount a LDR inside or close to the PIR But I can see it causing issues when the lights have been turned on because the brightness would then more than likely be over the LUX threshold and the lights would cycle surely?

Hope that makes sense and I look forward to hearing any suggestions - maybe someone has torn down a standard PIR and seen how it is done?

Here is what you almost always need to do when buying from ebay.

  1. Roughly 98% of the time, they don’t provide adequate documentation, but the products
    are almost always clones of someone else’s IP, and who do provide documentation.

  2. so, what you need to do is use “google images” search, and try to locate the original
    device, where someone does provide the correct documentation. Then, you’ll know
    what you actually have.

  3. in regards PIRs, a lot of these devices already have an LDR inside that’s used to adjust
    the ambient light sensitivity - but of course, first you have to know what the heck it is
    that you actually have. So, go to #2.

Hi oric_dan. The PIR does not have a LDR built in and I know enough about it to use it but thanks for the tip :)

I'm just wondering how to measure the ambient light without the room lights effecting the readings when they have been triggered?

If the LDR is there so that the Arduino can know when to switch lamps on and off then presumably it already knows when the lamp is on and could apply the appropriate criteria to the LDR reading. In that case you just need to find out how much difference the lamp makes to the LDR reading and adjust the code to accommodate that.

there is no LDR there yet but I will be implementing one - I guess as you say maybe it will have to be a software thing to allow it to function properly once the lamp is on?


I assume you are measuring the ambient light so your PIR doesn't cause the lights to go on when someone enters the room during daylight hours.

Daylight to darkness doesn't change frequently so the logic for dealing with it seems simple.

  1. If the room is empty the lights should be off regardless of ambient light.

  2. If the room is occupied and the lights are off and the ambient light is high the lights stay off.

  3. If the room is occupied and the ambient light is low the lights go on.

  4. If the lights are on the ambient lighting is ignored and rule 1 is applied.


Thanks Robin, I never really thought of it like that, I guess it will be a software thing then.

Thanks again!

I guess with the logic I mentioned earlier there is a risk if the room is occupied prior to dawn that the lights won't go off when daylight comes if the room remains occupied.

If I was concerned about that I think I would locate my LDR so that it was looking out the window to detect outdoor light.


Another problem with this sort of project is reliably detecting the human, a PIR will only detect movement, if they sit still for 5 minutes it will think they have left the room.


This is the problem that gives substance to the expression "many hands make light work".


Graynomad: if they sit still for 5 minutes it will think they have left the room.

Graynomad: Another problem with this sort of project is reliably detecting the human, a PIR will only detect movement, if they sit still for 5 minutes it will think they have left the room.


I have thought quite a bit about this case, but can't think of a way around it using a standard PIR. You can get microwave occupancy sensors but I guess they also work on the principles of changing values.

I think if I go ahead I will have the lights fade out when the time has elapsed, then if the room is occupied it gives the occupier a chance to keep it on!

haha, many hands... I like it :)

well, I was looking at the PCB and noticed through holes labelled cds. I have done some reverse engineering on the PCB, then I found a datasheet which confirms that the controller has a output disable function if the voltage on a pin is <2v

I had a 10k LDR lying around and tried it out, voltage was too low because the divider was only being pulled up to 3V via 1 1M resistor. I took it off and connected a 100K pot which seems to give a nice range of light to dark. Very chuffed with these little PIR’s and they are so cheap!

Hopefully the only issue I have now is finding a bigger dome fresnel lense :slight_smile: