I’m currently using a maxbotic ultrasonic rangefinder http://www.sparkfun.com/commerce/product_info.php?products_id=639 connected to arduino on pin 1 analog, +5v and ground also connected. I can read quite well distance information but every now and then i get totally erroneous readings. For instance, I may read 220,220,210,8,222,218,220,14,7,217,220 etc. The small values have nothing to do with reality. Is there anything I could do to improve that? I think I read somewhere that if i’m not using the other analog ins i should connect them to ground to avoid wrong lectures, is that right?
Hey, that was quick!!!
I was just reading faq at maxbotic, and it said:
But if in your application the MaxSonar®-EZ1? analog voltage output has noise, there is an easy way to remove the noise on the analog voltage output. Place a 0.1uF capacitor near/at your analog to digital pin directly to your ground. Next place a 10K ohm resistor in series with the analog voltage output from the MaxSonar®-EZ1? to the 0.1uF capacitor. The time constant for this circuit will be 1mS. This will cause a 5mS delay to allow the voltage to settle. For slower readings and slightly less noise the resistor can be increased to 100K ohms and this will cause a 50mS delay. (If you are technical please read the sections following this answer for the reasons why this might be needed.)
So, I should connect ultrasound sensor->10k ohm resistor->analog in and in parallel ultrasound sensor->0.1uF capacitor->ground?
The MaxSonar-EZ1 should not allow readings that vary. So unless, there is another ultrasonic noise source in the room, or you are running two sensors at the same time, or there is an unusual beam path situation the output should be noise free. For example, say you dropped something on the table as this might cause a false reading from noise, or if there is an object just outside the main path, and sometimes the MaxSonar-EZ1 might detect the closer object. But false readings should not occur with the MaxSonar-EZ1. The web page here shows what you should expect. http://www.maxbotix.com/MaxSonar-EZ1__FAQ.html
For example the LV-MaxSoanr-EZ1 is 100% tested for no false readings before it is shipped, and the MaxSonar-EZ1 is basically the same sensor. If you have eliminated all other sources of noise, then your sensor may be the problem. We have worked to find the noise contributors with our customers, and we have replaced an occasional sensor (but to date, less than 0.2%). We will replace your sensor, if the noise is caused from the MaxSonar-EZ1 and not from your setup.
As for the analog voltage noise, the noise that the resistor/capacitor filters out, is noise that occurs when the analog voltage is being set. During the time when the MaxSonar-EZ1 sets the analog voltage, very short duration “spikes” a few uS wide, with an amplitude of a few mV may occur. If you have a fast microcontroller, it is possible (however unlikely) that you might pick up one of these spikes. In addition, noise could get picked up during the routing to the AD converter input. Both of these noise sources should only cause reading anomalies of an inch or so. But the resistor/capacitor will not help with readings that are off by more as they are caused by other issues.