Pages: [1]   Go Down
Author Topic: Need help with sharp ir GP2Y0A02YK0F distance sensor  (Read 3685 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 0
Posts: 381
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Dubuque, Iowa, USA
Offline Offline
Edison Member
*
Karma: 31
Posts: 2270
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Sr. Member
****
Karma: 0
Posts: 381
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

- http://letsmakerobots.com/node/23297
- http://electronics.stackexchange.com/questions/17754/where-to-place-a-capacitor-to-smoothen-ir-sensor-reading
- http://www.societyofrobots.com/robotforum/index.php?topic=2712.msg32989#msg32989

What's the right way?

Regards.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31534
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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 http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

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

Dubuque, Iowa, USA
Offline Offline
Edison Member
*
Karma: 31
Posts: 2270
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Sr. Member
****
Karma: 0
Posts: 381
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12482
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 - http://arduino.cc/playground/Main/MultiMap
might be usefull,
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Sr. Member
****
Karma: 0
Posts: 381
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Unfortunatly no luck  smiley-slim

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 <--
Logged

New Hampshire
Offline Offline
God Member
*****
Karma: 13
Posts: 779
There are 10 kinds of people, those who know binary, and those who don't.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
http://www.acroname.com/robotics/info/articles/irlinear/irlinear.html
Logged


Offline Offline
Sr. Member
****
Karma: 0
Posts: 381
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Sr. Member
****
Karma: 0
Posts: 381
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

New Hampshire
Offline Offline
God Member
*****
Karma: 13
Posts: 779
There are 10 kinds of people, those who know binary, and those who don't.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Belgium
Offline Offline
Newbie
*
Karma: 2
Posts: 25
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: