Here is the code I used. I've tried adjusting the potentiometers on the sensor but still no success.
I've tried different code online and still have the same problem. Also tried with different arduino boards (uno and mega) and still no success.
int LED = 13;
int isObstaclePin = 2;
int isObstacle = HIGH;
void setup() {
pinMode(LED, OUTPUT);
pinMode(isObstaclePin, INPUT);
Serial.begin(9600);
}
void loop() {
isObstacle = digitalRead(isObstaclePin);
if (isObstacle == LOW)
{
Serial.println("Obstacle");
digitalWrite(LED, HIGH);
}
else
{
Serial.println("clear");
digitalWrite(LED, LOW);
}
delay(200);
}