I need the following code to allow me to control the LED (pin 13) and also send sms alert when the gas detector pin goes high. When the gas goes pin goes high it sends the alert but then why i send the sms to control the LED that doesn't work. Although if I send the SMS for LED on before the gas pin has gone high it works fine. Its kinda puzzling. Any suggestions? :~
#include <SoftwareSerial.h>
#include <SerialGSM.h>
char inchar;
SoftwareSerial cell(2,3);
SerialGSM cell1(2,3);
void setup()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
digitalWrite(13, LOW);
cell.begin(9600);
delay(4000);
cell.println("AT+CMGF=1");
delay(200);
cell.println("AT+CNMI=2,2,0,0");
delay(200);
}
void loop()
{
while(digitalRead(12)==HIGH)
{
sendsms();
}
//If a character comes in from the cellular module...
if(cell.available() >0)
{
inchar=cell.read();
if (inchar=='l')
{
delay(10);
inchar=cell.read();
if(inchar=='a')
{
delay(10);
inchar=cell.read();
if(inchar=='m')
{
delay(10);
inchar=cell.read();
if(inchar=='p')
{
delay(10);
inchar=cell.read();
if(inchar==' ')
{
delay(10);
inchar=cell.read();
if (inchar=='0')
{
digitalWrite(13, LOW);
}
else if (inchar=='1')
{
digitalWrite(13, HIGH);
}
delay(10);
}
}
}
}
}
}
}
void sendsms()
{
cell.end();
cell1.begin(9600);
cell1.Verbose(true);
cell1.Boot();
cell1.FwdSMS2Serial();
cell1.Rcpt("+919884499852"); //
cell1.Message("leak");
cell1.SendSMS();
cell1.end();
cell.begin(9600);
}