PDA

View Full Version : Sharp GP2Y0D340K IR Range Sensor headache



Macadaciouse
04-17-2010, 10:45 PM
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

Mike Green
04-17-2010, 10:59 PM
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.

Macadaciouse
04-19-2010, 12:49 AM
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_sam
04-19-2010, 12:59 AM
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·http://forums.parallax.com/images/smilies/idea.gif·that you may have and all of your time finding them http://forums.parallax.com/images/smilies/smile.gif

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 4/18/2010 5:06:08 PM GMT

PJ Allen
04-19-2010, 01:08 AM
' {$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.'