KY-032 Infrared Obstacle Avoidance Sensor Module

View on Amazon
Overview
About KY-032 Infrared Obstacle Avoidance Sensor Module
The KY-032 Infrared Obstacle Avoidance Sensor Module is designed to detect obstacles using infrared light. It emits infrared light, which, when reflected by an obstacle, is detected by a photodiode. The module outputs a digital signal indicating the presence or absence of an obstacle. This sensor is commonly used in robotics for obstacle detection and avoidance.
Get Your KY-032
💡 Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
KY-032 Specifications
Complete technical specification details for KY-032 Infrared Obstacle Avoidance Sensor Module
📊 Technical Parameters
KY-032 Pinout
The **KY-032** is a 4-pin infrared obstacle avoidance sensor module:
Visual Pinout Diagram

Pin Types
Quick Tips
**Interface**: Digital obstacle detection,🔦 **Sensor**: IR LED emitter + photodiode receiver pair,🚨 **Signal**: Active low - S pin goes LOW when obstacle detected
**Power**: 3.3V to 5V operation,📏 **Range**: 2-30cm adjustable (depends on potentiometer and object reflectivity),🎚️ **Adjustment**: Two potentiometers - one for distance, one for sensitivity
**Enable Pin**: Pull EN LOW to disable sensor, HIGH (or leave open) to enable,🎯 **Applications**: Robot obstacle avoidance, line following, proximity detection, object counting
Pin Descriptions
| Pin Name | Type | Description | Notes |
|---|---|---|---|
1 GND | Power | Ground connection | |
2 VCC | Power | Power supply | 3.3V or 5V |
3 S | Communication | Signal output | LOW when obstacle detected |
4 EN | Communication | Enable pin | Optional - controls sensor on/off |
Wiring KY-032 to ESP32
To interface the **KY-032** with an **ESP32** for obstacle detection:
Visual Wiring Diagram

