#include <SoftwareSerial.h> // added GSM Sensor serial communication library
#include <LiquidCrystal_I2C.h> // add a library to enable scripts for lcd
SoftwareSerial myserial(9, 10); // declare pins 9 and 10 for GSM serial communication
char msg; // declare variable msg with data type char
char call; // declare a variable call with data type char
LiquidCrystal_I2C lcd(0x3F ,2,1,0,4,5,6,7,3, POSITIVE); // activate the lcd address and pin used
const int sensorValue = 0; // declare a value for sensor value with 0, with data type const int
int piezopin = 13; // declare piezopine on pin 13
int ppmgas; // declare variable ppm gas
int gaspercent; // declare a variable gas percent
int gas=analogread(sensorvalue); // declare gas as analog data reading from sensor value
int a = 1; // declares the value of a as 1, the value of a is used when reading sensor data mq5
void setup() {
myserial.begin(9600); // setting the baud rate of gsm module with 9600
serial.begin(9600); // setting baudrate of serial data with 9600
lcd.begin(16, 2); // start lcd command
lcd.setcursor(0,0); // setting the position of the text to be displayed on the lcd
lcd.print("Detection system"); // display detection system writing on lcd
lcd.setcursor(0,2); // setting the position of the text to be displayed on the lcd
lcd.print("Gas leaking"); // display detection system writing on lcd
delay(2000); // delay 2000 ms
lcd.clear(); // reset lcd text
}
void loop(){
Serial.println(a); // display the value of a on the serial monitor
Start Preparation Component
Assembly Validation End
80 ILKOM Jurnal Ilmiah Vol. 13, No. 2, August 2021, pp. 78-85 E-ISSN 2548-7779
Suhartono & Suhardi (Pressure measurement algorithm of LPG leakage using MQ6 sensor and GSM SIM900 for smart home)
lcd.setCursor(0,0); // setting the position of the text to be displayed on the lcd
lcd.print("Gas Level:"); // display gas level writing on lcd
lcd.setCursor(0,2); // setting the position of the text to be displayed on the lcd
lcd.print(String(GasPercent)+("% ")+String(ppmGas)+("ppm")+(" ")); // display text on lcd
GasPercent = map(analogRead(sensorValue),0,1023,0,100); // mapping program for analog data is converted to
percent, i.e. values from 0 to 1023 are mapped to 0-100 :
ppmGas = map(analogRead(sensorValue),0,1023,0,1000); // mapping program for analog data is converted to
percent, i.e. values from 0 to 1023 are mapped to 0-100 :
if(ppmGas > 200 && a < 2){ // to indicate if the gas is leaking then the gas ppm value will be above 200,
where the value above 200 must pass 2 readings to be able to send messages
SendMessage(); // perform an order to send a message
a = a + 1; // calculation algorithm to be able to send messages
}
if(ppmGas > 200){ // if the value of ppm is above the value of 200 then
lcd.setCursor(0,0); // setting the position of the text to be displayed on the lcd
lcd.print("Danger!! "); // display danger writing on lcd
tone(piezoPin, 2000, 800);
}else{ // if not
a = 1; // the value of a returns to 1
}
Serial.println(ppmGas); // displaying the ppm value of the serial gas monitor
delay(1000);
}
void SendMessage() // displaying the ppm value of the serial gas monitor
{
Serial.println("send");
mySerial.println("AT+CMGF=1"); // set the modem as sms text mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"+6285343804326\"\r"); // setting sms text mode by sending to a phone number
delay(1000);
mySerial.println("Danger Warning!!! There has been a gas leak in your home.");// send text message
delay(100);
mySerial.println((char)26);// send ascii data to mark end of text
delay(1000);
}