Sharp Range Sensor gives inconsistent results
2008-06-15 06:55
I'm trying to use a Sharp range sensor (http://www.pololu.com/catalog/product/136) on the Picaxe 18x project board but I seem to be getting bad results. When the sensor is not facing anything within range, the analog input jumps around 95 - 110 in the debug window. When an object gets closer the results seem to be more accurate, but still jumps around a little bit.
The problem is that when objects are in range and getting closer, the number goes up (I believe this is correct behavior). So if my robot is trying to avoid objects, 100 looks really close -- even though nothing is in range. I would expect the sensor to show something close to zero when nothing is within range.
I've connected the wires to the board in the order of: red, white (data), black. This seems to be correct based on the datasheet for the board.
Based on the "First Robot" tutorial, I also shorted the other analog input. Then I added a 10 micro farad capacitor to the power input line to the sensor. I'm running this circuit with 4 AA batteries.
Is my seonsor bad or could I be doing something wrong?

Can you take a picture of
Mine did that too
So I averaged several readings to get more consistent results. And yes, it's backwards; approaching 500 is close, and approaching 0 is far. Think of it like resistance, closer to 0 is no resistance. :) I figured out that on mine, 500 was about 3.5", and 200 was about 8".
See http://letsmakerobots.com/node/672 to see how I dealt with the averaging. Works pretty well. Even though you are using a PicAxe, same theory applies.
Reclarifing...
I just reread my question and realized that it doesn't make much sense. Basically, my problem is that I would expect the analog input to register close to zero when nothing is within range, but for some reason it jumps around 90 - 110 (which should tell me something is very close). Does this mean it is defective or that I'm doing something wrong.
I've tried a number of wiring combinations and the current setup (which is based on the Picaxe board and IR sensor specs) is the only one which returns results which seem to change with proximity (even if it doesn't seem like the correct results).
Here are the pictures, a couple with things called out and then the same pics without. Sorry my camera phone isn't that clear.
I know there is a lot of wiring going on, I have built this a little at a time. I first mounted the motor and controller and made sure that it worked, then the servo and tested that. All the wires are so that it was easy to reconfigure and test as I developed.
Sensor oddities
Strange things that might be a clue :
The Sharps have a "cone" of detection, starting at the sensor then widening about 15 degrees out to a maximum width of about 10 or 12 inches ( 25 to 27 cm ) in their range, sometimes even tapering off further out. What might not seem in their detection area can sometimes actually be causing false readings. The 100 reading sounds like it's picking something up 5-6 inches (13-14 cm) away, and the pictures show the sensor aimed a bit downward, though you probably aim it somehow when testing. The max value you might see could be 160 or so, when the sensor detects something 2 inches (5 cm) away, but dropping again as the obstacle gets even closer.
Other possible glitches include some types of flourescent and sodium lighting, that used to mess with other types of IR detectors as there were 40 kHz harmonics in the light.Not sure if I recall any specific instances with the Sharps, though it did fool others.
Another possible glitch was from an old Sharp app note on these type sensors, that stated the device should be mounted vertically if the detected surface corners were vertical, or horizontal (as you have) if the corners detected were primarily horizontal (due to specular reflection or something like that).
I've personally noticed on these sensors a cracking of the solder joints around the pins. Retouching the solder generally cures it.
No Voltage Regulator
What is going on with all
What is going on with all that stuff between the Picaxe and the Sharp? Capasitors? Huh? Strange setup = strange readings, my friend.
Top menu / start here for how to connect it. The thing just needs voltage, and it returns it more or less depending on distance.. so just straight to an analouge input you go with the white wire!
Your right, then again this
Your right, then again this post has come after quite a bit of trying things to get it to work properly. Originaly I had it setup the same exact way as you did in the "Start Here" post.
I shorted the zero analog input because of this in that post:
"...you should also connect the 3 remaining analogue input to V. I had some jumpers laying, and you can see that all 3 connections left are short cut....The reason it is important to shortcut the unused analogue inputs here is that the are “left floating”. This means that you will get all sorts of weird readings where you try to read if these are not connected. (to put it short, this is a fast paced walkthrough ;)"
Then when reading the specs on the Sharp IR sensor (http://www.pololu.com/file/download/gp2y0a21yk0f.pdf?file_id=0J85) it recommended adding a 10 micro farad capacitor to remove any electrical noise.
Originally I had the sensor connected straight to the Picaxe board (as you did in the walkthrough) and used very simple code to test it:
main:
readadc 1, b1
debug
goto main
The changes to the circuit didn't make any changes to the results, unfortunately. Is there any simple test I can make to check if the sensor is working properly?
If you have a
If you have a measure-thingey, you can use that to test the sharp.
However, I suspect the problem may be the code. Do you have a turn-knob-thingey, and have you tried to connect it as this:
What is returned if you attach nothing?
Good idea, I'll attach a
It is called a
Right, right. I'll try the
Don't forget to use hot glue
Just tested it with a
Just tested it with a turn-knob-thingey and it worked as expected by showing values 0 - 255. I did this with the exact same setup and code I am using with the IR sensor -- capacitor and all. Since I am plugging the sensor into a row of female headers I could just solder 3 wires onto the "turn-knob-thingey" and plug them in. This ensures there was no change in circuitry.
That is really surprising.
That is really surprising. However, nice to have it clear - I thought you had made a mess of variables or something..
And also, it is surpricing because my experience tells that these Sharp IR's burn really easy - but when they are done, they are just done.
But aparently yours is semi-working!?!
OH! What are the specs on it? Number? What raange should it work in? Could you have one with strange specs?
Specs - Sharp GP2Y0A21YK0F Distance Sensor
Here's the exact one that I purchased (Sharp GP2Y0A21YK0F Distance Sensor): http://www.pololu.com/catalog/product/136
And the spec: http://www.pololu.com/file/download/gp2y0a21yk0f.pdf?file_id=0J85
- Range: 10 - 80cm (4" - 32")
- Supply Voltage: -0.3 to +7V
- Output Terminal voltage: -0.3 to +0.3V
- Average supply current: 30 - 40mA
Graph fom Pololu.comThis is the first application I've used it in since I got it in the mail and I was careful to set it up correctly. No magic black smoke yet. :)
I've just emailed Pololu about this and hopefully they will be able to help me figure out if it is defective or not. I really want to get this robot working and then move on to more advanced robots. I'm not sure what to build next...
Oh - Now I think I get the
Oh - Now I think I get the picture!!
Can you confirm that you have a certain range (distance) in which results are somewhat stable?
Sorry for being a bit slow on this one - but what I may have overseen is that all is actually working, you are just interpeting it the wrong way.
If you in fact have A to B ranges that in fact does produce somewhat reliable measurings.. Well then that is all you are going to get!
There is no law that an analouge input has to go from 0-255, and fill out the whole range. And with IR distance-thingeys there is nothing to tell you if your object is out of range, or too close.
So.. In the code you will have to only work with the window that works. perhaps from 90 to 189 or something. Yes, you can insert a voltage divider to fill out the whole spectrum more or less, but for what reason? It will not be more acurate, just higher in the resolution.
IR-distance thingeys from Sharp DOES produce strange results when something is too close etc. Just make sure your robot has reacted before this happens! Or place the sensor at the back on the robot..
Also; Sometimes the strange data of something too close produces numbers out of the normale working range / window / spectrum. Or faster jumps fron one extreme to another etc. This can be a way of telling that you are too close for actual measuring anything.
- And now you know why I use SRF05 :)
Yes, I figured that it
Yes, I figured that it wouldn't fill up the entire range and tried to have the code compensate. Here's what happens:
So the "out-of-range" number is in between the in-range numbers. And since the numbers fluctuate so much, when I tried to add code to compensate, it wouldn't work.
The SRF05 is starting to sound a lot better right now. What about PING from Parallax (http://tinyurl.com/4kclnx), have you used it before?
I don't know the Sharp
I am not sure you already
I am not sure you already considered this or not but just in case that you have not. The voltage to distance curve starts out as low setting even though the object is close and when the object moves further away the voltage will go up. This continues shortly until the object is farther than 10cm. This will give you a strange reading. You did not tell how close the object is to the sensor. Make sure that the object is not closer than 10cm. Also note that the curve is not linear.
Hmm it doe not sound all
Hmm it doe not sound all that nice.. "Hmm" is all I can say. Sorry. I do not have time to hook one up and try, sorry for that as well.
For Ping & Picaxe, you should talk to the expert, Chris The Carpenter
I'm using a similar sensor gp2d12
I found this but have not tried it yet...waiting for another proto board to work on first.
it's not a picaxe, but based on the same mcu family.
The guy notes the use of a 4.7mf cap for this sensor.
http://www.oopic.com/gp2d12.htm
Are you missing some resistors?
Once again, I have no idea what I am talking about but I noticed you are missing 2 resistors on your 18 board... I think they are called pull-down resistors. (Are pull down resistors only for digital inputs?). I have no idea what I am talking about. All I know it there are spaces for 2 resistors on that board. They are connected to the first two inputs. I have them installed and my sharp IR's are working. You don't have them and yours don't.
Again, I have no idea what I am talking about.
--Oh, Frits-- I'm not the Ping/picaxe expert! I'm the guy who says it won't work! -- I have seen some promising posts, but I have yet to see a video with it working!! :)
www.rocketbrandcustom.com baby!!
I got the ping/ picaxe
I got the ping/ picaxe working!
http://letsmakerobots.com/node/1346
Check out the 3rd video down, and the code is attached to the post.
Since it's an analogue
Since it's an analogue device, a pull up/down resistor doesn't make much sense(logic 1/0)...if anything I would guess it to be a current limiting resistor to prevent the mcu from getting fried if too much current were pushed to it. The input pins only sink/source 15-20ma from what I recall.