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.