I am trying to send SMS after detecting LPG gas but it is not working.
I am using SIM800 GSM module here. Everything except the GSM Module is working. Need Help!!
//Library declaration
#include <LiquidCrystal.h>
#include <Servo.h>
//global variable
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
#define servoPin 9
Servo myservo;
//Object declaration
LiquidCrystal lcd(12,11,5,4,3,2);
//I/O and variable declaration
int mq5 = A0;
int fan = 8;
int led = 7;
int pos = 90; // variable to store the servo position
float aValue;
int sensor=0;
void setup() {
// put your setup code here, to run once:
// Serial.begin(9600); //Serial debugging
lcd.begin(16,2); //Initialization of LCD
myservo.attach(servoPin);
pinMode(mq5, INPUT);
pinMode(fan, OUTPUT);
pinMode(led, OUTPUT);
pinMode(23, INPUT);
lcd.setCursor(0,0);
lcd.print(“LPG leakage”);
lcd.setCursor(3,1);
lcd.print(“Controller”);
delay(2000);
lcd.clear();
}
void knobON(){
myservo.write(90); // tell servo to go to position in variable ‘pos’
delay(5000); // waits 15ms for the servo to reach the position
}
void knobOff()
{
myservo.write(0); // tell servo to go to position in variable ‘pos’
}
void SendSms(){
mySerial.println(“AT+CMGF=1”); // send SMS in text mode
delay(1000);
mySerial.println("AT+CMGS=“08296931160"”); //CHANGE TO Number , you’d like to receive message
delay(1000);
mySerial.println(“Gas Leakage at HOME (attention required)”); // content of the message
mySerial.println((char)26); // ctrl+z ASCII code
delay(1000); // Wait for 1 second before next reading
}
void loop() {
// put your main code here, to run repeatedly:
aValue = analogRead(mq5);
//debugging purpose
//Serial.println(aValue);
//delay(2000);
if(aValue > 485){
lcd.setCursor(0,0);
lcd.print(“Leakage detected”);
lcd.setCursor(0,1);
lcd.print("Controller ON ");
digitalWrite(fan, HIGH);
digitalWrite(led, HIGH);
SendSms();
knobON();
knobOff();
}
else{
lcd.setCursor(0,0);
lcd.print("Safe Mode ");
lcd.setCursor(0,1);
lcd.print("Controller OFF ");
digitalWrite(fan, LOW);
digitalWrite(led, LOW);
}
}
sketch_may28a.ino (2.07 KB)