Introduction: SanityForce (Alarm System- Rpi)

Now there are many ways to keep your belongings safe, or just keep your siblings out of your room, like putting a lock on it or just keeping it out other peoples reach. What if I told you that you don't need to do all those basic things but can turn your Raspberry Pi into your personal alarm system! Now you might think this is impossible or just extremely unnecessary, you could just put a lock on your room door to keep your little brother out. But, your brother could find the key to the lock and just go enter your room, but with this alarm system, once you turn it on, it can't be disabled until you go and turn it off via the code. If your brother even comes a meter near your door, the alarm will go off telling everybody in your house that someone tried to invade your privacy. Then once someone knows he tried to invade your privacy, they will come and stop him. To convert your Pi into the amazing alarm system called SanityForce, you are going to need to follow a few simple steps and going to require some add-ons to your Pi. All the steps and materials you will need are listed below. Good Luck, and May the SanityForce be with You!

Step 1: Gather Materials

Now for this project you will require quite a few pieces of add-ons for your Raspberry Pi. Before starting to construct the project, please make sure you have all the materials that are listed below.

  • 1x Raspberry Pi
  • 1x Breadboard
  • 1x Pair of Speakers
  • 1x PiCamera
  • 10x Red LEDs
  • 1x PIR Motion Sensor
  • 3x Female-Male Wires
  • 10x 330 Resistors
  • 10x of Blue Jumper Cables
  • 2x of Black Jumper Cables

Step 2: Connecting the PIR Motion Sensor

Before connecting all the other LEDs and speakers, you want to connect the motion sensor which is the back bone of your project. For connecting the motion sensor, you have to be careful to connect the correct female-male wire to the GPIO pins and GND pins. I will be using the picture above as an example to state which wire would go where. In the example there are 3 wires connected to the motion sensor, a green one, purple one, and blue one, in that order from right to left. The green wire would connect to the GND pin in your bread board, as you could see in the example above. The purple wire would connect to the 5 volts power power pin in the bread board, you could see this in the picture above. The third and last wire, the blue one goes into the GPIO pin on your bread board, in which GPIO pin it goes is your choice.

Step 3: Connecting the LEDs and Resistors

So on to the LEDs and resistors, connecting these is very easy, just make sure that the long leg (anode) of the LED is connected to the jumper cable that is connected to the GPIO pin. The short leg (cathode) of the LED is connected to the 330 resistor which is connected to the GND pin. Before setting up the LEDs on the board, hook up two black jumper cables which would attach from a GND pin to the GND rail on the board. You can spread the LEDs anywhere on the bread board, in any design you like. Make sure to follow the things I said above and your LEDs should light once we put the code in and test them. Also, the GPIO pins you connect the LEDs to does not matter, that could be your choice.

Step 4: Connecting the PiCamera

Now connecting the PiCamera is an easy job, but be careful while connecting it that you do not damage the pins of the camera in the process of planting them in the Pi. There you would open up the black hatch on the bar, and just insert the Pi camera in, remember to push the bar back in once the camera is in place. After doing that you would like to press the Raspberry Pi button on the bottom bar of the Pi interface, the menu bar would come up. Then you would click on "Preferences", and go down to "Raspberry Pi Configuration", once you have clicked on that you would get a menu in front of your screen. There you would click on "Interfaces", there click on the enable button for the camera option. If the camera is already enabled, disable and then enable it. Once you have enabled the camera, restart your Pi and your camera will begin to function once the Pi has rebooted.

Step 5: Setting Up the Speakers

Now for the Pi you could use any speakers you like, but I would recommend you use speakers which have a headphone outlet that you could connect to the Pi's headphone jack. Now setting up the speakers is the most easy part of creating this project, all you must do is plug in the speakers headphone outlet into the Pi's headphone jack. Then you would plug in the speakers USB A cable into the Pi's USB A spot. You just then turn on your speakers and you should be up and running. Just in case your speakers do not work after plugging them in, try taking them and out and putting them back in, or turning your Pi off and on again!

Step 6: Coding the Project

So now after you have assembled everything on your Pi, you are ready to code in Python, so it will actually function. Below is the code that will make it all work, you may just use that, but remember to change all the GPIO pin numbers to the pin number specific to your bread board. You will also have to change the music folder name that I have set in the code, change the name to whatever the name of the folder is on your computer. At the bottom is a picture of how your code should look on Python, just download the file and have a look.

from gpiozero import MotionSensor
from gpiozero import LED

from time import sleep

from picamera import PiCamera

import pygame

camera = PiCamera()

pir = MotionSensor(4)

alarm1 = LED(21)

alarm2 = LED(24)

alarm3 = LED(20)

alarm4 = LED(19)

alarm5 = LED(16)

alarm6 = LED(5)

alarm7 = LED(12)

alarm8 = LED(13)

alarm9 = LED(25)

alarm10 = LED(22)

def rest():

pygame.init()

pygame.mixer.music.load("LA LA LA.mp3")

pygame.mixer.music.play(-1)

while True:

pir.wait_for_motion()

if pir.motion_detected:

camera.start_preview()

sleep(0.1)

camera.capture('/home/pi/Desktop/capture.jpg')

camera.stop_preview()

rest()

print ("INTRUDER ALERT!!!!")

alarm1.on()

alarm2.on()

sleep(0.4)

alarm1.off()

alarm2.off()

alarm3.on()

alarm4.on()

sleep(0.5)

alarm3.off()

alarm4.off()

alarm5.on()

alarm6.on()

sleep(0.4)

alarm5.off()

alarm6.off()

alarm7.on()

alarm8.on()

sleep(0.4)

alarm7.off()

alarm8.off()

alarm9.on()

alarm10.on()

sleep(0.4)

alarm9.off()

alarm10.off()

alarm10.on()

alarm9.on()

sleep(0.4)

alarm10.off()

alarm9.off()

alarm8.on()

alarm7.on()

sleep(0.4)

alarm8.off()

alarm7.off()

alarm6.on()

alarm5.on()

sleep(0.4)

alarm6.off()

alarm5.off()

alarm4.on()

alarm3.on()

sleep(0.4)

alarm4.off()

alarm3.off()

alarm2.on()

alarm1.on()

sleep(0.4)

alarm2.off()

alarm1.off()

else:

alarm1.off()

alarm2.off()

alarm3.off()

alarm4.off()

alarm5.off()

alarm6.off()

alarm7.off()

alarm8.off()

alarm9.off()

alarm10.off()

Step 7: Final Check Up

Now that you have put your code into python, it is time to put everything together and see if your project actually works! Below is a video of how your project should function, ignore some of the people talking in the back, I was not in a quiet place! Hope your efforts in making SanityForce: The Alarm System were a success, and now you have something cool that will help you keep your siblings out of your room.

Thank you for following this instructable, and I hope your learned a thing or two! Don't forget to leave your thoughts down in the comments below! Have fun with your SanityForce!