Sharp GP2Y0D340K IR Range Sensor headache
Macadaciouse
Posts: 16
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
' {$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
main:
IF IN15 THEN GOTO light
light:
HIGH 14
PAUSE 500
DEBUG "light"
LOW 14
PAUSE 1500
GOTO main
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··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 4/18/2010 5:06:08 PM GMT
Yes, if you don't know what you're doing, then the·sensor could be damaged (but you knew that already.)· Not likely 'defective.'