RPI Security System
Function of RPI Security Alarm
In this instructable you will learn how to make an fully functioning night time alarm system. If the system detects an intruder it will immediately print out "INTRUDER" on your monitor as well as making a loud noise from the alarm. The leds will also flash in a pattern along with the alarm.
Materials Needed
Procedure
Procedure:
- First place power and ground both your rails
- Place your 330 resistors at the bottom of the bread board starting at the ground rail to any rail on the bread board
- Then place your leds next to your resistor. The short leg goes directly to the right of the resistor if your resistors are placed on the left side of the bread board.
- The long leg of led goes anywhere you want but make sure there all in different rails
- Connect jumper wires to the long led of your led
- Connect jumper wires to any gpio pins
- Place buzzer above the resistors with the short leg going in the ground rail
- Connect a jumper wire to the buzzer and then into a gpio pin
- Now connect the ldr into a power rail and a rail on the bread board
- Connect the short leg of the capacitor to the gound rail and the long leg to the right of the ldr
- Connect a jumper wire to the left of the ldr and then into a gpio ping
- Finally connect three male to female wires onto the motion sensor
- Connect each one of the male to female wires to ground, 5v and gpio respectively making sure each is connected to the right end of the motion sensor
Code Procedure
Code ProcedureL
Make sure you are using python 3 as this code won't work on any other software.
First we must import the right things
from gpiozero import LED, Buzzer, LightSensor, MotionSensor,
from time import sleep
Now we have to define our electrical components. The number at the end should be the number of the gpio port you connected to with your jumper wire. For the code below you must replace the number with your respective gpio port.
Light1 = LED(21)
Light2 = LED(20)
Light3 = LED(12)
Light4 = LED(16)
alarm = Buzzer(19)
ldr = LightSensor (13,5,1,0.1)
pir = MotionSensor(24)
Now it's time to right the juicy part of the code.
while True:
if ldr.light_detected and pir.motion_detected:
print("safe")
light1.off()
light2.off()
light3.off()
light4.off()
else:
ldr.when_dark and pir.motion_detected
print ("INTRUDER INTRUDER INTRUDER INTRUDER")
alarm.on()
light1.on()
sleep(0.1)
light1.off()
light2.on()
sleep(0.1)
light2.off()
light3.on()
sleep(0.1)
light3.off()
light4.on()
sleep(0.1)
light4.off()
This is what the code will look like complete
from gpiozero import LED, Buzzer, LightSensor, MotionSensor,
from time import sleep
light1 = LED(21)
light2 = LED(20)
light3 = LED(12)
light4 = LED(16)
alarm = Buzzer(19)
ldr = LightSensor (13,5,1,0.1)
pir = MotionSensor(24)
while True:
if ldr.light_detected and pir.motion_detected:
print("safe")
light1.off()
light2.off()
light3.off()
light4.off()
else:
ldr.when_dark and pir.motion_detected
print ("INTRUDER INTRUDER INTRUDER INTRUDER")
alarm.on()
light1.on()
sleep(0.1)
light1.off()
light2.on()
sleep(0.1)
light2.off()
light3.on()
sleep(0.1)
light3.off()
light4.on()
sleep(0.1)
light4.off()
Now run the code and the module will display your text
Final Product
Finally, this is what the system should look like completed: