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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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

    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    54 Discussions

    None
    AlexisJ22

    7 months ago

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

    None
    YashwantP1

    Question 8 months ago on Step 6

    can i connect this system with mobile

    None
    MicoyA

    8 months ago

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

    None
    vikas62348

    Question 9 months 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.

    1 answer
    None
    vikas62348

    9 months 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.

    1 reply
    None
    hemanth kumar reddyNiyas24

    Reply 9 months ago

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

    None
    ashok1111

    Question 1 year ago

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

    waiting for your reply :)

    3 answers

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

    None
    RockP5

    10 months ago

    Please reply sir

    None
    SebastianT73

    11 months ago

    How to use this programming together with GSM?
    #include <SoftwareSerial.h>
    int trigPin = 5; //Trig - green Jumper
    int echoPin = 4; //Echo - yellow Jumper
    int countled = 10; //count led
    int detectled = 9;
    long duration, cm, inches;
    int shoe = 0;
    void setup()
    {
    Serial.begin (9600);
    //Define inputs and outputs
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
    pinMode(countled, OUTPUT);
    pinMode(detectled, OUTPUT);
    }
    void loop()
    {
    // The sensor is triggered by a HIGH pulse of 10 or more microseconds.
    // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
    digitalWrite(trigPin, LOW);
    delayMicroseconds(5);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    // Read the signal from the sensor: a HIGH pulse whose
    // duration is the time (in microseconds) from the sending
    // of the ping to the reception of its echo off of an object.
    pinMode(echoPin, INPUT);
    duration = pulseIn(echoPin, HIGH);
    // convert the time into a distance
    cm = (duration/2) / 29.1;
    inches = (duration/2) / 74;
    Serial.println(shoe);
    Serial.print(inches);
    Serial.print("in, ");
    Serial.print(cm);
    Serial.print("cm");
    Serial.println();
    if (cm < 12 && cm > 0)
    {
    digitalWrite(countled, HIGH);
    if (digitalRead(countled) == HIGH) {
    shoe += 1;
    delay(1000); // Wait for 1000 millisecond(s)
    digitalWrite(countled, LOW);
    }
    if (shoe == 3) {
    digitalWrite(detectled, HIGH);
    }
    } else {
    digitalWrite(countled, LOW);
    }
    delay(250);
    }
    I want to send the message after it count 3.
    Please help me I really need your help.

    None
    PrincessE10

    11 months ago

    Thank you for this tutorial, master!