I'm in the very early stages of trying to build a robot that wanders around and builds up a map of its environment. I'm using an Arduino and I currently have a Sharp 2Y0A21 IR range detector sat on top of a servo so it can take a 180 degree sweep in 10 degree increments.
The trouble is that the voltage readings back from the Sharp IR sensor aren't consistent. If I write an app that simple sends the value it reads from the sensor through the serial port and display it on my laptop, sitting the sensor pointing at an object, the values bounce around.
Watching the values, I can see that it tends to report one value more than the rest, so I wrote a SharpReader class that takes 20 samples and then returns the Mode of these values. This now means I get more consistent values, but not as good as I would like.
I have some code that performs the 180 degree scan and sends the angle and distance down the serial. I then have a python script that receives these values and draws what it sees on screen, ignoring any values at either end of the sensors range. So putting it in front of a box, it should draw a straight line on screen, but it doesn't - the line is crooked and not consistently crooked, which confirms to me that it's the readings that are off, not my code.
I have read in the datasheet that it is advisable to put a capacitor (can't remember the value offhand) in between the GND and PWR lines on the Sharp IR - I tried forcing the legs of the capacitor into the JST connector of the Sharp IR, but it made no difference. I'll try soldering it to the sensor and see if that makes any difference.
Can anyone recommend anything else to try, or am I just expecting too much from the Sharp IR?
I'm also considering buying a second servo and Sharp IR and running two at the same time like a pair of eyes, then trying to take an average of the two values to see if that increases the accuracy.
BTW, I'm a newbie to electronics, my background is in programming.