ESP32 KY-033 Line Tracking Sensor Module
Overview
The KY-033 is a line tracking sensor module that detects light-reflective and light-absorbing surfaces using infrared technology. It provides a digital output signal upon detecting a line, making it suitable for applications like robotic navigation and line-following projects.
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.
Where to Buy
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
Technical Specifications
Pinout Configuration
The VCC
pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND
pin is the ground connection and must be connected to the ground of your ESP32.
GND:
Connects to the ground of the circuit.VCC:
Supplies power to the module, typically 3.3V or 5V.S (Signal):
Outputs a digital signal indicating line detection.
Troubleshooting Guide
Common Issues
❌ No Line Detection
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.
⚠️ False Positives
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
🔍 Serial Monitor
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.
⚡ Voltage Checks
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
Code Examples
Arduino Example
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.
ESP-IDF Example
#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.
ESPHome Example
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 Example
platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
PlatformIO Example Code
#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.
MicroPython Example
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.
Conclusion
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.
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.