Hi All, I am having trouble getting clean data out of this sensor.
I follow this guide:
http://www.robotshop.com/PDF/Sharp_GP2Y0A02YK_Ranger.pdf
and have created two methods in C#:
public void GetRange(ref double Range, ref bool Success, AnalogInput sensor)
{
double Voltage = 0;
const double MinVolt = 0.4;
const double MaxVolt = 2.8;
// This pin number is for a BX-24. The pin number may need to be changed
// depending on the BasicX system being used.
Voltage = sensor.Read();
// Convert to voltage.
Voltage = Voltage * 5.0;
var r = VoltageToRange(Voltage);
// Check for legal voltage.
if ((Voltage >= MinVolt) & (Voltage <= MaxVolt))
{
Success = true;
Range = r;
}
else
{
Success = false;
}
}
//-------------------------------------------------------------------------------
private double VoltageToRange(double V)
{
// Returns distance in units of cm.
const double A = 0.0082712905;
const double B = 939.57652;
const double C = -3.3978697;
const double D = 17.339222;
// Curve fit.
return (A + B * V) / (1 + C * V + D * V * V);
}
The values that I am getting seem to be in 15-80 range when the senor is meant to be 20cm-150cm range.
I have tried a 100uf Cap between the power and ground, and it doesnt seem to smooth out any of the values.
At 60cm constant distance, I am getting random values between 36 and 48, with or without the cap.
I have the sensor connected to a breakout board plugged into socket 9 of the extender which has a P0.12/AD6.
The guide says I should put a 470 ohm resistor on the signal list yet if I do is it will reduce the values converted even further?
Little help please anyone.