Introduction: Security System Using Ultrasonic Sensor and Gsm Module

Picture of Security System Using Ultrasonic Sensor and Gsm Module

we used the following components:

· Aurdino Uno

· GSM Module,

· Ultrasonic Sensor

· Piezo Buzzer

· Breadboard and Jump Wires.

Step 1:

Step 2: CONNECTION OF ULTRASONIC SENSOR:

Picture of CONNECTION OF ULTRASONIC SENSOR:

·

VCC -> Arduino +5V pin

· GND -> Arduino GND pin

· Trig -> Arduino Digital Pin 9

· Echo -> Arduino Digital Pin 10

Step 3: CONNECTION OF BUZZER:

Picture of CONNECTION OF BUZZER:

·

s -> Arduino pin 8

·GND -> Arduino GND pin

Step 4: CONNECTION OF GSM:

Picture of CONNECTION OF GSM:

GND -> Arduino GND pin

TX -> Arduino Digital Pin 2

RX -> Arduino Digital Pin 3

Step 5: Over View

Picture of Over View

At the first step, we are going to store the first distance as ‘Distance’ later in the loop we are going to check every time if the if the Distance is equal to the distance we got now if the distance is less than the distance we stored at the initial setup the trigger will goes on and the Buzzer will start buzzing and at the same time GSM module will send a message to the mobile number we given.

Step 6: Code ....

// use header file #include of SoftwareSerial.h //hope u understand it due to some reason i can not able to show as normal so thanks //////////////////////

#define trigPin 9

#define echoPin 10

#define piezoPin 8

SoftwareSerial mySerial(2, 3);

int normalDistance;

boolean triggered = false;

long duration, distance;

void setup()

{

mySerial.begin(9600);

Serial.begin (9600);

delay(100);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

pinMode(piezoPin, OUTPUT);

digitalWrite(piezoPin, HIGH);

long duration, distance;

while (millis() < 5000)

{

digitalWrite(piezoPin, HIGH);

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance= duration*0.034/2;

normalDistance = distance;

Serial.print("Distance: ");

Serial.println(distance);

digitalWrite(piezoPin, LOW);

} }

void loop()

{

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance= duration*0.034/2;

Serial.print("Distance: ");

Serial.println(distance);

if (distance < normalDistance-5)

{

triggered = true;

}

else

{

triggered = false;

}

if (triggered)

{

tone(piezoPin, 635);

delay(500);

tone(piezoPin, 912);

delay(250);

mySerial.println("AT+CMGF=1");

//Sets the GSM Module in Text Mode

delay(1000);

// Delay of 1000 milli seconds or 1 second mySerial.println("AT+CMGS=\"+91xxxxxxxxx\"\r");

// Replace x with mobile number

delay(1000);

mySerial.println("I am SMS from GSM Module");

// The SMS text you want to send delay(100);

mySerial.println((char)26);

// ASCII code of CTRL+Z

delay(1000);

} }

Comments

JessejoeT (author)2017-12-14

the buzzer is always turn on w/c is very noisy even though there's no motion yet and also no sms is sent

JessejoeT (author)2017-12-14

bro what seems to be the problem?

JessejoeT (author)2017-12-14

it's not working

NurulF14 (author)2017-04-04

thanks for your tutorial in advance... but, could you tell me why the #include coding got error in arduino? what the coding used for? thanks

For some reason it is not showing what iam typing in brakets u know how the #include works so
Place
SoftwareSerial.h
Header file

thank you so much :)

For some reason it is not showing what iam typing in brakets u know how the #include works so
Place
SoftwareSerial.h
Header file

Its some pasting miss spelled its #include

Sorry for that
I will change it
#include

Swansong (author)2017-03-28

It looks good :) I need to set up a sensor on the garage door just so my husband will remember to close it, lol.

Thanks & good luck in it

:)

About This Instructable

1,586views

4favorites

More by hemanth kumar reddy:Security System Using Ultrasonic Sensor and Gsm Module
Add instructable to: