Skip to main content

Ultrasonic Security System

 

Ultrasonic Security System


It is a simple tutorial on how to create little a security device using an Arduino.


Components and supplies

  • Arduino UNO
  • Jumper wires 
  • Ultrasonic Sensor - HC-SR04
  • Breadboard 
  • Buzzer
  • Resistor 221ohm
  • LED 5mm

Project description


Step 1: Assemble Materials




Step 2: Setup



Connect a red wire from the 5V pin on the Arduino to the positive channel of the breadboard. Connect a black wire from the GND pin on the Arduino to the negative channel of the breadboard:

  1. Buzzer = pin 7
  2. Echo = pin 3
  3. Trig = pin 2
  4. RedLED = pin 4
  5. YellowLED = pin 5
  6. GreenLED = pin 6

On Ultrasonic Sensor:

LEDs:

The green wires connected to the LEDs should be connected in line to the positive side of the LED, while the negative side of the LED should be connected to the negative channel of the breadboard using a 220 ohm resistor. 

Step 3: Assembly - Breadboard



Firstly, let's connect the 5V and GND pin on the Arduino to the breadboard. As I mentioned before, be sure that the wire attached to the 5V pin is connected to the positive channel of the breadboard, and the wire attached to the GND pin is connected to the negative channel of the breadboard.

Step 4: Assembly - Ultrasonic Sensor



Time to connect the HC-SRO4 ultrasonic sensor! A great tip is to place the ultrasonic sensor as far right to the breadboard as possible and make sure that it is facing out. Referring back to the setup picture, you should connect the GND pin on the ultrasonic sensor to the negative channel on the breadboard. Next connect the Trig pin on the sensor to pin 2 on the Arduino and connect the Echo pin on the sensor to pin 3 on the Arduino. Lastly, connect the VCC pin on the ultrasonic sensor to the positive channel on the breadboard. Refer to the picture above if anything gets confusing.


Step 5: Assembly - LEDs


The next step is to connect the LED's to the breadboard and Arduino. If you need to, I highly recommend that you refer back to the setup picture (Step 2), attaching the LEDs is pretty easy, there's a lot of repetition. Let's first attach the Green LED. So the way to do this, is to connect the anode (the longer leg) to pin 6 on the Arduino with a green wire, and to connect the cathode (the shorter leg) to the negative channel on the breadboard, using a 220 ohm resistor. Then repeat that step for the Yellow and then the Red LED, make sure to connect the anode (the longer leg) of the yellow LED to pin 5 on the Arduino and then connect the anode of the red LED to pin 6. Once you have done that, your setup should look similar to the picture above.
Resistors are not absolutely necessary, however they are highly recommended to be used.

Step 6: Assembly - Buzzer



The last part of the setup for this, is connecting the buzzer to the breadboard and the Arduino. This is one of the easiest parts of the whole setup. All that is required to do is to connect the longer leg of the buzzer to pin 7 of the Arduino using a green wire and then connect the shorter leg of the buzzer to the negative channel of the breadboard using a 220 ohm resistor.

It is HIGHLY recommended to use a resistor in connecting the shorter leg of the buzzer to the negative channel of the breadboard. This greatly reduces the volume of the buzzer and prevent it from dying to quickly.


 Code -

#define trigPin 2
#define echoPin 3
#define LEDlampRed 4
#define  LEDlampYellow 5
#define LEDlampGreen 6 
#define soundbuzzer 7
int sound  = 500;
void setup() {
  Serial.begin (9600);
  pinMode(trigPin,  OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(LEDlampRed, OUTPUT);
  pinMode(LEDlampYellow,  OUTPUT);
  pinMode(LEDlampGreen, OUTPUT);
  pinMode(soundbuzzer, OUTPUT);
}
void  loop() {
  long durationindigit, distanceincm;
  digitalWrite(trigPin, LOW);  
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  durationindigit = pulseIn(echoPin, HIGH);
  distanceincm = (durationindigit/5) / 29.1;
 
  if (distanceincm < 50) {
      digitalWrite(LEDlampGreen, HIGH);
}
  else {
      digitalWrite(LEDlampGreen,  LOW);
  }
  
  if (distance < 20) {
    digitalWrite(LEDlampYellow,  HIGH);
}
  else {
    digitalWrite(LEDlampYellow,LOW);
  }
  if (distance  < 5) {
    digitalWrite(LEDlampRed, HIGH);
    sound = 1000;
}
  else  {
    digitalWrite(LEDlampRed,LOW);
  }
 
  if (distanceincm > 5 ||  distanceinsm <= 0){
    Serial.println("Outside the permissible range of distances");
    noTone(soundbuzzer);
  }
  else {
    Serial.print(distance);
    Serial.println("  cm");
    tone(buzzer, sound);
  }
  
  delay(300);
}


Comments

Popular posts from this blog

Weather Station Using Arduino & DHT11

Weather Station Using Arduino & DHT11      Introduction: Weather monitoring is an important task in many industries and applications. In this project, we are going to build a weather monitoring station using Arduino Nano, DHT11 sensor, 16x2 LCD display, and I2C module. The DHT11 sensor will be used to measure temperature and humidity, and the results will be displayed on the 16x2 LCD display with the help of the I2C module. Hardware Required:

Understanding the Basics of Resistors: A Beginner's Guide

  Understanding the Basics of Resistors: A Beginner's Guide Introduction: Resistors are one of the most basic and fundamental components used in electronic circuits. They play a vital role in controlling the flow of current in a circuit and have a wide range of applications in everything from simple LED circuits to complex electronic systems. In this blog post, we will dive into the world of resistors, exploring what they are, how they work, and the different types of resistors that are available. What is a Resistor? A resistor is an electrical component that is used to regulate the flow of electrical current in a circuit. It is designed to have a specific resistance value, which is measured in ohms (Ω). The resistance value of a resistor determines how much current can flow through it, with higher resistance values limiting the current flow, and lower resistance values allowing more current to flow. Resistors are passive components, which means that they do not generate or amplify

Revolutionizing Home Automation: Empowering Smart Living through Seamless Control and Advanced Monitoring

Revolutionizing Home Automation: Empowering Smart Living through Seamless Control and Advanced Monitoring Introduction : Welcome to the forefront of modern living, where our innovative home automation project is reshaping the way we interact with our homes. Our mission is to bring convenience, efficiency, and security to homeowners through a comprehensive system that leverages the power of cutting-edge technology. By integrating internet networking, sensor data, and cloud-based storage, our project ensures real-time updates and effortless user control. With a focus on simplicity and accessibility, our solution is designed for all, regardless of technical expertise. Join us on this journey as we explore the extensive capabilities of our home automation project. Project Overview: At the heart of our home automation project lies the vision of creating a smart ecosystem that seamlessly connects various aspects of the home. By interlinking appliances, sensors, and user devices through inter