Introduction: Arduino Security Alarm

About: Building and coding is what I do.

Introduction

Hello all, and welcome to my first project. I will be showing you in full detail how to make your very own intruder alarm. Read all the steps very carefully. Miss one little thing, and you can fry a circuit, or the code won't be correct. Check below that you have all of the necessary supplies.

Supplies

  • Arduino Uno
  • 4 normal LEDs, any color
  • 1 RGB LED,
  • 1 photo resistor
  • 1 10k ohm resistor
  • 6 220k ohm resistors
  • 1 16/2 LCM1602C(preferred) lcd screen
  • 1 potentiometer
  • About 20+ jumper cables
  • 1 9V battery with ground and power jumper wires attatched

Now that you got the supplies, let's start building.

Step 1: LEDs

Now, with this tutorial I will assume you have prior knowledge on using an Arduino, basic coding, and wiring. Hook up the positive end of each LED to a GPIO pin on the Arduino, and the negative end to ground. I hooked them up to pins 2, 9, 3, 4, 8, and 5, and it is crucial you do the same. You will see why when we hook up the lcd screen.

Please note, there aren't enough GPIO pins on the Arduino, so do not connect one of the RGB pins to the Arduino. Or, if you don't have a RGB LED, just substitute it with two more LEDs. Keep in mind that means you'll need an extra resistor. Don't worry, it doesn't matter that much in the end.

Step 2: Photo Resistor

This step is simple. Connect the photo resistor to power and ground. After that, hook it up to the A0 (Analog pin 0) pin on the Arduino board.

Photo resistors can detect light. So, in this project, the photo resistor will feed the Arduino the light value every second and if it changes, or goes below a certain level (caused by the door opening), it will set off the alarm.

For more information on photo resistors, click here.

Step 3: LCD Screen

This step is a tiny bit complicated. However, if you do exactly as instructed, it won't be to you. This LCD screen has 16 connections numbered 1-16, going left to right in this photo. Connect as instructed:

  1. Ground
  2. Power Source
  3. Potentiometer(see next step)
  4. Arduino pin 12
  5. Ground
  6. Arduino pin 11
  7. Nothing
  8. Nothing
  9. Nothing
  10. Nothin
  11. Arduino pin 10
  12. Arduino pin 13
  13. Arduino pin 6
  14. Arduino pin 7
  15. Power Source (put 220 ohm resistor)
  16. Ground

Putting the correct pins down is crucial for coding later on, something I learned the hard way while making this project.

For more info on LCD screens, click here.

Step 4: Potentiometer

Attach the potentiometer to the breadboard. And connect it to power and ground. In this photo, the red wire is power, and the black wire is to ground. Then connect a wire from the other side(green in the photograph) and attach it to the third pin on the LCD screen.

In this project, the potentiometer basically controls the brightness of the screen. When booting up, turn the knob to set it to the appropriate setting.

Step 5: Battery

This isn't really a step, but assuming your computer isn't on the floor next to your door, you are going to need a different power source. This power source will be a 9V battery. connect the positive end to "Vin" on the Arduino board and the negative side to ground. It should look something like in the picture.

Now, you should have your circuit complete, and look something like the photo in the introduction. Now... on to the code.

Step 6: The Code

Now, just download the code below.

The only thing you will have to do to the code is change the line circled in red. The number 140 is basically the light value inbetween the value of when the door is open, and when the door is closed. The value drops below 140 when the door opens, setting off the alarm. But you are going to have to change that number because the lighting in your house will be different from mine. You may even have to switch the < symbol to > if the light value of the door open is higher than when closed.

if(sensorValue < 140) {

This is why I mentioned earlier that you should have experience with Arduino before doing this project, because this requires troubleshooting on a slightly more complicated level than yours or someone else's comfort zone.

Also, if you didn't use the same GPIO pins as me, you have to read this. Right after importing the liquid crystal library, you see this line of code:

LiquidCrystal lcd(12, 11, 10, 13, 6, 7);

This is stating that the pins connected to the lcd are 12, 11, 10, 13, 6, and 7 on the Arduino board. Refer back to the list on step 3. As you can see, the pins 12, 11, 10, 13, 6, and 7 are in order from top to bottom on the list (they are bolded for you). You have to identify what pins went where in your project and follow the same order or it won't work. Let me know if you have any questions.

Let me know how the project goes. Comment your results, questions, problems, or future ideas. I hope you enjoy, and I will be back for another whole new project in the near future.

Coded Creations

Participated in the
Coded Creations