Need help with sharp ir GP2Y0A02YK0F distance sensor

Dear all

I'm in the process to implementing a sharp GP2Y0A02YK0F (20-150cm) ir distance sensor in my project. Reading around it draw much more current than 30mA medium when it fires and that make the sensor to return some heavy spikes on the power supply and consequently bad distance reading.

After reading a lot I saw some solution adding capacitors and resistors here and there, but I'm not sure how to do that and which one solution is correct.

Could someone help me making the right filter? Note that my arduino platform is powered by eight 1.2v rechargeable batteries. Could be a problem?

Please help me. I'm pretty sure about the arduino code, but have problem with electronics.

Regards.

From the datasheet:

?Advice for the power supply
• In order to stabilize power supply line, we recommend to insert a by-pass capacitor of 10?F or more
between Vcc and GND near this product.

In your code you might also try calling analogRead() twice and only use the second result -- see if that gives a more reliable reading.

Dear Chagrin

thank's a lot for answering. I know what the datasheet say but looking around there are some other suggestion for best results. Unfortunatly I don't know which is better and how to translate it in a schema for breadboard testing... (as I said I'm not expert in electronic).

Please have a look here:

What's the right way?

Regards.

I know what the datasheet say

In electronics what the data sheet says should not be disregarded.

There are two things those threads suggest:-

  1. Improving the supply decoupling, like the data sheet says and you can read about here De-coupling

  2. Actually smoothing the analogue signal from the sensor to remove noise from it.

Try 1 first, only go to 2 when you have further problems.

In addition to the decoupling capacitor, In your second link there's a post that says you should also ground the black plastic case of the sensor. It would be something simple to try...

Thank you very much. I will try as explained in the datasheet.

Could you please help me in another thing? I'm working with 9*1.2V battery for arduino power totale 9.6V.

The sharp ir sensor work from 4.5 to 5.5V. Do I need to stabilize the power out of arduino for my sensor?

Regards.

The Arduino makes 5V from the 9.6V by means of an LM7805 (voltage regulator) If you connect the rangefinder to the Arduino 5V pin it should work.

Have played with a rangefinder too, resulted in the multiMap() function for interpolation of the distances, see - Arduino Playground - MultiMap
might be usefull,

Unfortunatly no luck :relaxed:

Spikes remain as you can see from serial output after adding 10uF capacitor as described in the ddaatasheet. Any hints?

I'm not doing any calculation, only value from sensor.

236
236
228 <--
238
237
236
236
238
237
236
238
236
236
237
236
236
238
228 <--
236
237
263 <---
237
236
237
236
236
237
239
236
236
236
237
228 <--
236
237
237
237
237
236
236
237
237
236
237
237
237
237
245 <--
237
237
236
237
241 <--
248 <--
237
236
236
237
237
237
232
236
236
236
237
237
237
243 <--
256 <--
237
236
236
236
236
237
237
237
237
236
237
236
237
237
237
237
238
237
243 <--

Mid to low 200 values are in the range of voltages which correspond to the bottom of the non-linear range of readings from the Sharp sensor. As a result, even moderate jumps in ADC values only correspond to relatively small changes in distance readings. Perform the conversion calculations and see what kind of variation you are getting in terms of actual distance readings.

If you're within +/- 1 cm in real world operation, you're doing excellent. If it's worse than around +/-3-5cm, then there's likely room for improvement. Don't expect too much from these sensors.

Here's a good resource for linearizing the output from these sensors:

Thank's a lot. Very good info you give.

I will try with distance calculation as soon as I can.
Below the distance formula used for this sensor in the shop where I bought it.

Distance (cm) = 9462/(SensorValue - 16.92)

You said to not expect too much from this sensor. Do you know any other Ir sensor with a range from 20 to 150cm or more?

Regards.

After some tests calculating distance measurements, I have spike values around.

Distance from the wall 105cm, this is what I had in serial monitor:

106
107
106
107
107
123 <-
107
106
107
95 <-
107
108
106
105
107
106
128 <-

and so on.

Seems a very difficult sensor to use for may application.

Could you show the code and wiring schematic for your setup?

Those spikes seem excessive.

Are you switching ADC channels in between readings?

Is your ADC circuitry well isolated?

Can you average ADC readings to mitigate the spikes? (keep in mind that the sensor operates relatively slowly, about 40ms between readings. This provides ample time to take multiple readings and average them to reduce the impact of noise on the ADC line.

Also, the surface the IR sensor is reading against can influence the results. A textured or specular surface can cause larger variations in readings. Also, going from brighter to lighter surfaces will change the readings as well. I can't remember the direction, but a black matte surface will read as either closer or farther away than a white matte surface, both at the same actual distance.

These reading are strange and might be caused by a low supply voltage.
The sensor should work at 3.3V, but if you have a 5V Arduino board, I would advise to use the 5V Vcc.

PS: I did some sensor calibration tests and created a small library:
http://arduino.cc/forum/index.php/topic,83947.0.html

I have made a detailed post and a video on how to perform disciplined calibration of SHARP distance sensors. The post can be found here:

https://aleksandarhaber.com/noise-reduction-and-calibration-of-distance-sensors-sharp-infrared-sensors/

and the video can be found here:

Best Regards,
Aleksandar Haber

Considering the thread is 8 years old and most contributors have closed their accounts here even I don't think it's very useful to add to it.