Go Down

Topic: Sharp GP2Y0A02YK0F linearizing voltage (Read 1 time) previous topic - next topic

cadrogui

Mar 24, 2010, 07:36 pm Last Edit: Mar 24, 2010, 07:39 pm by cadrogui Reason: 1
i, im buid a project with an arduino Duemilanove, im using a  Sharp GP2Y0A02YK0F IR Sensor, but the output voltage is non linear, i really need obtain a true value of proximity object, anyone can helpme in this situation?

im used this code:

#define sensorPin 0
#define VOLTS_PER_UNIT    .0049F        // (.0049 for 10 bit A-D)
float volts;
float inches;
float proxSens = 0;
int cm;

void setup() {
 
 beginSerial(9600);
   pinMode(sensorPin, INPUT);

}

void loop() {
proxSens = analogRead(sensorPin);
     volts = (float)proxSens * VOLTS_PER_UNIT; // ("proxSens" is from analog read)
 inches = 23.897 * pow(volts,-1.1907); //calc inches using "power" trend line from Excel
 cm = 60.495 * pow(volts,-1.1904);     // same in cm
 if (volts < .2) inches = -1.0;        // out of range    
   Serial.print(cm);
   Serial.print(' ');

}

but is not precise, the values are not linear, ex: when i put an objetct to 20 cm, the output says 21-22 cm, and when put an objetct to 3 cm, the ouput says 28-30 cm.

the pin order is this:

pin 0 (analogic input) -> output voltage from IR Sensor
pin 5V -> input Voltage in IR Sensor
GND -> GND Ir Sensor


i need a way to mesure the distance an objetct from 3 cm and up.

i apreciate your help.

tnx

startx

Hello,

The range of GP2Y0A02YK0F is 20cm ~ 150cm.
If you need to  measure distance from 3cm to 20cm, use another sensor.

cadrogui

yes, but if lineralize the output voltage can be work?

the issue on this web is taht i dont understand the topic

http://www.acroname.com/robotics/info/articles/irlinear/irlinear.html

tnkx

pd: i buy 10 of this IR... Duhhh  :'(

cadrogui

int val;  
int distance = 0;

void setup()
{
 Serial.begin(9600);
}

void loop()
{
 val = analogRead(0);
 distance = (6787 / (val + 5)) - 1;
 
 Serial.print("Valor Analogo: ");
 Serial.print(val);
 
 Serial.print(" - Distancia Lineal: ");
 Serial.print(distance);
 
 Serial.println(" ");
 delay(1000);
}

doesnt work for my model, can anyone helpme?

tnxs

startx

#4
Mar 24, 2010, 11:26 pm Last Edit: Mar 24, 2010, 11:29 pm by startx Reason: 1
I don't think it's possible to linearize values between 0 to 20 cm.
You can see graph for the GP2D120 (same familly) :
http://www.pobot.org/IMG/png/courbe_sharp.png
Sorry in french but interresting. (thanks again Luj06   ;) )

cadrogui

snif... yes its impossible!!!...

thanks!!!

Go Up