Project tutorial
Distance Alarm System

Distance Alarm System © GPL3+

A simple device that will trigger an alarm when objects come too close to the Ultrasonic sensor.

  • 3,606 views
  • 3 comments
  • 17 respects

Components and supplies

About this project

Introduction

Mabuhay!

Darwin here. In this project, I make a device that can calculate distance and set off an alarm when objects are too close to the sensor. The buzzer will buzz and a LED light will trigger to light.

Hardware Required

Connections: HC-SR04 Sensor

  • Attach the HC-SR04 sensor to the Breadboard
  • The Sensor VCC connect to the Arduino Board +5V
  • The Sensor GND connect to the Arduino Board GND
  • The Sensor Trig connect to the Arduino Board Digital I/O 9
  • The Sensor Echo connect to the Arduino Board Digital I/O 10

Buzzer and LED

  • The Buzzer attach to the Breadboard
  • The Buzzer long leg (+) connect to the Arduino Board Digital 11
  • The Buzzer short leg (-) connect to the Arduino Board GND
  • The LED attach to the Breadboard
  • The Resistor connect to the LED long leg (+)
  • The Resistor other leg (from LED's long leg) connect to the Arduino Board Digital 13
  • The LED short leg (-) connect to the Arduino Board GND

To view how this project work see video below

Code

Distance Alarm SystemArduino
Darwin here, in this project I make a Distance Alarm Sensor that will alarm when an object is near on the HC-SR04 sensor and a buzzer will trigger and light an Led.
const int trigPin = 9;
const int echoPin = 10;
const int buzzer = 11;
const int ledPin = 13;
long duration;
int distance;
int safetyDistance;
void setup() {
pinMode(trigPin, OUTPUT); 
pinMode(echoPin, INPUT); 
pinMode(buzzer, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600); 
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
safetyDistance = distance;
if (safetyDistance <= 5){
digitalWrite(buzzer, HIGH);
digitalWrite(ledPin, HIGH);
}
else{
digitalWrite(buzzer, LOW);
digitalWrite(ledPin, LOW);
}
Serial.print("Distance: ");
Serial.println(distance);
}

Schematics

Schematic 01
Hc sr04 bb fa682zpqmk

Comments

Similar projects you might like

Ultrasonic Security System

Project tutorial by Ivan

  • 17,283 views
  • 18 comments
  • 50 respects

Buzzer Alarm System With Help Of Arduino

by Team ONYX

  • 37,920 views
  • 5 comments
  • 21 respects

Plant watering alarm system with arduino

Project tutorial by Giannis Arvanitakis

  • 3,709 views
  • 1 comment
  • 5 respects

Security System And Access Control With Arduino And RFID

Project tutorial by Sarath P

  • 7,254 views
  • 0 comments
  • 18 respects

Entry Level Door Monitoring Alarm System

Project tutorial by Team Robodia Technology Solutions

  • 5,753 views
  • 1 comment
  • 16 respects

DIY Arduino Fire Alarm System At Home

Project tutorial by Team MrModder

  • 15,816 views
  • 1 comment
  • 15 respects
Add projectSign up / Login