You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 24, 2026. It is now read-only.
The datasheet for this SharpIR sensor shows a non-linear mapping between the output voltage and distance, but this package uses an average linear mapping calculation. This causes lines that should be straight to become curved in scan plots.
I solved this by not using this package, but instead by writing 2 semi-linear maps that use data directly from the analogRead() which gives me a lot more accurate results:
int getDistance(int sensorPin, int numberOfSamplesToCollect, int samplingRate) {
int distance = 0;
int distancesSum = 0;
for (int i = 0; i < numberOfSamplesToCollect; i++) {
int analogSensorReading = analogRead(sensorPin);
if(analogSensorReading > 200) {
distance = map(analogSensorReading, 544, 200, 15, 60);
} else {
distance = map(analogSensorReading, 175, 81, 70, 150);
}
distancesSum += distance;
delay(samplingRate);
}
int averageDistance = distancesSum / numberOfSamplesToCollect;
return averageDistance;
}
SOLVED
This caught me out.
The datasheet for this SharpIR sensor shows a non-linear mapping between the output voltage and distance, but this package uses an average linear mapping calculation. This causes lines that should be straight to become curved in scan plots.
I solved this by not using this package, but instead by writing 2 semi-linear maps that use data directly from the analogRead() which gives me a lot more accurate results: