Hackster is hosting Hackster Holidays, Ep. 5: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 5 on Friday!
Daini
Published © CC BY-SA

Home Security System using GSM

Home Security System Using Arduino, Pir Sensor And GSM Sim900A

BeginnerFull instructions provided1 hour29,612
Home Security System using GSM

Things used in this project

Story

Read more

Schematics

Schematic For this project

Code

Programming

Arduino
#include <SoftwareSerial.h>
SoftwareSerial SIM900(2, 3);
String textForSMS;

int pirsensor = 10;
int buzzer = 9;
int red = 7;
int green = 8;

void setup() {
  randomSeed(analogRead(0));
  Serial.begin(9600);
  SIM900.begin(9600); // original 19200. while enter 9600 for sim900A
  Serial.println(" logging time completed!");
  pinMode(pirsensor, INPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  digitalWrite(buzzer, LOW);
  digitalWrite(red, LOW);
  digitalWrite(green, LOW);

  delay(100);

}

void loop() {


  if ( digitalRead(pirsensor) == HIGH) //
  {
    textForSMS =  "\Any Person in your Room  Plz Check It ";

    digitalWrite(buzzer, HIGH);
    digitalWrite(red, HIGH);
    digitalWrite(green, LOW);
    sendSMS(textForSMS);
    Serial.println(textForSMS);
    Serial.println("message sent.");
    delay(8000);
  }
  if ( digitalRead(pirsensor) == LOW) //
  {
    digitalWrite(buzzer, LOW);
    digitalWrite(red, LOW);
    digitalWrite(green, HIGH);
    delay(1000);
  }

}


void sendSMS(String message)
{
  SIM900.print("AT+CMGF=1\r");                     // AT command to send SMS message
  delay(1000);
  SIM900.println("AT + CMGS = \"+918830584864\"");  // recipient's mobile number, in international format

  delay(1000);
  SIM900.println(message);                         // message to send

  SIM900.println((char)26);                        // End AT command with a ^Z, ASCII code 26
  delay(1000);
  SIM900.println();
  // give module time to send SMS

}

Credits

Daini

Daini

31 projects • 16 followers

Comments