Burglar Alarm

by 937605 in Circuits > Arduino

3395 Views, 22 Favorites, 0 Comments

Burglar Alarm

Instructables title image.jpg

The TEJ2O0 engineering course is an outstanding course that teaches one many things about the computer and basic electronic circuits. One of the main highlights of this course is the Arduino Uno, specifically learning to code using it. This project demonstrates this skill and is easy to make.

The Burglar Alarm is a device that alerts the user if any form of motion is detected. Further, it sounds a 'siren' if the motion or in this case the 'burglar' is within a certain distance. Else, it will notify the user that all is clear and there is no motion detected via the LCD monitor.

Gather Supplies

Supplies.jpg
Below is a list of supplies along with links to purchasing the product:

* Links to products have been attached (as of 19th April 2021). Prices and availability might change.

Understanding the Circuit

This isn't necessarily a step, so you can skip this step if you wish. This is just some basic theoretical understanding behind each component.

A PWM pin on the Arduino is a pin with the ~ in front of it. These pins, also called pulse width moderation pins, recreate a analog or varying signal. They help with devices like an RGB LED or the Trig pin in an Ultrasonic Distance Sensor. For example: An RGB LED changes colour based on the code inputted into the Arduino. The PWM pin makes sure to vary this signal so it can change colour.

The motion sensor detects motion through infrared sensors, causing it to turn on. By turning on, the motion is considered detected.

The ultrasonic distance sensor helps detect specific distances. The echo and trig pins are connected to PWM pins on the Arduino. The trig pin sends out 'pings' or sound waves. When the sounds waves hit an object, they return and are inputted by the echo pin. The code on the Arduino takes this reading and calculates it, turning it into a measurement (in this case in inches).

The LEDs have an anode (power) and cathode (ground) side. Anode is the longer 'leg' of the LED while the cathode is the shorter one. This is done on purpose, don't cut them! The anode is, in this case, connected to the Arduino. The cathode side is connected to a 330 ohm resistor. A resistor 'resists' the flow of electricity through the LED. If there were no resistor, the LED would burn out.

The Common Anode RGB LED works the same way. An RGB led is powered to show all three colours: red, green, and blue. The longest 'leg' (or the second from the left) is the one that needs to be connected through a resistor to power. This provides the LED with power. The other 3 legs, red, green, blue (in that order) are connected to the PWM pins.

The LCD monitor is soldered to an I2C chip. This is done so there is a smaller load on the Arduino and more components can depend on it. The chip then has 4 wires coming out of it. The Vcc connects to the 5v pin, the Gnd connects to the ground pin, the SDA wire connects to the A4 analog pin and the SCL wire connects to the A5 analog pin

To learn more read this link: Link about basic components and functions

Build the Circuit

Breadboard Schematic.png
Schematic.png
Burglar Alarm building process
Circuit on breadboard - Instructables.jpeg

To build the circuit, you can follow the breadboard diagram, circuit schematic or video above.

The wires on the breadboard diagram are colour-coded to help you navigate through the picture. This level of colour-coding isn't required, although it is recommended that some sort of colour coding is to be done regardless.

Things to note:

Don't connect the power wire to the ground as this will create a short circuit and diffuse a lot of the components on the breadboard. Additionally, the buzzer will sound very loudly. Before connecting the Arduino to a power source, be sure to cross check wire connections.

Colour code your wires as best as possible. It is better to make direct connects to power a red wire and direct connections to ground, black. This will help you navigate through the circuit easily.

LEDs are rather 'sensitive'. This is where cross-checking further applies. The power or the Arduino pin connection goes to the Anode (long leg - don't cut this) of the LED. From the cathode (short leg) goes the connection to a resistor, which is important, and then a connection to ground. The same logic applies to an Common Anode RGB LED, except the longest leg is connected to power through a resistor, while the other short ones are connected to the PWM (~) Arduino pins.

Don't fix something on the breadboard while the Arduino is connected to power. Again, this could cause a short-circuit or cause some components to stop working if connected the wrong way.

Just remember to double check before providing the Arduino with power. A lot of things can go wrong if cross checking hasn't been done.

Uploading the Code

Download the file below. This will enable access to the code, although you would need the Arduino IDE software to be able to access this. As soon as you download the code below, your computer will add it into a file and then access it. Here is a link that explains the basics of Arduino.

Within the code, you can change the frequencies of the void 'siren' function, to create a different warning tone. You can change the colour of the RGB LED using the colour code link below. Further, you can change the distance at which the device detects by typing a number bigger than 40 (1 meter) into the 'if' distance statements.

This link explains how to download and include libraries into the Arduino software.

Here are the links to the usage of the Arduino software, the different code functions, the link to uploading libraries and the RGB LED colour codes.

The code provided includes comments about all the different parts of the code, so you don't need to worry about understanding it too much. You can use the links above to help you if you do need it, but I have troubleshooted this code and made sure there were no problems.

Some problems that did occur were:

  • Conflict: A timer conflict between the LCD library and the pitches.h library
    • Solution: I replaced it with the timer free tone library. The only downside is that instead of note names, you would need to write the frequencies.
  • Conflict: LCD monitor was outputting the text weirdly
    • Solution: I realized that I wrote lcd.print.ln instead of lcd.print, causing it to add weird squares to the output
  • Not necessarily a conflict, but I didn't like the colour the RGB LED outputted, so I changed those using this link.

Downloads

Final Product

Burglar Alarm Demo

Your project should work as above. Turn your volume up to hear the buzzer.

And that is all. In 4 simple steps, you can create this simple Burglar Alarm. You can play around with the code, and if you mess up you can always redownload it. That's all for now.

Happy building! (ノ◕ヮ◕)ノ*:・゚✧