Shop OBEX P1 Docs P2 Docs Learn Events
Sharp GP2Y0D340K IR Range Sensor headache — Parallax Forums

Sharp GP2Y0D340K IR Range Sensor headache

MacadaciouseMacadaciouse Posts: 16
edited 2010-04-18 17:08 in BASIC Stamp
I'm trying to use a Sharp GP2Y0D340K IR Range Sensor for object avoidance and it is turning out to be a PAIN. It has a digital output, which I have been connecting to pin 15. I've been trying to use pulsin and pulsout to tell when the voltage changes (by timing a response pulse) but there IS no voltage change; the output voltage remains identical to the input voltage. Am I going about this the wrong way? Is there another command I should be using? Thanks for any advice, I must have spent 5 hours last night writing and rewriting code.

' {$STAMP BS2}
' {$PBASIC 2.5}
duration VAR Word

main:
PULSOUT 15, 50
PULSIN 15, 1, duration
PAUSE 800
IF IN15 >= 50 THEN
HIGH 14
DEBUG "go"
PAUSE 500
LOW 14
PAUSE 2000
ENDIF

IF IN15 < 50 THEN
LOW 14
DEBUG "turn"
ENDIF
GOTO Main

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-04-17 14:59
    You can't use this sensor the way you want. This has a digital output that's high (Vdd = 5V) when there's no object sensed within 400mm or low (Vss = 0V) when there's an object detected within 400mm. The distance is fixed. You can sense the digital state just by looking at an input pin connected to the sensor's output (like IN15 for pin #15). IN15 will be 1 if there's no objected detected within 400mm. It will be 0 if there's an object within 400mm.
  • MacadaciouseMacadaciouse Posts: 16
    edited 2010-04-18 16:49
    Thank you for the clarification, what commands would I use to detect this? I tried IF IN15 1 THEN GOTO, but the stamp wouldn't recognize the "1". What i have below turns on an LED fine, but it makes no difference if there's something in front of the sensor or not. Could the sensor be damaged/defective? Thanks for any help.

    main:
    IF IN15 THEN GOTO light
    light:
    HIGH 14
    PAUSE 500
    DEBUG "light"
    LOW 14
    PAUSE 1500
    GOTO main
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-04-18 16:59
    You are missing ( = ) 1

    main:
    IF IN15 = 1·THEN GOTO light
    light:
    HIGH 14
    PAUSE 500
    DEBUG "light"
    LOW 14
    PAUSE 1500
    GOTO main


    OR

    You could use this

    What this dose if your button or your input··is low or·not pushed it just loop again

    main:
    IF IN15 = 1 THEN
    GOSUB light
    ELSE
    GOTO MAIN
    ENDIF

    light:
    HIGH 14
    PAUSE 500
    DEBUG "light"
    LOW 14
    PAUSE 1500
    RETURN

    I hope this helps

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·Now wanting to learn Spin· Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 4/18/2010 5:06:08 PM GMT
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2010-04-18 17:08
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
     
    INPUT 15
     
    test_routine:
      DEBUG "sensor = ", BIN1 IN15, CR
      GOTO test_routine
     
     
     
    

    Yes, if you don't know what you're doing, then the·sensor could be damaged (but you knew that already.)· Not likely 'defective.'
Sign In or Register to comment.