Line tracking sensor with RPi

Use a Line Tracker to detect if a door is open, or if a line is crossed with only one sensor and a raspberry pi

About

A simple exemple to create a line tracker or detect if a door is opened with only one KY-033 module and a raspberry PI, sensor from the “Elegoo37-1 Sensor Kit v2″ that Elegoo sent me.

This project is also compatible with the HW-006 v1.2 and some others tracker modules. This project includes a python code that is really simple to use.

Connect sensor through the GPIO

There is a very little manipulation to connect 3 pins of the sensor on the GPIO. Let’s see :

S is for Signal got to GPIO24[Pin 18] +V is for voltage go to 3, 3V [Pin 1],G is for ground and go to GND [Pin 6] (See shematic)

Install and start script

Python is required. Install it before doing anything.

Clone code exemple in this gist where you want in your RPi.

git clone https://gist.github.com/2299af0b2fbace8994b9fb9e409bc3f5.git

Open your command line and launch the script :

python tracer.py

Your code should display “Line detected ” when a dark line is near the sensor like in this exemple : https://streamable.com/e/gcu08m

Schematics

Code

Needed modules will be imported and configured

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

Declaration of the input pin which is connected with the sensor

GPIO_PIN = 18
GPIO.setup(GPIO_PIN, GPIO.IN, pull_up_down = GPIO.PUD_UP)

Break between the results will be defined here (in seconds)

delayTime = 0.2

print “#— Hackster project line tracker exemple —#”

main loop

try:
while True:
if GPIO.input(GPIO_PIN) == False:
print “Line detected”

        # Reset + Delay
        time.sleep(delayTime)

Scavenging work after the end of the program

except KeyboardInterrupt:
GPIO.cleanup()

Source: Line tracking sensor with RPi

Scroll to Top
Read previous post:
RIGOL DG952 2-CH 50MHZ ARBITRARY WAVEFORM FUNCTION GENERATOR
RIGOL DG952 2-CH 50MHZ ARBITRARY WAVEFORM FUNCTION GENERATOR

The Rigol DG952 50MHz Dual Channel Function Generator, although value-priced, provides highly-accurate 16-bit standard and arbitrary waveforms point by point from its huge 16Mpt memory....

Close