Shop OBEX P1 Docs P2 Docs Learn Events
Photoresistor help — Parallax Forums

Photoresistor help

ShyShy Posts: 15
edited 2008-08-20 15:01 in BASIC Stamp
Hi,

I have boe-bot robot. on it ping and infrared head lights are also working. now i want when my robot go into low intensity light area it shutdown, means stop working.

·

Comments

  • dandreaedandreae Posts: 1,375
    edited 2008-08-18 14:10
    In Chapter 6 of the "Robotics with the Boe-Bot" it explains how the photoresistors work.· Based on the value of the photoresistor you can create a subroutine that puts the BASIC Stamp in "Sleep" mode.· The Sleep mode puts the BASIC Stamp into a low power mode for up to 18 hours.· You can find more information regarding the "SLEEP" command in the "BASIC Stamp Syntax and Reference Manual.

    Dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Parallax Tech Support·
  • ShyShy Posts: 15
    edited 2008-08-18 16:04
    Thank you for reply. i want the robot to remain in sleep mode·during the period
    , thephotoresistors remain in shadow. but when light falls on·robot it should wake up·
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2008-08-18 17:22
    The SLEEP command will be in a loop in your program. It goes into low power mode for say 1 minute, wakes up briefly to check the light level, and either go back to sleep for another minute or activate.

    DO
    SLEEP 60
    GOSUB seethelight
    LOOP UNTIL light > threshold

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • ShyShy Posts: 15
    edited 2008-08-19 00:24
    Thanks again, Please tell me

    DO
    SLEEP 60
    GOSUB seethelight
    LOOP UNTIL light > threshold

    is it the complete code, i am little confused about subroutine·{·GOSUB seethelight} , please explaine
  • FranklinFranklin Posts: 4,747
    edited 2008-08-19 01:23
    Shy said...
    is it the complete code, i am little confused about subroutine·{·GOSUB seethelight} , please explaine
    This is not the whole code, just the part that sleeps while dark the GOSUB would go to code you write that does the things when it is light.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • ShyShy Posts: 15
    edited 2008-08-19 12:05
    i am attaching here code, please insert in photoresistor command, you have told me,·in it
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2008-08-19 17:51
    Do you have a photoresistor? What is its electrical resistance at the light level that would be the border between lignt and dark? The code you have is basically the Ping demo written by Andy Lindsay at Parallax, and it does not yet have any provision for the light sensor.

    You can connect the photoresistor in series with a fixed resistor from Vdd to Vss, and the junction to a Stamp pin, so that PBASIC will read 1 on that pin in the dark and 0 in the light. You have to discover the correct value of fixed resistor or provide more information about your photoresistor.

                 fixedR     photoR
       +5 ---/\/\---o---/\/\---- Vss
                        |
                        p0
    



    Then at the end of the main loop, add the lines marked with "<
    ":

    Main:
    DO
    
      FREQOUT 8, 1, 38500                   ' Emit 38.5 kHz IR To Left
      irDetectLeft = IN9                    ' Store IR Detection Values
    
      FREQOUT 2, 1, 38500                   ' Emit 38.5 kHz IR To Right
      irDetectRight = IN0                   ' Store IR Detection Values
    
      IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
        GOSUB Ping_Around                   ' Object Detected via IR Forward
      ELSEIF (irDetectLeft = 0) THEN
        GOSUB Ping_Around                   ' Object Detected via IR Left
      ELSEIF (irDetectRight = 0) THEN
        GOSUB Ping_Around                   ' Object Detected via IR Right
      ENDIF
    
      counter = counter + 1                 ' Increment Passive Counter
    
      IF counter > 10 THEN                  ' Wait For 10 Servo Pulses
        GOSUB Ping_Out                      ' Activate PING)))
      ENDIF
    
      IF (distance > 30) THEN               ' Is Object Farther Than 30 cm?
        GOSUB Forward_Pulse                 ' If Yes Go Forward
      ELSE
        GOSUB Ping_Around                   ' Otherwise Scan For Clear Path
      ENDIF
    
      dark PIN 0   ' <------- whatever pin you want to use for the light sensor
      DO WHILE dark  ' <-------  this will only execute when it is dark, pin level high
        SLEEP 60  ' <-------   sleep in increments of 60 seconds
      LOOP    ' <-------    recheck for light once a minute, and back to work when light
    
    LOOP
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • ShyShy Posts: 15
    edited 2008-08-20 15:01
    thanks Allen it works.
Sign In or Register to comment.