Alarm System

by DA1 in Circuits > Arduino

93 Views, 0 Favorites, 0 Comments

Alarm System

image_6487327 (16).JPG
image_6487327 (14).JPG

An alarm system is a circuit which warns you when movement near the motion sensor is made. Once movement is detected the buzzer goes off while the RGB turns red and the led starts flashing. After a few seconds the led stops flashing and the buzzer also stops. However, the RGB will continue to remain red to indicate movement has been detected. In order to get the system to turn back to default mode, you press the button which will turn the RGB blue indicating that default mode has been activated. If movement is detected once again then it’ll repeat the process. 

Supplies

Copy of Copy of Copy of Bodacious Kieran-Wolt (9).png

Materials + Cost

  • LED x (1) $1.00-$2.00
  • RGB LED x (1) $1.00-$2.00
  • PIR sensor x (1) $17.29
  • 555 timer x (1) $1.05
  • 1kΩ resistor x (1) $1.00-$2.00 each
  • 10kΩ resistor x (2) $1.00-$2.00 each
  • 330Ω resistor x (4) $1.00-$2.00 each
  • Push button x (1) $1.00-$2.00
  • Slide switch x (1) $1.00-$2.00
  • Capacitor x (1) $3.59
  • Jumper wires $6.00-$15.00 (depends on how much you get)
  • Arduino uno $20.00-$30.00
  • Bread board $10.00-$15.00

**Materials can be bought from amazon or from any electric store.

(Ex. Newark Electronics)

Placement

Copy of Copy of Copy of Bodacious Kieran-Wolt (8).png

For the construction part of your circuit you’ll need to start off by placing all the components onto the breadboard. Place your PIR sensor, slide switch, push button, 555 timer, LED, RGB, capacitor and your buzzer anywhere onto the breadboard. You might want to add your PIR and slide switch near each other since you’ll be wiring them together afterwards. Remember to evenly space your components to ensure that you have enough space to add wiring. (You don't want everything to be cramped into the same place as this can interfere with how your circuit works).

Wiring [Positive + Negative]

Copy of Copy of Copy of Bodacious Kieran-Wolt (7).png

You can then start off by wiring all the negative and positive sides of all of your components. Wire the ground pin of the PIR sensor to ground and the power to the common pin of the slide switch. Then wire the power pin of the 555 timer which is at the top left to power and the bottom left to ground. Also wire the reset pin which is at the bottom right of the 555 timer to power. You can wire the cathode pin of the led to ground directly but in order for the LED to last long and not get damaged, use a 330Ω resistor and connect it the the ground. For your RGB connect the cathode pin of it using a 330Ω resistor and then connect that to ground. Ensure that you connect the negative pin of your buzzer to ground as well. For your push button connect terminal 1b to power and 2b to ground using a 10kΩ resistor. Place one end of a 1kΩ resistor on the output pin of the 555 timer as you’ll need to wire your led to it. Also connect your discharge pin of the 555 timer to ground using a 330Ω resistor. Place another 330Ω resistor by the top of the 555 timer as you’ll need to connect both of its sides to the pins of the 555 timer.  

Wiring [LED + 555 Timer]

Copy of Copy of Copy of Bodacious Kieran-Wolt (1).png

Once you’re done wiring all the components to power and ground you can start wiring all the other components but its best to start wiring your LED flasher with the 555 timer first. You’ll first need to wire your trigger pin of the 555 timer to the threshold. Next wire your capacitor to the 555 timer. Wire terminal 2 of the capacitor to the trigger of the 555 timer. Now connect the other end of the resistor that you connect to the output in to the anode of the led. Finally connect one end of the resistor that you placed near the top of the 555 timer to the discharge and the other to the threshold. Once all of that is done you're done wiring the 555 timer and the LED.

Wiring [Arduino Pins]

Copy of Copy of Copy of Bodacious Kieran-Wolt (4).png

This is the last step of the building part of the circuit. You’ll need to connect each component to a pin on the arduino. You can connect the components to whatever pin you’d like but you’ll need to adjust your code accordingly to the pins you connect it to. First connect the signal pin of the PIR sensor to A1 on the arduino. Next, connect terminal 2a of your button to pin 2. Once you're done connecting your PIR sensor and your push button, connect the anode pin of your flashing LED to pin number 9. Once you're done with that start connecting your RGB pins. Connect the red pin to pin number 13, your blue pin to pin 12 and finally your green one to pin 11. Once you're done that you only need to wire your buzzer. Connect the positive side of your buzzer to pin 8 and connect threshold of your 555 timer to pin 4. This will help determine how long you want the alarm and flashing LED to go off for. Finally once all your components have been connected to a pin, connect the power and ground pin of the aurindo to your circuit and you’re done with the construction part of the circuit!

Variable Declaration

image_6487327 (8).JPG

To write the code you want to start off by declaring all of your variables. Remember you must declare your variables according to what pin you have the components connected to on the Arduino. (There’s comments for guidance as to what each segment is for).

Void Setup ()

image_6487327 (9).JPG

Once you’ve declared your variables you can start defining them in “void setup ()” by writing a pinMode statement which declares all of your variables and states weather they’re inputs or outputs. Eg. “pinMode(variable pin, OUTPUT);” or “pinMode(variable pin, INPUT);” 

Void Loop ()

image_6487327 (10).JPG

The next part of the code will gather reading inputs in “void loop ()”. We’ll first be declaring the variables alarm, detect and buttonpush in order to store information into them. What it does is that it'll gather information from the PIR sensor to detect motion and then will update the variable "detect" in order to keep track of movement and will check the state of the button to detect if its been pressed or not.

Void Loop ()

image_6487327 (11).JPG

You’re then going to write an if statement which will turn the RGB LED red and play the buzzer if the if the push button has not been pressed and if movement is detected. You can change the way your buzzer sounds when playing by changing the numbers in the line “tone(SPEAKER, 700, 300);”

Void Loop ()

image_6487327 (12).JPG

You’re now going to write a for loop for the LED flasher which will cause the LED to flash five times before turning off. The delays will determine the time it’ll flash for and the timer between each flash. The next part of code is for your 555 timer. What this part will do is that the code activates the 555 timer causing the LED to blink for a certain duration. After the blinking is complete, the detection count is reset to 0. 

Void Loop ()

image_6487327 (13).JPG

Finally, you’re going to write an else statement which will turn off the LED flasher, the buzzer and the 555 timer and will turn the RGB blue if no movement is detected. There is also a delay of 10 MS at the end that provides a small pause in the execution of the program. 

Downloads