I'm building a self-navigating robot that uses IR sensor (GP2Y0A21YK0F model) with Arduino to navigate through a terrain, however during testing phase when I put my hand closer than 7cm it bugs and doesn't detect if anything can be closer than that distance as you can see on the screenshot.
The code I am using for distance measurement:
#include <SharpIR.h>
// Define model and input pin:
#define IRPin A0
#define model 1080
// Create variable to store the distance:
int distance_cm;
/* Model :
GP2Y0A02YK0F --> 20150
GP2Y0A21YK0F --> 1080
GP2Y0A710K0F --> 100500
GP2YA41SK0F --> 430
*/
// Create a new instance of the SharpIR class:
SharpIR mySensor = SharpIR(IRPin, model);
void setup() {
// Begin serial communication at a baudrate of 9600:
Serial.begin(9600);
}
void loop() {
// Get a distance measurement and store it as distance_cm:
distance_cm = mySensor.distance();
// Print the measured distance to the serial monitor:
Serial.print("Mean distance: ");
Serial.print(distance_cm);
Serial.println(" cm");
delay(1000);
}