Introduction: UltraSonic Proximity Alarm

Picture of UltraSonic Proximity Alarm

This is a quick and easy guide on how to make a proximity alarm using a HC-SR04 Ultrasonic sensor, Arduino UNO, Arduino breadboard, and a 6V DC buzzer. This sensor will beep as an object move closer.

Step 1: Materials Needed

Picture of Materials Needed

(1x) Arduino UNO
(1x) Breadboard (please note: any breadboard will work. the above photo is of an Arduino Breadboard)
(1x) 6V DC Buzzer
(1x) HC-SR04 Ultrasonic Sensor
(6x) Jumper Wires

Step 2: The Setup

Picture of The Setup

The photo above is the setup of the board. Connect the jumper wires as follows to connect the breadboard and Arduino UNO together:
Connect a jumper wire from the 5 volt pin on the Arduino UNO to the bottom channel of the breadboard
Connect another jumper wire from a ground pin on the Arduino UNO to the upper channel of the breadboard

Ultrasonic Sensor (4 pins on sensor)
Its best to connect the sensor to the corner of the breadboard without any obstruction

Using jumper wires:
Gnd -> GND----------------------connect the GND on the sensor with top channel of the breadboard (GND)
Echo -> pin 6 --------------------connect the ECHO on the sensor to pin 6 on the Arduino Uno
Trig -> pin 7 ----------------------connect the Trig on the sensor to pin 7 on the Arduino Uno
Vcc -> 5V-------------------------connect the Vcc on the sensor to the bottom channel of the breadboard (5v)

Buzzer
red wire -> pin 3----------------connect the red wire on the buzzer to pin 3 on the Arduino UNO
black wire -> GND-------------connect the black wire to the top channel of the breadboard (GND)

If you want the buzzer to have a lower volume, connect a 330 ohm resistor to the GND wire.

Step 3: The Code

Picture of The Code

Original code by flynn_munroe

Refined and edited.

Once you have completed the physical circuit, now you plug in the code for the Arduino UNO. Copy and paste the code below.

#define trigPin 7
#define echoPin 6
#define buzzer 3
int sound = 250;

void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buzzer, OUTPUT);
}

void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;

if (distance <= 30) {
digitalWrite;
sound = 600;
}
else {
digitalWrite;
}
if (distance < 25) {
digitalWrite;
sound = 400;
}
else {
digitalWrite;
}
if (distance < 20) {
digitalWrite;
sound = 350;
}
else {
digitalWrite;
}
if (distance < 15) {
digitalWrite; sound = 250;
}
else {
digitalWrite;
}
if (distance < 10) {
digitalWrite;
sound = 50;
}
else {
digitalWrite;
}
if (distance < 5) {
digitalWrite;
sound = 50;
}
else {
digitalWrite;
}
if (distance > 30 || distance <= 0){
Serial.println("Out of range");
noTone(buzzer);
}
else {
Serial.print(distance);
Serial.println(" cm");
tone(buzzer, sound);
}
delay(500);
}

Once you have the code, plug in the Arduino UNO and upload it. The sensor is now ready for use. If you want to change the volume of the buzzer the closer it gets, change the number for the sound. ie (sound=250)

Step 4: Refine and Develop

Picture of Refine and Develop

Once you have the sensor working, you can now refine the model and make it smaller. We chose to make the sensor into a wearable object by replacing the Arduino UNO with the Arduino Lilypad. We 3D printed an appropriate housing that can be clipped onto the back of your backpack.

Step 5: Accessible Alternative Design

Being that public safety is universally sought out, making this sensor accessible for to all is an important factor. Since the electronic parts are relatively inexpensive and easy to find, the housing for the sensor can be made out of a tupperware container, a tin can, or even cardboard box making the design more economic while retaining the quality of the sensor.

Comments

notinsanity (author)2017-10-18

Awesome project

SMART KARL (author)notinsanity2017-10-23

Thank you!

Swansong (author)2017-10-18

That's a neat idea to help you keep some personal space :)

SMART KARL (author)Swansong2017-10-18

Thank you!

About This Instructable

752views

19favorites

More by SMART KARL:UltraSonic Proximity Alarm
Add instructable to: