Let's Make Robots!

Sharp Range Sensor gives inconsistent results

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? 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I'm getting exactly the same problem (as I understand it) as the OP with a Sharp 3cm - 30cm analogue sensor.  Within the range 3cm to 30cm, the analogue output is exactly as per the graph - i.e. 3V down to 0.5V.  Also, below 3cm the output drops off again, as per the graph.  The strangeness occurs when the distance to an object is BEYOND 30cm.  The output rapidly increases from 0.5V to a constant level of around 1V and stays there.  I have included the 10uF decoupler near the device, am measuring with a scope and in an optically quiet environment. 

The sensor is performing to spec - It is a 3 to 30cm sensor, but the 1V out of range is annoying as any simple program would indicate an object at 10cm or so.  I think the way around it is to define a 'dead band' in the code where values are ignored, but this would chop a chunk out of the detection range.




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.

 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 working!


Check out the 3rd video down, and the code is attached to the post.



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. 


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 

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 wouldn't fill up the entire range and tried to have the code compensate.  Here's what happens:

  • When nothing is in range it fluctuates between 90 - 100 (but this isn't consistant).
    • So I set the code to assume there is nothing in front of it if the number was above 100.
  • When something comes within range it starts around 70 - 80 and then goes up to 130 as the object gets closer.

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 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. 

I don't know the Sharp sensor, but try measuring on the output pin with a voltmenter (without anything connected to it but power) to see if the output voltage from the unit is stable. If it is, I suppose that your sensor is ok and the error might be electrical noise in the wires or in the A/D converter.