Basic Ultrasonic Proximity Alarm using one sensor

in #micro-controllers7 years ago (edited)

Intro

The following is a project I did to practice electronics/robotics for security applications. This is a simple proximity sensor alarm circuit, here is a list of what you will need:

1 Arduino microcontroller (for this project I used a uno r3, but other boards can be used).
Buzzer
HC-SR 104 Ultrasonic Sensor
Connector cables
Breadboard
Arduino IDE

Hardware Setup

Hardware Pic One
DSCF2476 - Copy.JPG

Notice the ultrasonic sensor connected directly to the breadboard and the cables going from it. Following the cable colour scheme is optional.

Hardware Pic Two
DSCF2470 - Copy.JPG

A overview of the circuit. Positive pole of buzzer goes to digital pin 9 and the negative to gnd pin.

Hardware Pic Three
DSCF2478 - Copy.JPG

VCC on sensor goes to 5v, trig to A0, echo to A1 and gnd to gnd pin (there are two).

Pic Four
DSCF2472 - Copy.JPG

Another pic to help you out.

Software

Copy this exactly as you see it in these pictures.

Code Pic One
usapic1 - Copy.PNG

Make sure you download the newPing library and install it in your IDE.

Code Pic Two
usaPic2 - Copy.PNG

Code Pic Three
usapic3 - Copy.PNG

Applications


Here I will give some more detail on how to use this alarm effectively.

Drawbacks

There is a gap in detection of about 1.5 seconds due to the code structure, someone running past it may not trigger the alarm.

The alarm is best pointed at solid non porous objects (like a wall), this is because ‘soft’ objects absorb the sound waves.

If you place more than one of these alarms take care, as the sound waves from other sensors may interfere with the alarm. This is known as the ghost effect remember sound waves bounce all over the place.

Due to the code structure when the alarm is activated it will not turn of until you reset it (press the reset button on Arduino). Make sure you reposition it before you reset it.

Advantages

Ultrasonic sound waves are hard to detect so all but the most sophisticated intruders will be caught out.

The alarm can be programmed to use less electricity (more on that later).

The alarm can be reprogrammed to meet your needs.

Hardware used is cheap so you can afford for it to be damaged/destroyed.

Additional Info

Remember that humidity and temperature effects distance that sound waves can travel.

The HC SR104 sensor has a resolution of 0.3cm, which means measurements will be within 0.3cm of accuracy. (Datasheet)

The maximum range of this sensor is 400cm. (Datasheet)

Ultrasonic sensors have a ‘vision cone’ imagine a cone coming out of the sensor from the middle, that is its sensor range. The further away an object the bigger the sensor area.

Remember not to put it too close to something, it needs space for the sound waves to bounce back.

Suggested Applications

To guard a box of supplies, simply leave it behind the box but pointing at it, if the box moves it will activate.

To check if a door is opened.

To check if a window is opened.

To check there is no movement along a wall. (Point it at a blank wall, I recommend 100cm distance).

To check if someone reaches across to grab something (not recommended due to 1.5s gap).

Trouble shooting

NOTE! it beeps on initialization to let you know it has activated! The alarm beep is 5 seconds.

The sensor does its initial scan immediately; don’t be standing in front of it.

The sensor can be set off with peripheral motion, don’t stand or wave objects by the side of it.

It still beeps! The code is designed to that if the initial scan and frequent scans don’t match it activates. Move any obstacles out of the way and point sensor directly at the target.

The line of code with serialBegin, inside the void loop prints the variable that stores the distance value (for continuous scans). As this is the value that is always changing open the Arduino IDE, go to tools – serial monitor. Press reset and watch, use this to practice aligning it. I tested mine to a distance of 31cm.

I can’t get away fast enough before it activates! Ok, in the void loop setup part of the code, at the very top, within the brackets add this code. delay(10000); you now have ten seconds to get away from it. Upload the new code to board, set it up and run.

Bonus

Here is an altered version of the void loop code, it contains a longer delay. Because the sensor is continuously scanning it uses up a lot of electricity, which means a lower battery life. Now this isn’t a problem if you want to know if something is there right away, but what if you just want to know if a box is moved?

Altered Code
usaPic4 - Copy.PNG

If you want to delay the scan time add that extra line of code you see at the bottom, just change it to suit your needs.

Conclusion

I hope you enjoyed this post, in an ideal world we would add housing and solder all the connections to a permanent breadboard. But in many ways not doing to gives use more flexibility, take a look at some of my other microcontroller posts.

I will be doing more with ultrasonic proximity alarms, including adding more of them together in a line, that acts like a radar and mounting one on a servo which can systematically scan in all three directions.

Other posts you may like:
https://steemit.com/micro-controllers/@aspieprepper/micro-controlled-soil-sensors-for-preppers-survivalists
https://steemit.com/electronics/@aspieprepper/best-electronic-components-to-store

Survive and Thrive!

Minds: https://www.minds.com/AspiePrepper
Steemit: https://steemit.com/@aspieprepper
Patreon: https://www.patreon.com/aspieprepper
Youtube: https://www.youtube.com/channel/UC8WohhlmLNq2B5w3dV84Omw
Vidme: https://vid.me/AspiePrepper
Paypal: paypal.me/AspiePrepper

Sort:  

Cool, I like it. I've done a few projects with the Raspberry Pi but never used Arduino.

Arduino is very easy and fun! It does not have its own operating system, but has an easy IDE.

Resteemed by @resteembot! Good Luck!
Curious?
The @resteembot's introduction post
Get more from @resteembot with the #resteembotsentme initiative
Check out the great posts I already resteemed.

This post has received a 0.95 % upvote from @booster thanks to: @aspieprepper.

This post has received a 1.92% upvote from @lovejuice thanks to @aspieprepper. They love you, so does Aggroed. Please be sure to vote for Witnesses at https://steemit.com/~witnesses.

Coin Marketplace

STEEM 0.17
TRX 0.16
JST 0.029
BTC 61129.24
ETH 2376.01
USDT 1.00
SBD 2.54