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.
Can you take a picture of the wiring, and shortcuts?

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.


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.

  • The motor controller is connected to a section of the darlington DIP socket through a line of header pins (not connected in the pictures).
  • I originally soldered the IR sensor wires to the Picaxe board directly but when I wanted to try adding the capacitor I had to move it to the other board.
  • The looped white wire at the top left of the the Picaxe board is the wire "shorting" the zero analog input.

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.


It might also be important to know that I'm currently bypassing the voltage regulator in the pictures and connecting 4 AA batteries straight to the system and all the components.

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


    readadc 1, b1


    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 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:Billede_11.png

What is returned if you attach nothing? 

Good idea, I'll attach a potentiometer tonight and try it.
It is called a turn-knob-thingey!