#define SENSOR_PIN 18 // ESP32 pin GIOP18 connected to OUT pin of IR obstacle avoidance sensor
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// initialize the Arduino's pin as an input
pinMode(SENSOR_PIN, INPUT);
//initialize the led pin as output
pinMode(4,OUTPUT);
}
void loop() {
// read the state of the the input pin:
int state = digitalRead(SENSOR_PIN);
if (state == LOW)
Serial.println("The obstacle is present");
else
Serial.println("The obstacle is NOT present");
delay(100);
if(state==LOW)
digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(4, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}