Connection Status
Protocol
Pin Connections
| KY-032 Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 GND Required | GND | Ground | |
2 VCC Required | 3.3V or 5V | Power supply | |
3 S Required | GPIO16 | Digital input (any GPIO) | |
4 EN Optional | GPIO17 or VCC | Enable control (optional) |
**Detection Logic**: S pin reads LOW when obstacle present, HIGH when clear
**Distance Tuning**: Adjust onboard potentiometer to set detection range (2-30cm)
**Sensitivity Tuning**: Second potentiometer adjusts response to different surface colors/materials
**Enable Control**: Connect EN to GPIO for software on/off, or tie to VCC for always-on
**LED Indicators**: Power LED and detection status LED onboard
**Ambient Light**: Works best indoors - sunlight can cause false readings
**Pull-up**: Internal pull-up on S pin recommended for stable HIGH state
**Robot Use**: Mount at appropriate height for target obstacles (usually 5-15cm above ground)
KY-032 Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
Issue: The sensor does not detect obstacles.
Solutions:
- Ensure proper wiring connections and verify the power supply voltage.
- Adjust the sensitivity and detection distance using the onboard potentiometers.
- Check for any obstructions or dirt on the sensor's infrared emitter and receiver.
Issue: The sensor indicates obstacles when none are present.
Solutions:
- Reduce the sensitivity using the potentiometer to prevent detection of distant or small objects.
- Ensure the sensor is not exposed to direct sunlight or strong ambient infrared sources.
- Verify that the sensor is securely mounted to prevent vibrations or movements that could cause false readings.
Debugging Tips
Use the Serial Monitor to check for error messages and verify the sensor's output. Add debug prints in your code to track the sensor's state.
Use a multimeter to verify voltage levels and check for continuity in your connections. Ensure the power supply is stable and within the sensor's requirements.
Additional Resources
KY-032 Programming Examples
Ready-to-use code examples for different platforms and frameworks
int sensorPin = 10; // Sensor input pin
void setup() {
pinMode(sensorPin, INPUT);
Serial.begin(9600);
Serial.println("KY-032 Obstacle Detection Test");
}
void loop() {
int sensorValue = digitalRead(sensorPin);
if (sensorValue == LOW) { // Obstacle detected
Serial.println("Obstacle detected");
} else {
Serial.println("No obstacle");
}
delay(500);
}This Arduino code initializes the sensor input pin and serial communication. In the loop, it reads the sensor value and prints "Obstacle detected" or "No obstacle" to the serial monitor based on the sensor's digital output.
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#define SENSOR_PIN GPIO_NUM_16
void app_main(void) {
gpio_config_t io_conf = {
.intr_type = GPIO_INTR_DISABLE,
.mode = GPIO_MODE_INPUT,
.pin_bit_mask = (1ULL << SENSOR_PIN),
.pull_up_en = GPIO_PULLUP_ENABLE
};
gpio_config(&io_conf);
printf("KY-032 Obstacle Detection Test\n");
while (1) {
int sensor_value = gpio_get_level(SENSOR_PIN);
if (sensor_value == 0) { // Obstacle detected
printf("Obstacle detected\n");
} else {
printf("No obstacle\n");
}
vTaskDelay(pdMS_TO_TICKS(500));
}
}This ESP-IDF code configures GPIO16 as an input with a pull-up resistor. It continuously reads the sensor's state and prints "Obstacle detected" or "No obstacle" to the console based on the sensor's output.
binary_sensor:
- platform: gpio
pin:
number: GPIO16
mode: INPUT_PULLUP
name: "KY-032 Obstacle Sensor"
device_class: motion
filters:
- invert:
on_press:
then:
- logger.log: "Obstacle detected"
on_release:
then:
- logger.log: "No obstacle detected"This ESPHome configuration sets up the KY-032 obstacle avoidance sensor as a binary sensor on GPIO16. It logs messages when an obstacle is detected and when it is cleared. The input is inverted to match the sensor's logic.
platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduinomain.cpp
#include <Arduino.h>
#define SENSOR_PIN 16
void setup() {
pinMode(SENSOR_PIN, INPUT_PULLUP);
Serial.begin(115200);
Serial.println("KY-032 Obstacle Sensor Test");
}
void loop() {
int sensor_value = digitalRead(SENSOR_PIN);
if (sensor_value == LOW) {
Serial.println("Obstacle detected");
} else {
Serial.println("No obstacle");
}
delay(500);
}This PlatformIO code sets up GPIO16 as an input with a pull-up resistor for the KY-032 sensor. It prints "Obstacle detected" or "No obstacle" to the serial monitor based on the sensor's state.
import machine
import time
SENSOR_PIN = machine.Pin(16, machine.Pin.IN, machine.Pin.PULL_UP)
while True:
if SENSOR_PIN.value() == 0:
print("Obstacle detected")
else:
print("No obstacle")
time.sleep(0.5)This MicroPython script configures GPIO16 as an input with a pull-up resistor for the KY-032 sensor. It continuously checks for obstacles and prints the corresponding message every 500ms.
Wrapping Up KY-032
The ESP32 KY-032 Infrared Obstacle Avoidance Sensor Module is a powerful KY-0xx module sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.
Best Practices
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Safety First
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.
Ready to Start Building?
Now that you have all the information you need, it's time to integrate the KY-032 into your ESP32 project and bring your ideas to life!
Explore Alternative Sensors
Looking for alternatives to the KY-032? Check out these similar sensors that might fit your project needs.

KY-029 Dual Color LED Module
The KY-029 is a dual-color LED module featuring a 3mm LED that emits red and green light. By adjusting the intensity of each color using...

KY-001 Temperature Sensor Module
The KY-001 is a temperature sensor module that operates within a wide temperature range. It supports 1-Wire communication and is based on...

KY-009 RGB Full Color LED SMD Module
The KY-009 is an RGB LED module that allows for the creation of various colors by adjusting the brightness of its red, green, and blue LEDs...





