Distance Alarm System

869

11

1

Introduction: Distance Alarm System

About: Mabuhay! I'm a Filipino maker that build InternetofThings, Artificial Intelligence and Robotic projects. I'm also an open-source developer that contributing in open source community.

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

Step 1: Hardware Components

Arduino UNO https://goo.gl/Z8dDbH

Ultrasonic Sensor 1LED (generic) https://goo.gl/X4NCqa

1 Buzzer https://goo.gl/6kP83v

1 Resistor 220 ohm https://goo.gl/rGQyWL

1 Breadboard (generic) https://goo.gl/aqdBDr

1 Jumper wires (generic) https://goo.gl/6JrpLz

Step 2: Connections: HC-SR04 Sensor

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

Step 3: 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 13The LED short leg (-) connect to the Arduino Board GND

Step 4: CODES

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); }

Share

    Recommendations

    • Tiny Home Contest

      Tiny Home Contest
    • Metalworking Contest

      Metalworking Contest
    • Creative Misuse Contest

      Creative Misuse Contest

    Discussions

    0
    None
    Pib2

    7 months ago

    Neat!, I'd also recommend looking into a PIR motion sensor