Index
Introduction
The IR Infrared Obstacle Avoidance Sensor detects obstacles by emitting infrared light and measuring the reflected signal.
It provides a digital output (HIGH or LOW) depending on whether an object is detected.
The ESP32-S3 can read the sensor’s output and take appropriate action, such as stopping or turning a motor.
In this tutorial, we’ll interface the IR sensor with the ESP32-S3 to detect obstacles.
Required Components
- ESP32-S3 Board
- IR Sensor
- Jumper wires
- Breadboard (optional)
Pinout

Circuit Diagram / Wiring
- IR SENSOR VCC → VIN, 3.3V (ESP32-S3)
- IR SENSOR GND → GND (ESP32-S3)
- IR SENSOR OUT → GPIO 15 (ESP32-S3)
Code / Programming
/*
Filename: ol_ir_obstacle_sensor.ino
Description: Reads IR obstacle sensor and prints detection status via Serial Monitor
Author: www.oceanlabz.in
Modification: 1/4/2025
*/
#define IR_SENSOR_PIN 15 // Define IR sensor pin
void setup() {
Serial.begin(115200); // Start serial communication
pinMode(IR_SENSOR_PIN, INPUT); // Set IR sensor pin as input
}
void loop() {
int sensorValue = digitalRead(IR_SENSOR_PIN); // Read sensor value
if (sensorValue == HIGH) {
Serial.println("No Obstacle"); // No obstacle detected
} else {
Serial.println("Obstacle Detected"); // Obstacle detected
}
delay(500); // Wait for 500 milliseconds
}
Explanation
- The
IR_SENSOR_PIN
reads a digital HIGH or LOW value depending on obstacle detection. - If the value is HIGH, no obstacle is detected; if LOW, an obstacle is present.
- The sensor value is printed to the Serial Monitor for feedback.
Troubleshooting
- Ensure that the sensor is powered correctly (VCC to 3.3V, VIN and GND to GND) and that the output pin is connected to the ESP32-S3.
- If the sensor continuously reads “Obstacle Detected,” check if the sensor is too close to a surface or incorrectly calibrated.
- If no readings are displayed, ensure the sensor’s wiring is secure and the ESP32’s GPIO is set to INPUT.