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?

Can you take a picture of
Can you take a picture of the wiring, and shortcuts?

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. :slight_smile: I figured out that on mine, 500 was about 3.5", and 200 was about 8".

See https://www.robotshop.com/letsmakerobots/node/672 to see how I dealt with the averaging. Works pretty well. Even though you are using a PicAxe, same theory applies.

 

No Voltage Regulator
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.

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.

circuit2.jpg

circuit1.jpg

circuit2_blank.jpg

circuit1_blank.jpg

 

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.

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:

Billede_11.png

What is returned if you attach nothing?

Good idea, I’ll attach a
Good idea, I’ll attach a potentiometer tonight and try it.

It is called a
It is called a turn-knob-thingey!

Right, right. I’ll try the
Right, right. I’ll try the “turn-knob-thingey” tonight. Thanks for the correction. :slight_smile:

Don’t forget to use hot glue
Don’t forget to use hot glue to keep it in place! (I think Frits sells the stuff)

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

0J387.jpg

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

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:

  • 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?

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 don’t know the Sharp
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.

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.