Dimming a light with a photo sensor
Archiver
Posts: 46,084
Hey all. Extreme newbie here. I searched the forum and found a few
posts that sort of deal with what I'm trying to accomplish, and I'm
just hoping that maybe someone can point me in the direction of some
basic sample code that somewhat resembles what I'm going for (my
PBasic knowledge is very slim, but I'm trying).
Basically, I would like to be able to dim a small light (maybe a small
flashlight or something similar that doesn't suck much power) using a
photo sensor. The idea is that when it's bright outside, the light
inside will barely be on, and when it's night time, full power will
run through it, along with maybe 10-12 variances inbetween. I figure
the actual mechanics of such a setup to be somewhat simple, but it's
the code part that's freaking me out. I'm not asking anyone to write
it for me or anything, but if anyone knows where to find the code for
something similar in concept, I'd be extremely greatful for it. I
haven't been able to really find anything for it on the net (as
opposed to my next project, a wearable midi interface, there's a good
deal of info for that on the net), so many thanks to any who can help.
ry
posts that sort of deal with what I'm trying to accomplish, and I'm
just hoping that maybe someone can point me in the direction of some
basic sample code that somewhat resembles what I'm going for (my
PBasic knowledge is very slim, but I'm trying).
Basically, I would like to be able to dim a small light (maybe a small
flashlight or something similar that doesn't suck much power) using a
photo sensor. The idea is that when it's bright outside, the light
inside will barely be on, and when it's night time, full power will
run through it, along with maybe 10-12 variances inbetween. I figure
the actual mechanics of such a setup to be somewhat simple, but it's
the code part that's freaking me out. I'm not asking anyone to write
it for me or anything, but if anyone knows where to find the code for
something similar in concept, I'd be extremely greatful for it. I
haven't been able to really find anything for it on the net (as
opposed to my next project, a wearable midi interface, there's a good
deal of info for that on the net), so many thanks to any who can help.
ry
Comments
Use RCTIME to read the photocell and the delay in reading is used to
control the "on" portion of a synthesized PWM wave. In psuedocode,
something like this:
Main:
HIGH LightCtrl
RCTIME photocell, 1, anyWordVar
LOW LightCtrl
PAUSE x
GOTO Main
You can use the output pin called LightCtrl to control a small MOSFET
that switches the current for the light bulb.
The idea is that the dimmer the light, the longer the RCTIME function
will take to return a value, so the on portion of the PWM waveform will
be longer. You'll have to experiment with the PAUSE value. Note that
PAUSE 0 will pause for about 100 microseconds.
-- Jon Williams
-- Applications Engineer, Parallax
-- Dallas Office (but not at home this weekend ... so I'm working)
Original Message
From: r_couldrey [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=lMTymPb1r9toXPv3uflftJlA1kvy_IHXEIJQtlS31euvx4z6Rc-t-aTsB4u55OFj5sr4EkzUNbFTJ6iCtsc]r_couldrey@y...[/url
Sent: Saturday, October 04, 2003 12:40 PM
To: basicstamps@yahoogroups.com
Subject: [noparse][[/noparse]basicstamps] Dimming a light with a photo sensor
Hey all. Extreme newbie here. I searched the forum and found a few
posts that sort of deal with what I'm trying to accomplish, and I'm
just hoping that maybe someone can point me in the direction of some
basic sample code that somewhat resembles what I'm going for (my
PBasic knowledge is very slim, but I'm trying).
Basically, I would like to be able to dim a small light (maybe a small
flashlight or something similar that doesn't suck much power) using a
photo sensor. The idea is that when it's bright outside, the light
inside will barely be on, and when it's night time, full power will
run through it, along with maybe 10-12 variances inbetween. I figure
the actual mechanics of such a setup to be somewhat simple, but it's
the code part that's freaking me out. I'm not asking anyone to write
it for me or anything, but if anyone knows where to find the code for
something similar in concept, I'd be extremely greatful for it. I
haven't been able to really find anything for it on the net (as
opposed to my next project, a wearable midi interface, there's a good
deal of info for that on the net), so many thanks to any who can help.
ry
To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject
and Body of the message will be ignored.
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
This message has been scanned by WebShield. Please report SPAM to
abuse@p....
r_couldrey@y... writes:
I figure
the actual mechanics of such a setup to be somewhat simple, but it's
the code part that's freaking me out. I'm not asking anyone to write
it for me or anything, but if anyone knows where to find the code for
something similar in concept, I'd be extremely greatful for it. I
haven't been able to really find anything for it on the net (as
opposed to my next project, a wearable midi interface, there's a good
deal of info for that on the net), so many thanks to any who can help.
++++++++++++++++++++++++++++++++++++++++++
Since it sounds like you are willing to do some work (not expecting the code
to be written for you) start with downloading the stamp manual from the
parallax web-sight. You can also download a tutorial that will tell you and show
you
how to use the RCTIME command.
This command will return a numerical value based on the resistance of your
sensor. You can then output PWM to your lamp or LED based on the value returned
from the RCTIME command.
If this is not enought information to get you going, don't hesitate to write
back.
Ken
[noparse][[/noparse]Non-text portions of this message have been removed]
jwilliams@p... writes:
Use RCTIME to read the photocell and the delay in reading is used to
control the "on" portion of a synthesized PWM wave. In psuedocode,
something like this:
Main:
HIGH LightCtrl
RCTIME photocell, 1, anyWordVar
LOW LightCtrl
PAUSE x
GOTO Main
+++++++++++++++++++++++++++++++++++++++++++++++++
Jon,
That's brilliant, but you knew that.....
[noparse][[/noparse]Non-text portions of this message have been removed]
ry
--- In basicstamps@yahoogroups.com, "Jon Williams" <jwilliams@p...>
wrote:
> Here's an idea...
>
> Use RCTIME to read the photocell and the delay in reading is used to
> control the "on" portion of a synthesized PWM wave. In psuedocode,
> something like this:
>
> Main:
> HIGH LightCtrl
> RCTIME photocell, 1, anyWordVar
> LOW LightCtrl
> PAUSE x
> GOTO Main
>
> You can use the output pin called LightCtrl to control a small
MOSFET
> that switches the current for the light bulb.
>
> The idea is that the dimmer the light, the longer the RCTIME
function
> will take to return a value, so the on portion of the PWM waveform
will
> be longer. You'll have to experiment with the PAUSE value. Note
that
> PAUSE 0 will pause for about 100 microseconds.
>
> -- Jon Williams
> -- Applications Engineer, Parallax
> -- Dallas Office (but not at home this weekend ... so I'm working)
>
>
>
>
>
Original Message
> From: r_couldrey [noparse][[/noparse]mailto:r_couldrey@y...]
> Sent: Saturday, October 04, 2003 12:40 PM
> To: basicstamps@yahoogroups.com
> Subject: [noparse][[/noparse]basicstamps] Dimming a light with a photo sensor
>
>
> Hey all. Extreme newbie here. I searched the forum and found a few
> posts that sort of deal with what I'm trying to accomplish, and I'm
> just hoping that maybe someone can point me in the direction of some
> basic sample code that somewhat resembles what I'm going for (my
> PBasic knowledge is very slim, but I'm trying).
>
> Basically, I would like to be able to dim a small light (maybe a
small
> flashlight or something similar that doesn't suck much power) using
a
> photo sensor. The idea is that when it's bright outside, the light
> inside will barely be on, and when it's night time, full power will
> run through it, along with maybe 10-12 variances inbetween. I figure
> the actual mechanics of such a setup to be somewhat simple, but it's
> the code part that's freaking me out. I'm not asking anyone to write
> it for me or anything, but if anyone knows where to find the code
for
> something similar in concept, I'd be extremely greatful for it. I
> haven't been able to really find anything for it on the net (as
> opposed to my next project, a wearable midi interface, there's a
good
> deal of info for that on the net), so many thanks to any who can
help.
>
> ry
>
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the
Subject
> and Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
>
>
> This message has been scanned by WebShield. Please report SPAM to
> abuse@p...