Security System Using Ultrasonic Sensor and Gsm Module

Introduction: 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:

·

VCC -> Arduino +5V pin

· GND -> Arduino GND pin

· Trig -> Arduino Digital Pin 9

· Echo -> Arduino Digital Pin 10

Step 3: CONNECTION OF BUZZER:

·

s -> Arduino pin 8

·GND -> Arduino GND pin

Step 4: CONNECTION OF GSM:

GND -> Arduino GND pin

TX -> Arduino Digital Pin 2

RX -> Arduino Digital Pin 3

Step 5: 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 ....

#include<SoftwareSerial.h>

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

} }

Step 7:

Guys This was my mini project in college just posted it for others reference so i may not answer your questions

Be the First to Share

    Recommendations

    • Microcontroller Contest

      Microcontroller Contest
    • Automation Contest

      Automation Contest
    • Make it Glow Contest

      Make it Glow Contest

    58 Comments

    0
    YashwantP1
    YashwantP1

    Question 2 years ago on Step 6

    can i connect this system with mobile

    0
    V.Jagan
    V.Jagan

    Answer 11 months ago

    Yes

    0
    V.Jagan
    V.Jagan

    Reply 11 months ago

    Sim 300

    0
    GilA18
    GilA18

    1 year ago

    You see sir I am using the SIM900 GSM Shield and Arduino model and my problem is everytime the system is triggered, the GSM seems to be not working? Please reply good sir

    1
    AlexisJ22
    AlexisJ22

    1 year ago

    it keeps repeating, sir how can i stop it to only 1 message.. plsss i need this for my project

    0
    MicoyA
    MicoyA

    2 years ago

    i just want to get a message from gsm when it below 10cm or exact 10cm. how?

    0
    vikas62348
    vikas62348

    Question 2 years ago on Step 6

    Do we simply need to copy and paste the code changing the mobile number and the text message only. Will that work fine??
    Please help me its urgent.

    0
    hemanth kumar reddy
    hemanth kumar reddy

    Answer 2 years ago

    Yes if you are using the same components, if it's different I am not sure about it .

    0
    vikas62348
    vikas62348

    2 years ago on Step 6

    Do we simply need to copy and paste the code changing the mobile number and the text message only. Will that work fine??
    Please help me its urgent.

    0
    Niyas24
    Niyas24

    2 years ago

    How can i set triggering distance to 10cm.

    0
    hemanth kumar reddy
    hemanth kumar reddy

    Reply 2 years ago

    normalDistance = distance;
    Change distance
    normalDistance =________________;
    Caluculate distance according to you

    2
    RockP5
    RockP5

    2 years ago

    Gsm module send not message

    0
    Niyas24
    Niyas24

    Reply 2 years ago

    It is not sending any sms

    0
    ashok1111
    ashok1111

    Question 2 years ago

    sir can i used this code on SIM 900A gsm module?

    waiting for your reply :)

    0
    ashok1111
    ashok1111

    Reply 2 years ago

    but the buzzer still beeping continuous then when it reach the corresponding distance it stops a bit