photoresistors
m_c
Posts: 1
hi there-
My goal with this boebot is to use the photo resistors to find a burning candle in the dark.
my problem is: up close, the sensors detect light, but any distance away and it doesn't work.
I hope you don't mind if put below the code i'm using.
can you give me advice?
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] Variables ]
' Declare variables for storing measured RC times of the
' left & right photoresistors.
timeLeft VAR Word
timeRight VAR Word
average VAR Word
difference VAR Word
'
[noparse][[/noparse] Initialization ]
FREQOUT 4, 2000, 3000
'
[noparse][[/noparse] Main Routine ]
DO
GOSUB Test_Photoresistors
' For mismatched photoresistors, use Appendix F, uncomment and use next line.
' timeLeft = (timeLeft */ 351) + 7 ' Replace 351 and 7 with your own values.
GOSUB Average_And_Difference
GOSUB Navigate
LOOP
END
'
[noparse][[/noparse] Subroutine - Test_Photoresistors ]
Test_Photoresistors:
HIGH 6 ' Left RC time measurement.
PAUSE 3
RCTIME 6,1,timeLeft
HIGH 3 ' Right RC time measurement.
PAUSE 3
RCTIME 3,1,timeRight
RETURN
'
[noparse][[/noparse] Subroutines ]
Average_And_Difference:
average = timeRight + timeLeft / 2
difference = average / 6
RETURN
Navigate:
' Shadow significantly stronger on left detector, turn right.
IF (timeLeft > timeRight + difference) THEN
PULSOUT 13, 850
PULSOUT 12, 850
' Shadow significantly stronger on right detector, turn left.
ELSEIF (timeRight > timeLeft + difference) THEN
PULSOUT 13, 650
PULSOUT 12, 650
ELSE
' Shadows in same neighborhood of intensity on both detectors.
PULSOUT 13, 850
PULSOUT 12, 650
ENDIF
PAUSE 10
RETURN
My goal with this boebot is to use the photo resistors to find a burning candle in the dark.
my problem is: up close, the sensors detect light, but any distance away and it doesn't work.
I hope you don't mind if put below the code i'm using.
can you give me advice?
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] Variables ]
' Declare variables for storing measured RC times of the
' left & right photoresistors.
timeLeft VAR Word
timeRight VAR Word
average VAR Word
difference VAR Word
'
[noparse][[/noparse] Initialization ]
FREQOUT 4, 2000, 3000
'
[noparse][[/noparse] Main Routine ]
DO
GOSUB Test_Photoresistors
' For mismatched photoresistors, use Appendix F, uncomment and use next line.
' timeLeft = (timeLeft */ 351) + 7 ' Replace 351 and 7 with your own values.
GOSUB Average_And_Difference
GOSUB Navigate
LOOP
END
'
[noparse][[/noparse] Subroutine - Test_Photoresistors ]
Test_Photoresistors:
HIGH 6 ' Left RC time measurement.
PAUSE 3
RCTIME 6,1,timeLeft
HIGH 3 ' Right RC time measurement.
PAUSE 3
RCTIME 3,1,timeRight
RETURN
'
[noparse][[/noparse] Subroutines ]
Average_And_Difference:
average = timeRight + timeLeft / 2
difference = average / 6
RETURN
Navigate:
' Shadow significantly stronger on left detector, turn right.
IF (timeLeft > timeRight + difference) THEN
PULSOUT 13, 850
PULSOUT 12, 850
' Shadow significantly stronger on right detector, turn left.
ELSEIF (timeRight > timeLeft + difference) THEN
PULSOUT 13, 650
PULSOUT 12, 650
ELSE
' Shadows in same neighborhood of intensity on both detectors.
PULSOUT 13, 850
PULSOUT 12, 650
ENDIF
PAUSE 10
RETURN
Comments
- Use DEBUG commands to display what the photoresistors sense in the Debug Terminal.
- Datalog a session and then display it in the Debug Terminal later.
Robotics with the Boe-Bot has a DEBUG examples, so all you would need if you are using this approach is a way of having a laptop or PC close enough to the candle course to display the messages. Alternately, you can datalog a session and display the results later. This is presented in Smart Sensors and Applications, Applied Robotics with the Boe-Bot, and Applied Sensors. You can download the full PDF of any of these texts from www.parallax.com.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay
Education Department
Parallax, Inc.