Thursday, January 31, 2013

Trying the Sharp Sensor

The datasheet  of GP2Y0A02YK0F might be handy...

I first connected GND to ground, VCC to +5 V pins and V0 to Analog zero (A0)

And first tried an slightly adapted version of ReadAnalogVoltage

void setup() {
  Serial.begin(115200);
}
void loop() {
  int sensorValue = analogRead(A0);
  float voltage = sensorValue * (5.0 / 1023.0);
  Serial.println(voltage);
  delay(1000);
}
 The output is the voltage on AO


2.45
2.33
0.48
1.62
2.17
2.23
0.36
0.36
0.34
1.11
0.02
1.80
1.83
1.97
2.11
2.15
2.33
2.39
High values are close range and low values are long range just like the datasheet tells me.

Next step change measurements to the metric system. 
I found this blog post doing a linear mapping. But the datasheet() shows me its a nonlinear relationship between distance and voltage so I would like to find a arduino library.

Yay a little googleing later I found http://code.google.com/p/gp2y0a21yk-library/ but that is for the little brother of this sensor with lower range...

And then I found this resource for linearizing output ... 

to be continued....


No comments:

Post a Comment