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

} }

Share

    Recommendations

    • Fix It! Contest

      Fix It! Contest
    • Water Contest

      Water Contest
    • Creative Misuse Contest

      Creative Misuse Contest

    32 Discussions

    sir, can i use this codes with SIM 900A, please answer me

    1.how to send the distance measure using sensor to mobile throught sms

    2.and also want to trigger sensor when an sms is received by sim module

    In the above system it automaticly set the distance according to ur need

    at the first stage

    distance= duration*0.034/2;

    normalDistance = distance;

    nirmalDistance is the setted distance

    I want add for more than one number phone, to what part i must change in code. Please can you help me. I am robiansyah from indonesia

    1 reply

    try this copy the messaging code and repast it one more time

    once try

    ######

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

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

    delay(1000);

    mySerial.println("AT+CMGS=\"+91xxxxxxxxx\"\r");

    delay(1000);

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

    mySerial.println((char)26);

    delay(1000);

    i don`t want to use buzzer what change i have to made in code. please healp

    1 more answer

    remove

    #define piezoPin 8

    and all piezoPin code where ever u find it remove that line

    I don't know exactly...... we need 5v to run ultrasonic but we have only one 5v output if it is possible to connect both ultrasonic to one output of 5v there is a way to connect both trigger and echo pins of ultrasonic sensor to pin 9 and 10 so that there is no need to change code

    int trigPin = 9;



    int echoPin = 10;



    int led = 7;



    int led0 = 3;

     



    void setup() {



      Serial.begin(9600);



       pinMode(led, OUTPUT);

      

       pinMode (led0,OUTPUT);



       pinMode(trigPin, OUTPUT);



      pinMode(echoPin, INPUT);



      // put your setup code here, to run once:



     



    }



     



    void loop() {



      long duration, distance;



      digitalWrite(trigPin,HIGH);



      delayMicroseconds(10000);



      digitalWrite(trigPin, LOW);



      duration=pulseIn(echoPin, HIGH);



      distance =(duration/2)/29.1;



      Serial.print(distance);



      Serial.println("CM");



      delay(10);



    if((distance<=10))



      {



        digitalWrite(led, HIGH);

        digitalWrite(led,LOW);



    }



       else if(distance>10)



    {



         digitalWrite(led, LOW);

         digitalWrite(led0,HIGH);

       }



    int trigPin = 9;



    int echoPin = 10;



    int led = 7;



    int led0 = 3;

     



    void setup() {



      Serial.begin(9600);



       pinMode(led, OUTPUT);

      

       pinMode (led0,OUTPUT);



       pinMode(trigPin, OUTPUT);



      pinMode(echoPin, INPUT);



      // put your setup code here, to run once:



     



    }



     



    void loop() {



      long duration, distance;



      digitalWrite(trigPin,HIGH);



      delayMicroseconds(10000);



      digitalWrite(trigPin, LOW);



      duration=pulseIn(echoPin, HIGH);



      distance =(duration/2)/29.1;



      Serial.print(distance);



      Serial.println("CM");



      delay(10);



    if((distance<=10))



      {



        digitalWrite(led, HIGH);

        digitalWrite(led,LOW);



    }



       else if(distance>10)



    {



         digitalWrite(led, LOW);

         digitalWrite(led0,HIGH);

       }





    Sir in above programme i want msg using gsm modem 300
    If distance less than 10 cm how i can write programme

    If any one can able to write so pls do and send me to

    Sir pls writeup programme for me and mail to me pbhushan451@gmail.com

    thankss bro its working

    Try one by one first only the buzzer later ultrasonic sensor then message you will get it

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

    1 reply

    This code is not run gets some error while compile