Sharp IR Sensor ( GP2Y0A2YK ) Accuracy problems

Hi guys, I'm working in this project where I'm measuring distance of objects passing by trough the sharp sensor. I'm checking every 50ms, and i will say 75% of the readings are correct values, but the other 25% are off by around +/- 10 cm. and I cannot accept that as it causes to trigger and event it shouldn't in my code. Has anyone using this sensor had similar problems?? The sensor is pretty straightforward to connect. I'm not sure what to do here, the formula i have works wonderful most of the times and the problems araises when the distance measured is in the higher end of the sensor (150cm) has anyone experienced something similar? what can i do? i was thinking of using and SR04 too to kind of validate the readings when the sensor is triggered to see if is a positive or a false positive. Any kind of feedback is appreciatted as i suppose I'm doing something wrong as the sensor cannot be off by soooo much distance.

Thanks

PS: The fitst read on the setup is there as in the sheet it says first read is unstable.

I Leave a snippet of my code here.

#define PINSHARP A5

float get_Sharp_Distance(int PinID)
{
// Read analog to digital converter value
float ADCValue = (float)analogRead(PinID);

// Convert in millimeters and return distance
return 2583.711122992086

  • 20.197897855471*ADCValue
  • 0.071746539329 ADCValueADCValue
  • 0.000115854182 ADCValueADCValue*ADCValue
  • 0.000000068590 ADCValueADCValueADCValueADCValue;

}

void setup(){
Serial.begin(9600);
pinMode(PINSHARP,INPUT);
get_Sharp_Distance(PINSHARP);
delay(100);
}

void loop (){
float DisSharp = get_Sharp_Distance(PINSHARP) / 10;
Serial.println(DisSharp);
delay(50);
}

It sound like a circuitry problem. Make sure you have decent decoupling, and you ground the ADC and sensor close to each other.

check also - Arduino Playground - MultiMap -