How to make a Security System with Ultrasonic Sensor and Arduino

preview_player
Показать описание
Build a distance sensitive security system with ultrasonic sensor and Arduino board.

This project is an ultrasonic sensor based alarm. It is distance sensitive so the speed of the buzzer depends upon how close or far the object is. If the object is near then the buzzer beeps faster and if it far then the buzzer beeps slowly.

Components Used:

IMPORTANT LINKS:

🕹My Favourite Equipment :

Timestamps:
0:00 Project Introduction
0:44 Circuit connections
1:58 Uploading the sketch
2:34 Final Output

Social Media

Full Tutorial-

Check out my other projects:
Рекомендации по теме
Комментарии
Автор

project code


//Security Alarm with Ultrasonic Sensor//

#define trigPin 6
#define echoPin 5
#define buzzer 2
float new_delay;


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;
new_delay= (distance *3) +30;
Serial.print(distance);
Serial.println(" cm");
if (distance < 50)
{
digitalWrite(buzzer, HIGH);
delay(new_delay);
digitalWrite(buzzer, LOW);

}
else
{
digitalWrite(buzzer, LOW);

}

delay(200);
}

IBRAHIMABEDAL_NABI
Автор

//Tech Trends Razis
//Object Detection Alarm

// Define pins numbers
const int trigPin = 13; //Connect Trig pin in Ultrasonic Sensor to Arduino Pin 13
const int echoPin = 12; //Connect Echo pin in Ultrasonic Sensor to Arduino Pin 13
const int buzzer = 11; //Connect Positive pin of Buzzer to Arduino Pin 11
const int ledPin = 10; //Connect Positive pin of LED to Arduino Pin 10

// Define variables
long duration;
int distance;
int safetyDistance;


void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(buzzer, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600); // Starts the serial communication
}


void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

// Sets the trigPin on HIGH state for 15 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(15);
digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);

// Calculate the distance
distance= duration*0.034/2;

safetyDistance = distance;
if (safetyDistance <= 8){
digitalWrite(buzzer, HIGH);
digitalWrite(ledPin, HIGH);
}
else{
digitalWrite(buzzer, LOW);
digitalWrite(ledPin, LOW);
}

// Print the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
}

emmaliaRazis
Автор

I want the same with high sensitivity, I mean It should work for any movement take place with a distance as much as 30-40 feet from the sensor. Thanks for your projects, you deserve more viewers.

banttubanttu
Автор

HII TYSMM I DIDNT PAY ATTNETION IN CLASS HAHA AND I DID THIS LAST MINUTE AND GOT GOT MARKS THANKS AGAIN <3

_sourx
Автор

Works fine for me Thank you for uploading!!!

johnjeffersonebergado
Автор

yo what is after else function in line 38

I can't find it in the video. Also there are many bugs in the code

adam.boy
Автор

something is wrong with the code. The buzzer wont top beeping even when nothing is in front of the sensor. Check the code

leni
Автор

mam your project is too good i tried this but i can't able to select the port in the tools can you please help me... i have to submit this project tomorrow plzzz help me mam....

yalamanchilisameera
Автор

tells me that there is a stray # in it but doesnt work pls help

DailyCarnagecodm
Автор

i do not have a buzzer...is it still possible to make this?

vaishnavikoornala
Автор

Did anyone do it with scratch 4 arduino? Because I would like some help with the code s4a. It's for elementary school class

agdimi
Автор

It is working but my buzzer is making less sound how to fix it

Szwaz
Автор

Thnk u thnk u so much it's working

queen_girl
Автор

it says these errors :Compilation error: a function-definition is not allowed here before '{' token
anyone pls help me fix it

TakahiroShinjo-vb
Автор

thank you but my buzzer is super quiet what could i do to fix this?

dragonknightsiriphatra
Автор

Thankyou so much!! Worked well for me❤

dhishiva
Автор

PARABENS POR DEIXAR O CODIGO NOS COMENTAROS, BEIJOS

matheussesi-ut
Автор

Is there barcoding for the device too?

schecterlynx
Автор

what volt of buzzer are used in this project?

ainuldayana
Автор

While I upload the coding itself the buzzer starts to sound I done all thinks as per the circuit diagram why it's happening

mohammedyoonus