In this article, we connect a KY-033 Line Detector to a Raspberry Pi Pico, any Rp2040 type board will be suitable. We actually tested this with a Cytron Maker Pi Pico
We will use Micropython for these examples but of course you can use the Arduino IDE as well if you have Raspberry Pi Pico support enabled
This module has an IR transmitter/receiver, and an LM393 differential comparator mounted on a breakout board with a potentiometer and several resistors.
The KY-033 module detects if the surface in front of the infrared transmitter/receiver absorbs or reflects light. A dark surface will absorb the light while a light surface in turn will reflect the light. This means that if the surface is dark, the signal pin will be pulled HIGH. And if the surface is light, the signal pin will be LOW.
The indicator LED turns on when the infrared light is reflected back to the receiver, meaning that a line is not detected.
We can then of course check for that value by connecting that pin to a Pico and setting it to be an input
The sensor looks like this
Parts Required
You can connect to the module using dupont style jumper wire.
Name | Link | |
Raspberry Pi Pico | ||
37 in one sensor kit | ||
Connecting cables |
Schematic/Connection
Pico | SENSOR |
---|---|
GPIO27 | S |
3v3 | Middle pin |
GND | – |
Code Examples
Basic example
from machine import Pin from time import sleep # Initialization of GPIO27 as input sensor = Pin(27, Pin.IN, Pin.PULL_DOWN) # Continuous loop while True: if sensor.value() == 0: print("No line present") else: print("Line present") print("-------------------------------------") sleep(1)
REPL Output
Draw a thick black line on a piece of paper and move the sensor over it or just cover it with a black/dark object. You may have to adjust the potentiometer to adjust the sensitivity
MicroPython v1.17 on 2021-09-02; Raspberry Pi Pico with RP2040
Type “help()” for more information.
>>> %Run -c $EDITOR_CONTENT
No line present
————————————-
No line present
————————————-
No line present
————————————-
No line present
————————————-
No line present
————————————-
No line present
————————————-
Line present
Links
https://github.com/getelectronics/rp2040learning/tree/main/Sensor%20Kit/KY-033%20Line%20Detector