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?
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".
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.
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.
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 ;)”
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?
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.
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...
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.
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 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 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.