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
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 :
Your code should display “Line detected ” when a dark line is near the sensor like in this exemple : https://streamable.com/e/gcu08m
Needed modules will be imported and configured
import RPi.GPIO as GPIO
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 —#”
if GPIO.input(GPIO_PIN) == False:
print “Line detected”
# Reset + Delay time.sleep(delayTime)
Scavenging work after the end of the program
Source: Line tracking sensor with RPi
Low cost PCB at PCBWay - only $5 for 10 PCBs and FREE first order for new members
PCB Assembly service starts from $30 with Free shipping all around world + Free stencil
Extra 15% off for flex and rigid-flex PCB