ARDUINO GSM BASED LPG LEAKAGE DETECTOR

#include <SoftwareSerial.h>
SoftwareSerial GSM(3, 2); // TX AND RX PINS

char phone_no[] = "+919074213906"; // REPLACE THIS NUMBER WITH YOUR NO(FOR ALERT)

#define INP 5   //SENSOR PIN 

void setup()
{
  Serial.begin(9600);
  GSM.begin(9600);
  pinMode(INP, INPUT_PULLUP);
  Serial.println("Initializing....");
  initModule("AT", "OK", 1000);
}

void loop() {
  if (digitalRead (INP) == 1)
  {
    callUp(phone_no);
  }
  delay(5);
}


void callUp(char *number) {
  GSM.print("ATD + "); GSM.print(number); GSM.println(";"); //THIS AT COMAND IS FOR MAKING CALLS
  delay(20000);
  GSM.println("ATH"); //TO CUT CALL
  delay(100);
}


void initModule(String cmd, char *res, int t) {
  while (1) {
    Serial.println(cmd);
    GSM.println(cmd);
    delay(100);
    while (GSM.available() > 0) {
      if (GSM.find(res)) {
        Serial.println(res);
        delay(t);
        return;
      } else {
        Serial.println("Error");
      }
    }
    delay(t);
  }
}

Leave a comment