Sharp IR Sensor Distance
I have a question in reference to the Sharp IR Sensor. It states that it has a range of 10cm - 80cm. But when I hook it up, the maximum distance it detected was less than 10cm.
Am I doing something wrong?
I used the code below:
The IR is connected to pin 9
Thanks ( in advance).
Am I doing something wrong?
I used the code below:
The IR is connected to pin 9
irDetectLeft VAR Bit
DO
irDetectLeft = IN9
DEBUG HOME, "irDetectLeft = ", BIN1 irDetectLeft
PAUSE 100
LOOP
Thanks ( in advance).
Comments
Take a look at this page http://www.acroname.com/robotics/info/articles/sharp/sharp.html for a tutorial on the Sharp sensors. Other good information can be found at other sites found with Google.
John Abshier
thank you Sir.
John Abshier
P.S. -- if you want to just have a binary (yes/no) detector with the IR ranger, you could run the output through a voltage divider into your micro pin -- adjusting the values in the voltage divider would let you set a threshold (corresponding to some distance between 10cm - 80cm) and get a "1" or "0" depending on whether the target is closer than the set value or further.
The Stamp's input pin high/low transition voltage is ~1.4V, and you can use that like a simple comparator if you want a digital go/no-go input. You can use a voltage divider to scale voltages higher than 1.4 down. I have also used an 8-resistor voltage divider string with a Sharp sensor and 8 IO pins to resolve distance in 8 different zones for a balancing robot.
It's becoming more clear. It will be even more so, when I test it out with the chip.
USPS shipping is cheap.
Ebay Thailand is still $4 and a 2-week wait! http://www.ebay.com/itm/ADC0831-ADC0831CCN-8-Bit-A-D-Converter-IC-/250866258051?pt=LH_DefaultDomain_0&hash=item3a68cb5083
I was hoping to use the Sharp sensor in place of the PING))) sensor.
then as I'm hooking up the sensor I see the comments about it being analog.
I'm using the Homework board and I assume that I need this converter but honestly not sure how/why I'd set it up.
I just want the sensor to recognize movement between 3-6 feet in front of the senor and if something is there send a signal. a simple yes/no
but still not entirely sure what I'm doing. will do some more research until I hopefully hear back.
i was just reading that thread. and wondering the same thing. no extra resistors needed if I just use the same PING))) code but use sep pins for puls out and puls in? (normal 4 pin mode rather than 3)
Hmmm. A soda, or a sensor? Same price.
ordered today
I'm getting there, it's slow going but moving in the right direction
got sensor in, ordered just 't one from amazon. yes i know it was more expensive but I didn't want to wait weeks for it and currently I just need 1.
anyway,
I have tried several different forms of code. i first modified my current setup (old PING))) sensor. I changed pulsout(trig) and pulsin(echo) to the correct pins for the new sensor.
'{$STAMP BS2} '{$PBASIC 2.5} '--------------Main Routine---------------------- counter VAR Word CmConstant CON 2260 InConstant CON 890 cmDistance VAR Word inDistance VAR Word time VAR Word Sense: cmDistance = 0 ' reset distance variables INDistance = 0 time = 0 DO PULSOUT 14, 5 'sense distance via hc-sr04 echo pin PULSIN 15, 1, time ' trigger pin is input pin cmDistance = cmConstant ** time 'conversion to inches and cm inDistance = inConstant ** time DEBUG HOME, DEC3 cmDistance, " cm" DEBUG CR, DEC3 inDistance, " in" PAUSE 100 IF (inDistance = < 48) THEN ' if <48in then spray silly string GOSUB Shoot ENDIF ' if >48 in then keep looking LOOP Shoot: FOR counter = 1 TO 75 ' Loop for ~1 second PULSOUT 12, 1000 ' Servo counterclockwise PAUSE 10 NEXT FOR counter = 1 TO 150 ' Loop for 2 seconds PULSOUT 12, 750 ' Servo center PAUSE 5 NEXT RLY1 PIN 0 HIGH RLY1 PAUSE 1000 LOW RLY1 PAUSE 1000 PAUSE 30000 ' pause 30 seconds then GOTO Sense ' return to sense mode
i just get zero on the two lines and the everything fires like there is an object in the way.
so I switch to
[COLOR=#333333]' {$STAMP BS2}[/COLOR] [COLOR=#333333]' {$PBASIC 2.5}[/COLOR] [COLOR=#333333]#SELECT $STAMP[/COLOR] [COLOR=#333333]#CASE BS2, BS2E[/COLOR] [COLOR=#333333]' Trigger CON 5 ' trigger pulse = 10 uS[/COLOR] [COLOR=#333333]Scale CON $200 ' raw x 2.00 = uS[/COLOR] [COLOR=#333333]#ENDSELECT[/COLOR] [COLOR=#333333]time VAR Word[/COLOR] [COLOR=#333333]RawToIn CON 889 ' 1 / 73.746 (with **)[/COLOR] [COLOR=#333333]RawToCm CON 2257[/COLOR] [COLOR=#333333]rawDist VAR Word ' raw measurement[/COLOR] [COLOR=#333333]inches VAR Word[/COLOR] [COLOR=#333333]IsHigh CON 1 ' for PULSOUT[/COLOR] [COLOR=#333333]IsLow CON 0[/COLOR] [COLOR=#333333]DO[/COLOR] [COLOR=#333333]PULSOUT 10, 5[/COLOR] [COLOR=#333333]PULSIN 11, 1, rawDist[/COLOR] [COLOR=#333333]rawDist = rawDist */ Scale ' convert to uS[/COLOR] [COLOR=#333333]rawDist = rawDist / 2 ' remove return trip[/COLOR] [COLOR=#333333]inches = rawDist ** RawToIn [/COLOR] [COLOR=#333333]DEBUG HOME, "inches = ", DEC3 inches[/COLOR] [COLOR=#333333]PAUSE 100[/COLOR] [COLOR=#333333]LOOP
and all i get is inches = 000
[/COLOR]' PingTest.bs2 ' {$STAMP BS2} ' {$PBASIC 2.5} time VAR Word DO PULSOUT 14, 5 PULSIN 15, 1, time DEBUG HOME, "time = ", DEC5 time PAUSE 100 LOOP
gives me time of 00001 or 00002 without any correlation to anything.finally I tried adding a 10k and 1k resistor as detailed here, and i get no improvement
if I simply reset pulsout and pulsin to same pin and swap in my PING))) my setup works fine. I assume it's a bad sensor
all I get is zeros
' {$STAMP BS2} ' {$PBASIC 2.5} DO PULSOUT 14, 5 'sense distance via hc-sr04 echo pin PULSIN 15, 1, W0 ' trigger pin is input pin DEBUG DEC W0,CR PAUSE 50 LOOP
I think you may have your I/O pins swapped, based on your comments. Connect pin 14 to TRIG on the sensor and pin 15 to ECHO. Once you get some numbers coming back, you can throw your math back in to calibrate for inches & cm.
' {$STAMP BS2} ' {$PBASIC 2.5} ' HC-SR04/SR05 ultrasonic sensor 1-pin usage ' P1 to TRIG on sensor ' connect 1500-1800 ohm resistor between TRIG and ECHO MAIN: HIGH 1 ' send brief pulsout to be cut short ASAP PULSIN 1, 1, W0 ' immediately switch pin to input W0=W0/72 ' calibrate to inches PAUSE 50 DEBUG DEC W0,CR GOTO MAIN
double checked pins and they are connected as you suggested. (when I was troubleshooting I think I tried them both ways honestly, not sure I updated the comments)
but no.
shortened code didn't work
your code also a no go. guess I should have ordered more than one.
thanks for going through the trouble of testing the code. I'll order some more and just use my PING))) till they arrive.
Shawn
eric
and thank you so much!
so I got a bad one initially.
Thanks for all the help
Shawn
That makes TWO somewhat different meanings for the abbreviation f/u .