KY-033 Line Tracking Sensor Module

View on Amazon
Overview
About KY-033 Line Tracking Sensor Module
The KY-033 Line Tracking Sensor Module is designed for line-following robots and similar applications. It utilizes an infrared emitter and receiver to detect the presence of a line by differentiating between light-reflective and light-absorbing surfaces. The module outputs a digital signal indicating whether it is over a line or not. Sensitivity can be adjusted using the onboard potentiometer.
Get Your KY-033
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
KY-033 Specifications
Complete technical specification details for KY-033 Line Tracking Sensor Module
📊 Technical Parameters
KY-033 Pinout
The **KY-033** is a 3-pin line tracking sensor module:
Visual Pinout Diagram

Pin Types
Quick Tips
**Interface**: Digital line detection,🔦 **Sensor**: IR LED emitter + phototransistor receiver pair,🚨 **Signal**: Active low - S pin LOW when over black line, HIGH over white/reflective surface
**Power**: 3.3V to 5V operation,📏 **Detection Height**: Optimal 2-10mm above surface,🎚️ **Adjustment**: Onboard potentiometer for sensitivity tuning
**LED Indicators**: Power LED and detection status LED,🎯 **Applications**: Line-following robots, automated guided vehicles (AGV), track detection
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 line detected, HIGH over white surface |
Wiring KY-033 to ESP32
To interface the **KY-033** with an **ESP32** for line tracking:
Visual Wiring Diagram

Connection Status
Protocol
Pin Connections
| KY-033 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) |
**Detection Logic**: S reads LOW on black line, HIGH on white/reflective surface
**Calibration**: Adjust potentiometer for optimal contrast detection on your surface
**Mounting Height**: Keep sensor 2-10mm above surface for best performance
**Pull-up**: Internal pull-up recommended for stable HIGH state
**Multi-Sensor Arrays**: Use multiple sensors (3-5) for robust line following
**Ambient Light**: Works best indoors - bright sunlight can interfere
**Power LED**: Always on when powered
**Status LED**: Lights when line (dark surface) detected
KY-033 Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
Issue: The sensor does not detect lines.
Solutions:
- Ensure proper wiring connections and verify the power supply voltage.
- Adjust the sensitivity using the onboard potentiometer to suit the surface and lighting conditions.
- Check for any obstructions or dirt on the sensor's infrared emitter and receiver.
Issue: The sensor indicates a line when none is present.
Solutions:
- Reduce the sensitivity using the potentiometer to prevent detection of unintended surfaces.
- Ensure the sensor is not exposed to direct sunlight or strong ambient infrared sources.
- Verify that the sensor is mounted at an appropriate height and angle relative to the surface.
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-033 Programming Examples
Ready-to-use code examples for different platforms and frameworks
int linetracking = 10; // Declaration of the sensor input pin
int value; // Temporary variable
void setup() {
pinMode(linetracking, INPUT); // Initialization sensor pin
digitalWrite(linetracking, HIGH); // Activation of internal pull-up resistor
Serial.begin(9600); // Initialization of the serial monitor
Serial.println("KY-033 Linetracking");
}
void loop() {
// The current signal at the sensor is read out.
value = digitalRead(linetracking);
// If a signal could be detected, this is displayed on the serial monitor.
if (value == HIGH) {
Serial.println("Line recognized");
delay(200); // 200 ms break
}
}This Arduino code initializes the sensor input pin and serial communication. In the loop, it reads the sensor value and prints "Line recognized" to the serial monitor when a line is detected. A 200 ms delay is added to debounce the sensor readings.
#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-033 Line Tracking Sensor Test\n");
while (1) {
int sensor_value = gpio_get_level(SENSOR_PIN);
if (sensor_value == 1) { // Line detected
printf("Line recognized\n");
} else {
printf("No line detected\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 "Line recognized" or "No line detected" to the console based on the sensor's output.
binary_sensor:
- platform: gpio
pin:
number: GPIO16
mode: INPUT_PULLUP
name: "KY-033 Line Tracking Sensor"
device_class: motion
filters:
- invert:
on_press:
then:
- logger.log: "Line detected"
on_release:
then:
- logger.log: "No line detected"This ESPHome configuration sets up the KY-033 line tracking sensor as a binary sensor on GPIO16. It logs messages when a line is detected and when no line is present. 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-033 Line Tracking Sensor Test");
}
void loop() {
int sensor_value = digitalRead(SENSOR_PIN);
if (sensor_value == HIGH) {
Serial.println("Line detected");
} else {
Serial.println("No line detected");
}
delay(500);
}This PlatformIO code sets up GPIO16 as an input with a pull-up resistor for the KY-033 sensor. It prints "Line detected" or "No line detected" 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() == 1:
print("Line detected")
else:
print("No line detected")
time.sleep(0.5)This MicroPython script configures GPIO16 as an input with a pull-up resistor for the KY-033 sensor. It continuously checks for lines and prints the corresponding message every 500ms.
Wrapping Up KY-033
The ESP32 KY-033 Line Tracking 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-033 into your ESP32 project and bring your ideas to life!








