Sunday, November 30, 2014

Receive SMS when there's a GAS leakage using SIM900A GSM module and Arduino






If you want to receive information about gas leakage when you are at home or office, this project is for you. the above fritzing explains how to interface (connect) GSM module (SIM900A) to arduino, the program is really simple , when the sensor receives a gas emission , it sends input to the arduino and arduino push the code for sending message to SIM900A, which then send you stored message to the number given to the program.




Components Required

GSM shield
Arduino
Gas detection sensor module

_________________________________________________________________________________

Arduino Program:

int PIN = 7;// attach gas sensor to pin 7
int sensor = 0;

void setup()
{
pinMode (PIN,INPUT);
Serial.begin(9600); // gsm baud rate
delay(5000);
}
void loop()
{
sensor = digitalRead (PIN); // read whether gas is presented or not
if (sensor == HIGH){   // if gas is presented send a message
Serial.println("AT");
delay(1000);
Serial.println("AT+CMGF=1"); // send SMS in text mode
delay(1000);
Serial.println("AT+CMGS=\"+919962\""); //CHANGE TO Number , you'd like to receive message
delay(1000);
Serial.print("Gas Leakage at HOME (attention required)"); // content of the message
Serial.write(26); // ctrl+z ASCII code
delay(300000); // Wait for 5 minutes before next reading
}
}

_________________________________________________________________________________



5 comments :

  1. please explain me why there is a 3rd connection given from the sensor to the audrino board which is connected to the 7th terminal of the board? if so then is it same for all the sensors to have 3 terminals .And most important of all where do i purchase these in india
    thanks in advance

    ReplyDelete
  2. Do you have code for SIM300

    or will the same code works with SIM 300 GSM module?

    ReplyDelete
  3. Can someone help me? This is my code.

    #include
    #include "SIM900.h"
    #include "sms.h"
    #include
    //#include
    #include
    SMSGSM sms;
    boolean started = false;
    char buffer[160];
    char smsbuffer[160];
    char n[20];
    //LiquidCrystal lcd(4,2,3,7,8,9);
    int buttonState;
    int lastButtonState = LOW;
    long lastDebounceTime = 0;
    long debounceDelay = 50;
    boolean st = false;
    int buzzer = 12;

    void setup() {


    //lcd.begin(16, 2);
    Serial.begin(9600);
    if (gsm.begin(2400))
    {
    started = true;
    }
    if (started)
    {
    delsms();
    }
    sms.SendSMS("+60142646978" , "Gas Sensor and GSM module activated");


    }

    void loop() {

    //lcd.setCursor(0, 0);

    //lcd.print("Detektor Gas SMS");
    int val = analogRead(A0);
    val = map(val, 0, 1023, 0, 100);
    //lcd.setCursor(0,1);
    //lcd.print("Kadar: ");
    //lcd.print(val);
    //lcd.print("% ");

    //code using sensor detection
    if (val > 10) {
    tone(buzzer,800,500);
    delay(1000);
    st = true;
    }
    else st = false;

    if (st != lastButtonState) {
    lastDebounceTime = millis();
    }


    if ((millis() - lastDebounceTime) > debounceDelay) {

    if (st != buttonState) {
    buttonState = st;


    if (buttonState == HIGH) {
    PString str(buffer, sizeof(buffer));
    str.begin();
    str.print("Gas Detected! Gas leakage at ");
    str.print(val);
    str.print("%");
    //String a=str;
    sms.SendSMS("+60142646978", buffer);
    }
    }
    }

    //code using sms lapor.
    lastButtonState = st;
    int pos = 0;
    if (started)
    {
    pos = sms.IsSMSPresent(SMS_ALL);
    if (pos)
    {
    sms.GetSMS(pos, n, smsbuffer, 100);
    delay(2000);
    if (!strcmp(smsbuffer, "lapor"))
    {
    PString str(buffer, sizeof(buffer));
    str.begin();
    str.print("Rate of gas leakage currently at ");
    str.print(val);
    str.print("%");
    //String a=str;
    sms.SendSMS("+60142646978", buffer);
    }
    delsms();
    }
    }
    }

    //delete sms yang dihantar
    void delsms()
    {
    for (int i = 0; i < 10; i++)
    {
    int pos = sms.IsSMSPresent(SMS_ALL);
    if (pos != 0)
    {
    if (sms.DeleteSMS(pos) == 1) {} else {}
    }
    }
    }



    I'm using arduino uno, sim900 module, mq2 gas sensor and buzzer to create a gas sensor detector based on sms.
    I have to 2 option :
    1. The mq2 gas sensor detects and send the result via sms to the number set in the code.
    2. We can send a specific string to know the surrounding gas percentage and send the result to the specific number set in the code.

    But I want to change the second option to be auto reply to any incoming number. What should I do?

    ReplyDelete