Arduino Alarm System

by 649723 in Circuits > Arduino

529 Views, 1 Favorites, 0 Comments

Arduino Alarm System

IMG_8309.JPG
IMG_8315.JPG

This Instructable will teach you how to make an Arduino Alarm System. This circuit will be integrated into a plastic box but can be integrated into other objects as well. This alarm system will have two different modes. A night mode and an away mode. The night mode will only make the alarm go off when the box is opened, and the away mode will do the same, but also make the alarm go off if there is motion detected in the box.

How it Works/What it Does

The Arduino Alarm system works mainly through the sensors and IR Receiver with a remote. These components are essential for making the system work as they are the input devices. The IR Receiver is important as it takes input from the remote which controls the system. The IR Receiver works by receiving an infrared signal from a remote control. Each button on a remote will be assigned a different value by the IR Receiver and this allows the Arduino to define those buttons as variables. The remote can have 5 different effects on the system. The away function, which readies the sensors. If the PIR sensor senses any motion, it will be read by the Arduino and then the buzzer will go off. The distance sensor measures the distance between it and the lid of the box. It does this by sending out a pulse and listening for the pulse back. The distance sensor tells us how many inches an object is from the sensor by converting the speed of sound by inches per microsecond. This conversion allows us to find how far an object is away in inches and even other units of measurement. This lets us know how far an object is away from the sensor. If the distance is increased by opening the lid, the buzzer will go off. The night mode will only ready the distance sensor so that motion can still go on in the box but if the lid is opened the buzzer will go off. There is also a disarm mode that disarms the system and turns off all the sensors. The off mode just turns off power to the entire system. The error mode function makes the system show an error on the 7 segment display if any button that has no set function is pressed.

The project can be added to with more functions assigned to each button.

Supplies

1 Arduino Microcontroller

1 Breadboard

1 PIR Sensor

1 Distance Sensor

1 RGB LED

3 330 Ohm Resistors

1 IR Receiver

1 IR Remote (Can be any remote such as a TV remote)

1 Buzzer

1 7-Segment Display

1 Box (Can be any box or cube-like object that can fit the breadboard and components inside)

1 Portable Charger (Optional, a laptop could be used in its place)

Basic Components

IMG_8314.JPG

The components used in this alarm system are fairly basic and easy to wire. The first few components to wire are the breadboard are the 7 Segment Display, RGB LED and Buzzer. The 7 Segment display will take the most digital I/O pins from 12- 6. It will require 7 connections but also require 2 connections to power. The RGB LED will also connect to digital pins 5-3. If you have a common anode LED, it will connect to power and a common cathode will connect to the ground. The first connection will be the red, the second will be power/ground, the third will be green and the fourth will be blue. The buzzer also has a simple connection with a digital I/O and ground, with the digital pin going to the side with the + sign.

IR Receiver

2B7EB62C-EF8C-4607-8F75-A2A2E77B3BB2.jpeg

The IR Receiver is one of the main parts of the project. The IR Reciever will take in signals from remotes and we can use this in our code. It is wired with a connection to a digital I/O pin, power and ground. Once you connect the IR Receiver you can use this code to help decide which buttons on a remote you want to use. Once you upload this code to your Arduino, open up the serial monitor and press a button on the remote. Each button will have a different number and value assigned to it. Looking at the serial monitor, you can decide which button you want to use and keep the assigned value of the button aside for the alarm system code.

Downloads

Adding Sensors

IMG_8312.JPG

Now we are going to add the final 2 components to the project. The PIR sensor and distance sensor. These sensors are responsible for making the buzzer as they detect if the box door opens or if there is any movement within the box. The PIR sensor is connected through power, ground, and an I/O pin. You can use one of the analog pins as the connection instead of a digital pin if the previous components took up all digital I/O pins from 2-13. The distance sensor will need a connection to power, ground and two I/O pins (digital or analog). Once the sensors are added, we move on to the code.

Code (Defining Variables)

Code.png

The first thing we have to do in the code is declare all the variables and pinModes. The echo pin and pir sensor pin will be the only inputs, with all other components acting as outputs. We also have to attach the library as we are using an IR Receiver.

Void Functions

Code1.png
Code2.png
Codex.png
Code4.png
Code5.png

The next part of the code is defining different functions. The setColour code is for the RGB LED and is an easy way to code which colour the RGB LED will output by having different values of red, blue and green. The countdown function is used for the alarm system countdown after arming it. It counts down from 5 to 0 while also making the led flash yellow. The away function is how the circuit should react after a button is pressed and gets the pir and distance sensor ready. Void night acts the same as void away, but for the night mode, which only uses the distance sensor. Void sensor is what the distance sensor should do when the system has been armed. Void disarmed is what the system should do once it is disarmed. Disarming the system will turn off the buzzer and the other two sensors. The error function is used if the wrong button is used to try and start the alarm system. The final function is off, which powers down the entire system.

If Statements (Button Presses)

Code6.png
Codex1.png
codex2.png

The first if statement in the void loop is what gets the IR Receiver to receive input from a remote. The if statements that come after it say that if one of the buttons is pressed, the corresponding functions will happen. For example when the night button is pressed, the functions sensor, countdown and night will happen. After understanding what the functions do, the void loop code is a lot easier to understand.

Full Code

Here is the file code file (Note: Depending on how you wired the circuit and what you want the circuit to do when pressing a button the code will need to be modified).

Downloads

Working Project

Arduino Alarm System