Photoresistor controlled light switch?
Femi
Posts: 3
I'm trying to design a product that will flip on a light switch when the ambient light level drops below a certain threshold. I'm using a BASIC Stamp, but I can't seem to get the code right. Can you guys point me in the right direction? Thanks!
Here's my code so far:
' {$STAMP BS2}
' {$PBASIC 2.5}
counter VAR Word
time VAR Word
DEBUG "Counterclockwise 10 o'clock", CR
DO
HIGH 2
PAUSE 100
RCTIME 2, 1, time
DEBUG HOME, "time = ", DEC5 time
LOOP
IF time > 50 THEN
FOR counter = 1 TO 75
PULSOUT 14, 1100
PAUSE 20
NEXT
DEBUG "Clockwise 2 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 14, 450
PAUSE 20
NEXT
DEBUG "Center 12 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 14, 2000
PAUSE 20
NEXT
DEBUG "All done."
ENDIF
END
Here's my code so far:
' {$STAMP BS2}
' {$PBASIC 2.5}
counter VAR Word
time VAR Word
DEBUG "Counterclockwise 10 o'clock", CR
DO
HIGH 2
PAUSE 100
RCTIME 2, 1, time
DEBUG HOME, "time = ", DEC5 time
LOOP
IF time > 50 THEN
FOR counter = 1 TO 75
PULSOUT 14, 1100
PAUSE 20
NEXT
DEBUG "Clockwise 2 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 14, 450
PAUSE 20
NEXT
DEBUG "Center 12 o'clock", CR
FOR counter = 1 TO 150
PULSOUT 14, 2000
PAUSE 20
NEXT
DEBUG "All done."
ENDIF
END
Comments
Yes, you can make a simple switch that will turn a lamp on when the room gets too dark. But once the lamp is on, the room is bright again, and that same circuit will turn the lamp off in short order. So the lamp will go on & off rapidly. You can buy outdoor lights and night lights with this photocell feature, and they usually oscillate (flash rapidly or dim themselves) at some almost-dark light level, even though they have these luxuries:
1) low light output that doesn't flood the light with room, and
2) they can aim the photocell away from the light output to minimize self-triggering effects
Your options include hysteresis (Google it), which is turning off at a brighter level than you turn on (experimentation required), or once on, set a timer to run the lamp for an hour or so, then switch it off, then check the ambient light level, and switch on if necessary. Loop that!
You do not need a microcontroller for this. An extremely simple comparator circuit can be made to close relay contacts. If you wish to have the light switched mechanically, the comparator can activate an h-bridge connection via two series NOT gates. iF you use dedicated ICs (like monolithic inverters, monolithic h-bridge, and monolithic comparator) you can fit all this circuitry on a small board with pretty few external components (pwr supply, some resistors, some decoupling caps, and MAYBE a buffer transistor or two). The rotation of the motor can be controlled by a monostable pulse.
Hope it helps!
Tomato
Franklin, Erco and Tomato have very good points on the way to control your lighting project and this is the why I would do it.
I would use a Basic Stamp 1 to do this with solid state relay or you can use cool lighting control board called FC-4 from EFX-TEK.com. This board is able to control the dimming and turn on/off your lights serialy and this will be the best bet for you.
TO Franklin: why won't my do loop exit? Sorry if that's a silly question, but I'm very new to coding.
i'm also doing the similar project which is to use photoresistor to detect the room brightness & adjust the brightness of the lamp.
which is to say something like environmental friendly lighting system that will dim the lamp when the room has sufficient brightness.
i really need help with that & hope to see more ideas soon!
thanks alot!