Wednesday, August 24, 2011

Light Sensor - Let there be light, but how do you know?


Sensing light is pretty simple. Most stuff I've found on it for microcontrollers (uC's) uses LDR's or Light Dependent Resistors. The problem I have with these is two fold. 1) They mostly come in non-weather proof packages so if you left them out in the yard they'd corrode/delaminate and fail within a few months. 2) They're butt-ugly and not as accurate as a photo-transistor. Plus doesn't photo-transistor (PTR) sound cooler?

So just like a regular BJT transistor, more current passes through based on current at the base. In the case of a PTR, the base is stimulated by light. So more light = more current (less resistance). So basically you have another voltage divider (like in the battery voltage sensor) but the resistor on top varies based on the ambient light picked up by the PTR. Simple enough?

Then you just put that voltage divider middle node (between the two resistors, or PTR) into your uC analog input and read the voltage level. A little trial and error and you quickly know what a good sunset level is. You have to do a little hysteresis (use the history of what's happened and feed it back into your algorithm). I.E. let it be dark enough for a few minutes before turning on your solar powered LED lights, then don't assume it's light again until you read a voltage somewhat different than your trigger voltage. You don't want the thing to spasm and turn on/off for 20 minutes at sunset. Just turn on and stay on. Also, turn on the lights when it's just dusk. It looks cool to be able to notice the lights when it's still a little light out.

No comments:

Post a Comment