Go Down

Topic: Sharp GP2Y0A02YK0F linearizing voltage (Read 2708 times) previous topic - next topic


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() {
   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(' ');


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.




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


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

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



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


int val;  
int distance = 0;

void setup()

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

doesnt work for my model, can anyone helpme?



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) :
Sorry in french but interresting. (thanks again Luj06   ;) )


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


Go Up