Here is the code for home automation,the IDE compiles it very fine …but when i send a string …it does not…response …
#include <LiquidCrystal.h>
#include <Servo.h>
LiquidCrystal lcd( 12, 11, 5, 4, 3, 2);
Servo SERVO ;
void setup()
{
Serial.begin(9600);
analogReference(EXTERNAL);
lcd.begin(16, 2);
SERVO.attach(10);
Serial.println("AT\r"); //To check if GSM module is working
delay(2000);
Serial.println("AT+CMGF=1\r"); // set the SMS mode to text
delay(1500);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(13,OUTPUT);
}
void loop()
{
int TEMP_read = analogRead(1);
float temp = ((4.68 * TEMP_read * 100.0) / 1024);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("TempC:");
lcd.println(temp);
int GAS_read = analogRead(2);
if(GAS_read >= 600)
{
lcd.setCursor(0,1);
lcd.print("Gas Detected");
delay(500);
}
if(GAS_read <= 600)
{
lcd.setCursor(0,1);
lcd.print("Gas Not Detected");
delay(500);
}
if(digitalRead(13) == HIGH)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Motion Detected");
Serial.println("Motion Detected");
delay(500);
}
//Serial.print("AT+CMGR=1\r");
//delay(1000);
//RUN2();
if (Serial.available() > 0)
{
//RUN();
RUN2();
}
}
void RUN2()
{
char c[8]={Serial.read()};
if(c == "LOAD1ON")
{
LOAD1_ON();
}
if(c == "LOAD1OFF")
{
LOAD1_OFF();
}
if(c == "LOAD2ON")
{
LOAD2_ON();
}
if(c == "LOAD2OFF")
{
LOAD2_OFF();
}
if(c == "LOAD3ON")
{
LOAD3_ON();
}
if(c == "LOAD3OFF")
{
LOAD3_OFF();
}
if(c == "LOAD4ON")
{
LOAD4_ON();
}
if(c == "LOAD4OFF")
{
LOAD4_OFF();
}
return;
}
//}
//subroutines
void LOAD1_ON()
{
digitalWrite(6,HIGH);
Serial.println("LOAD1=ON");
return;
}
void LOAD1_OFF()
{
digitalWrite(6,LOW);
Serial.println("LOAD1=OFF");
return;
}
void LOAD2_ON()
{
Serial.println("LOAD2=ON");
digitalWrite(7,HIGH);
return;
}
void LOAD2_OFF()
{
digitalWrite(7,LOW);
Serial.println("LOAD2=OFF");
return;
}
void LOAD3_ON()
{
digitalWrite(8,HIGH);
Serial.println("LOAD3=ON");
return;
}
void LOAD3_OFF()
{
digitalWrite(8,LOW);
Serial.println("LOAD3=OFF");
return;
}
void LOAD4_ON()
{
digitalWrite(9,HIGH);
Serial.println("LOAD4=ON");
return;
}
void LOAD4_OFF()
{
Serial.println("LOAD4=OFF");
digitalWrite(9,LOW);
return;
}