Preview:
int LED = 5; 
int isObstaclePin = A0; // This is our input pin
int isObstacle = LOW; // HIGH MEANS NO OBSTACLE

void setup() {
  pinMode(LED, OUTPUT);
  pinMode(isObstaclePin, INPUT);
}

void loop() {
  isObstacle = analogRead(isObstaclePin);
  if (isObstacle == HIGH) {
    digitalWrite(LED, HIGH);
    delay(500);
    digitalWrite(LED, LOW);
    delay(500);
    
  } else {
    digitalWrite(LED, LOW);
  }

}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter