BS1 driving an led as a sensor
Sesrun
Posts: 2
I read over forums.linear1.org/index.php?PHPSESSID=66595e369ddf5934339180c4605c62f6&topic=445.15 about using an led as a light sensor...I then tryed to illustrate this principle using a bs1 by hooking up a single red led to pin0(long end) and pin1(short end), I also hooked up a serial LCD to pin 7, I then wrote this program which just contently displays 0 no matter if I was shinning a red led at the led on the stamp or not. Here is what I tried:
Any suggestions would be appreciated, thanks in advance.
' {$STAMP BS1} PAUSE 1000 SEROUT 7,N2400,(" TEST") SYMBOL result = W1 SYMBOL half = B4 half = 1/2 loop: 'turn on led HIGH 0 LOW 1 'invert poleraty for 10ms and measure time of discarge of led POT 0,255,result 'invert result result = result*half 'Output value of result SEROUT 7,N2400,(254,1,#result) 'Repeat GOTO loop
Any suggestions would be appreciated, thanks in advance.
Comments
"Here's a circuit that takes advantage of the photo-voltaic voltage of an ordinary LED. The LED voltage is buffered by a junction FET transistor and then applied to the inverting input of an op-amp with a gain of about 20. This produces a change of about 5 volts at the output from darkness to bright light. The 100K potentiometer can be set so that the output is around 7 volts in darkness and falls to about 2 volts in bright light."
Cheers
Rafael
·· I believe this is the thread you refer to:
http://forums.parallax.com/showthread.php?p=570497
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Since the PBASIC Stamp can only do integer math, the follwing expression will not give you what you expect it will:
half = 1/2
The variable "half" wll NOT = .5 after that line is executed, as rounding will occur. Check your PBASIC Stamp Manual for details.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
This code works with the pos end of a led on pin0 and neg on pin1, a serial lcd on pin 7, and the lcd backlight hooked up to pin6 and ground. Thanks for all the help and suggestions...
-Ryan