Smit Babariya
Published

Fire Security System

If a flame is detected, this device will immediately send current location.

IntermediateFull instructions provided10
Fire Security System

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Arduino MKR GSM 1400
Arduino MKR GSM 1400
×1
TinyShield GPS
TinyCircuits TinyShield GPS
×1
Gravity: Analog Flame Sensor For Arduino
DFRobot Gravity: Analog Flame Sensor For Arduino
×1
Buzzer
Buzzer
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

flame sensor with GPS and GSM module

Arduino
#include <SoftwareSerial.h>
#include <TinyGPS++.h>

static const int RXPin = 6, TXPin = 5;   // GPIO 4=D2(conneect Tx of GPS) and GPIO 5=D1(Connect Rx of GPS
static const uint32_t GPSBaud = 9600; //if Baud rate 9600 didn't work in your case then use 4800

SoftwareSerial mySerial(9,10);
SoftwareSerial ss(RXPin, TXPin);  // The serial connection to the GPS device

String latitudes;
String longitudes; 

int green = 12;
int red = 13;
int buzzer = 11;
int flame = 10;

float spd;       //Variable  to store the speed
float sats;      //Variable to store no. of satellites response
String bearing;  //Variable to store orientation or direction of GPS
float latitude;     //Storing the Lat. and Lon. 
float longitude; 

TinyGPSPlus gps; // The TinyGPS++ object

void setup() {
  ss.begin(GPSBaud);
  pinMode(green,OUTPUT);
  pinMode(red, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(flame, INPUT);
  mySerial.begin(9600);
  Serial.begin(9600); 
  delay(500);
}

void loop() 
{  
  while (ss.available() > 0) 
  {
    // sketch displays information every time a new sentence is correctly encoded.
    if (gps.encode(ss.read()))
      displayInfo();
  }

  String maplink = "https://www.google.com/maps/search/?api=1&query=" + latitudes + ',' + longitudes;
  int sms_count = 0;
  int flameSensor = digitalRead(flame);

  Serial.print("Pin 9: ");
  Serial.println(flameSensor);
  
  if (flameSensor == 1)
  {
    digitalWrite(red, HIGH);
    digitalWrite(green,LOW);
    tone(buzzer, 3000, 300);
    
    if(sms_count<=0)
    {   
      mySerial.println("AT+CMGF=1");    //To send SMS in Text Mode
      delay(1000);
      mySerial.println("AT+CMGS=\"+918511017073\"\r"); // change to the phone number you using 
      delay(1000);
      mySerial.println("Fire Waring !!! Go to safe zone.");//the content of the message
      delay(200);
      mySerial.println((char)26);//the stopping character
      delay(1000); 
      mySerial.println(maplink);//the content of the message
      delay(200);
      sms_count++;
    }
    else
    {
      mySerial.println("Nothing Happen");
    }
    mySerial.println("ATD8511017073;");
    delay(1000);
  }
  else
  {
    digitalWrite(red, LOW);
    digitalWrite(green,HIGH);
    noTone(buzzer);
  }
  delay(1000);
}

void checkGPS()
{
  if (gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detected: check wiring."));
  }
}

void displayInfo()
{   
  if (gps.location.isValid() ) 
  {
    float latitude = gps.location.lat();     //Storing the Lat. and Lon. 
    float longitude = gps.location.lng(); 

    String latitudes = String(latitude);
    String longitudes = String(longitude); 
      
    Serial.print("Latitude :  ");
    Serial.println(latitude, 6);  // float to x decimal places
    Serial.print("Longitude : ");
    Serial.println(longitude, 6);
      
    spd = gps.speed.kmph();               //get speed
    Serial.print("Speed : ");
    Serial.print(spd); 
    Serial.println();
         
    sats = gps.satellites.value();    //get number of satellites
    Serial.print("Satellites : ");
    Serial.print(sats); 
    Serial.println();
  
    bearing = TinyGPSPlus::cardinal(gps.course.value()); // get the direction      
    Serial.print("Bearing : ");
    Serial.print(bearing); 
    Serial.println();

  }
  Serial.println();
}

Credits

Smit Babariya

Smit Babariya

8 projects • 3 followers

Comments

Add projectSign up / Login