Distance Sensor Alarm W/ Arduino

by 903925 in Circuits > Arduino

245 Views, 1 Favorites, 0 Comments

Distance Sensor Alarm W/ Arduino

Screen Shot 2020-06-19 at 1.52.21 PM.png

Have you ever wanted a distance/motion sensor alarm that could be comprised by yourself at home and activated with the flip of a switch? The alarm system I created does just that, it manipulates the ultrasonic distance sensor to monitor whether an object appears within 15 inches and once the alarm is armed (as in the switch is flipped on), the alarm lights will begin flashing while the buzzer creates a ruckus promptly alarming those in the surrounding area. The alarm is set with a timer which utilizes a 7 segment LED, although the alarm stays on infinitely unless shut off, after 10 seconds from the trigger, the police will be "notified" and dispatched to your location. So, without further ado let's look at the materials needed.

Supplies

Seven segment LED

Breadboard

Arduino

Buzzer

Johson Decade Counter x 2

555 Timer

Ultrasonic Distance Sensor

LED x 9

470 Ohm Resistor

330 Ohm Resistor x 2

1 Mega Ohm Resistor

Assemble the Flashing LED Lights

Screen Shot 2020-06-19 at 3.36.19 PM.png
Screen Shot 2020-06-19 at 3.47.07 PM.png

Remember to colour code your wires! Primarily, red wires indicate a connection to power whereas, black wires indicate a connection to ground. Wires of varying colours that do not represent black or red are simply for aesthetics which is completely up to your discretion. You will need to configure your 555 timer to one out of the two Johnson decade counters, once you wire one counter fully, proceed to the next one. This time connect the inverted output 10 pin from your already configured counter and connect it to the timer of your second decade counter. Make sure to ground all pins that are connected to black (or if you are using tinkercad utilize the inbuilt labelling system to distinguish various pins). Make sure to connect the breadboard to a digital pin instead of directly to power, this will be useful as we can manipulate when the LED system is powered via code.

Ultrasonic Distance Sensor

Screen Shot 2020-06-19 at 3.55.16 PM.png

The ultrasonic distance sensor will be utilized to see if an object has entered within a 15 inch range of the sensor, of course the real distance is up to you and in reality would be much farther. But for the sake of simulating the project virtually, we'll restrict it to 15 inches in diameter. Make sure to connect the Trig and Echo pins to digital pins of your choice, and the power and ground should also be connected to their designated pins.

Seven Segment LED and Buzzer

Screen Shot 2020-06-19 at 3.57.01 PM.png
Screen Shot 2020-06-19 at 3.57.38 PM.png

Configure the seven segment led to digital pins of your choice. Do not plug in a pin called DP, also depending on your model, you will either have a common anode (CA) or a common cathode (CC). Make sure to connect CC to ground and CA to power with a resistor of 330 ohms somewhere in circuit wire. In addition, the seven segment led should be placed somewhere near the center of the alarm but should not obstruct the vision of any major instruments. As for the buzzer, please set the buzzer to a digital pin for its terminal leg and plug the negative leg to ground along with a resistor of one kilo-ohm.

The Switch

Screen Shot 2020-06-19 at 4.04.19 PM.png

The switch should simply be connected to power and ground for either of the two terminals, the common leg should be connected to a digital pin because if switched on, the power will enter the pin which will sense a power and tell the alarm to turn off.

The Code

Screen Shot 2020-06-19 at 4.05.09 PM.png

The arduino file for the code is placed and is downloadable for any user who follows this guide. The code functions as to perceive the distance of the ultrasonic distance sensor, trigger the alarm if the ultrasonic distance sensor senses an object within 15 inches AND the switch is set to off. This will trigger the led tracer/flashing lights in the shape of an arrow, the seven segment led timer of 10 seconds (9 to 0), and the buzzer blasting ever time a second has passed on the seven segment display. The alarm can easily be disarmed by move the object outside the 15 inch border or the switch is turned on.