Shop OBEX P1 Docs P2 Docs Learn Events
photoresistors — Parallax Forums

photoresistors

m_cm_c Posts: 1
edited 2007-12-13 01:48 in BASIC Stamp
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

Comments

  • edited 2007-12-13 01:28
    If your goal is to use photoresistors, you'll need to find out what your photoresistors "see" under these circumstances. The two most common approaches to solving this problem are:

    - 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.
  • edited 2007-12-13 01:48
    BTW, after you have tested to find out what values the photoresistor circuits are returning, you will be in a much better position to either write code to make it work at longer distances or go looking for a better sensor.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.
Sign In or Register to comment.