Line Tracking Sensor with Raspberry Pi – Simple KY‑033 Door/Line Detector
Learn how to use a single KY‑033 line‑tracking sensor to detect whether a door is open or to sense a line crossing, all with a Raspberry Pi. The following guide covers wiring, installation, and a ready‑to‑run Python script.
About This Project
This concise example demonstrates how the Elegoo 37‑1 Sensor Kit v2 (or compatible HW‑006 v1.2) can turn a single sensor into a reliable door‑status or line‑tracking detector. It’s perfect for robotics, security, or DIY automation projects.
Connecting the Sensor to the GPIO
The KY‑033 has three pins: Signal (S), +V, and Ground (G). Connect them as follows:
- Signal (S) → GPIO 24 (Pin 18)
- +V → 3.3 V (Pin 1)
- G → GND (Pin 6)
Refer to the schematic for a visual guide.
Installing the Software
Ensure Python is installed on your Raspberry Pi. Then clone the sample code from the following Gist and run it.
git clone https://gist.github.com/2299af0b2fbace8994b9fb9e409bc3f5.git
Navigate to the cloned directory and execute:
python tracer.py
The script will output Line detected whenever a dark line is detected beneath the sensor. You can test this in action here.
Wiring Diagram

Python Code
Below is the complete script. It sets up the GPIO pin, reads the sensor, and prints a message when a line is detected.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
# GPIO pin connected to the sensor’s Signal pin
GPIO_PIN = 18
GPIO.setup(GPIO_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Delay between readings (seconds)
delayTime = 0.2
print("#— Hackster project line tracker example —#")
try:
while True:
if GPIO.input(GPIO_PIN) == False:
print("Line detected")
time.sleep(delayTime)
except KeyboardInterrupt:
GPIO.cleanup()
Source: Line tracking sensor with RPi
Manufacturing process
- Connecting HC‑SR04 Ultrasonic Sensor to Raspberry Pi 3 – A Complete Guide
- Build a Robust Temperature & Sensor API on Raspberry Pi Using the GY‑91 Module
- Advanced Raspberry Pi Table Tennis Ball Tracking with OpenCV
- Testing the DS18B20 Temperature Sensor on Raspberry Pi
- Master Raspberry Pi GPIO: Interfacing a PIR Motion Sensor on B+/Model 2
- Raspberry Pi Home Security System: PIR Motion Detection + Camera Email Alerts
- How to Connect, Calibrate, and Program the HC‑SR501 PIR Motion Sensor with a Raspberry Pi
- Digital Light Sensor – Power an LED with Ambient Light Using Windows 10 IoT Core
- Installing a Raspberry Pi Camera in a Birdhouse – Step‑by‑Step Guide
- Build an IR Sensor Project with Arduino UNO – Simple Guide