Raspberry Pi Laser Tripwire
by zdt030303 in Circuits > Raspberry Pi
292 Views, 2 Favorites, 0 Comments
Raspberry Pi Laser Tripwire
Hi, this is Daitian Zhao, Junmo Kim, Kyle Carter. This project is for ECET38001 class at Purdue. The main goal is to create an alarm system for your home in a budget of $100.
Supplies
-LDR $ 5.87
-LED lights $ 5.34
-microcontroller $ 49.07
-Laser pointer $ 9.78
-resistors $ 8.56
-buzzer $0.95
-wires
-Breadboard
Check All the Components
The first step is to make sure that you get all the components. Check them with the supplies listed above!
Assembly
-connect LDR, LED lights, buzzer, and resistors to the breadboard as shown in the figure.
-connect those connections to the microcontroller according to the GPIO of the microcontroller
You can choose GPIO pins by yourself and change the code on the next step
Prepare for Coding
Once you are going to code, you need to use Python in the Raspberry Pi to code!
Do Coding ! (LED Settings)
Here is the code for the Raspberry Pi.
This is the part for the LED.
import RPi.GPIO as GPIO
import time
from gpiozero import LightSensor, LED, Buzzer
ldr = LightSensor(17)
LED_RED = 11
LED_GREEN = 12
buzzer = Buzzer(13)
while True:
if ldr.value <= 700:
GPIO.output(LED_GREEN, GPIO.LOW)
- import RPi.GPIO as GPIO: This line imports the RPi.GPIO library, which provides a way to control the GPIO pins of the Raspberry Pi. The as GPIO part allows you to refer to the library as GPIO in your code.
- import time: This imports the time module, which can be used for time-related tasks like delays.
- from gpiozero import LightSensor, LED, Buzzer: This line imports specific classes from the gpiozero library: LightSensor, LED, and Buzzer. These classes provide a simpler and more intuitive interface for interacting with these types of hardware components.
- ldr = LightSensor(17): Initializes a light sensor (LDR - Light Dependent Resistor) connected to GPIO pin 17.
- LED_RED = 11: Sets the variable LED_RED to 11, presumably representing the GPIO pin number to which a red LED is connected.
- LED_GREEN = 12: Sets the variable LED_GREEN to 12, presumably representing the GPIO pin number to which a green LED is connected.
- buzzer = Buzzer(13): Initializes a buzzer connected to GPIO pin 13.
- while True:: Starts an infinite loop.
- if ldr.value <= 700:: Checks if the value of the light sensor is less than or equal to 700. This value is a threshold to determine whether it's dark or light.
- GPIO.output(LED_GREEN, GPIO.LOW): If the light sensor value is less than or equal to 700, this line turns off the green LED by setting the GPIO pin to LOW (0V).
Do Coding!(Buzzer)
This is the part for setting up the buzzer.
buzzer.on()
GPIO.output(LED_RED, GPIO.HIGH)
time.sleep(1)
GPIO.output(LED_RED, GPIO.LOW)
time.sleep(1)
else:
GPIO.output(LED_RED, GPIO.LOW)
buzzer.off()
GPIO.output(LED_GREEN, GPIO.HIGH)
- buzzer.on(): This line turns on the buzzer. It will start making a sound.
- GPIO.output(LED_RED, GPIO.HIGH): This sets the GPIO pin connected to the red LED (which is defined as LED_RED) to HIGH (3.3V), turning the red LED on.
- time.sleep(1): This pauses the execution of the script for 1 second.
- GPIO.output(LED_RED, GPIO.LOW): This turns off the red LED by setting the GPIO pin to LOW (0V).
- time.sleep(1): Another pause in the execution for 1 second.
- else:: This is part of the if statement. If the condition ldr.value <= 700 is not met (meaning the light level is above the threshold), the following lines under else will execute.
- GPIO.output(LED_RED, GPIO.LOW): This ensures the red LED is off when the light level is above the threshold.
- buzzer.off(): This turns off the buzzer.
- GPIO.output(LED_GREEN, GPIO.HIGH): This turns on the green LED by setting the GPIO pin to HIGH.
Building the Protecting Case
It will be easy to get wires off without a protective case! You can take a box left when shopping from Amazon or a shoebox. Remember to stick everything using the tape!
Be Creative
You can add more laser pointers and LEDs based on your needs. Then you can change the code and try use your own security system!
Demo Video
Downloads
References
[1] “Light dependent resistor (LDR) photocell,” PCBoard.ca - LEDs, Electronics, Maker Supplies and More..., https://www.pcboard.ca/ldr-light-dependent-resistor/
[2] A. Negi et al., “Raspberry pi 4 GPIO pinout, Specs, schematic (detailed board layout),” eTechnophiles, https://www.etechnophiles.com/raspberry-pi-4-gpio-pinout-specifications-and-schematic/
[3]“Home Security - Home Safety - Insight Security,” www.insight-security.com. https://www.insight-security.com/home-security-home-safety
[4]J. Bausch, “How to build a simple laser tripwire alarm system for your home,” Electronic Products, Jun. 23, 2016. https://www.electronicproducts.com/how-to-build-a-simple-laser-tripwire-alarm-system-for-your-home/