Hi,
I'm a newbie in gsm & arduino programming.
I created a simple code that will open on/off my relay.
When I send "ON" it will open and when I send "OFF" it will closed.
Here's my simple code.
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);
String inData;
char inchar;
int led1 = 10;
int led2 = 11;
int led3 = 12;
int led4 = 13;
void setup()
{
Serial.begin(19200);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
SIM900power();
SIM900.begin(19200);
delay(20000);
SIM900.print("AT+CMGF=1\r");
delay(100);
SIM900.print("AT+CNMI=2,2,0,0,0\r");
delay(100);
}
void SIM900power()
{
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(7000);
}
void loop()
{
while (SIM900.available()>0)
{
char recieved = SIM900.read();
inData += recieved;
delay(200);
if (recieved == '\n')
{
if (inData == "ON") {
digitalWrite(led1, HIGH);
} else if (inData == "OFF") {
digitalWrite(led1, LOW);
} else {
Serial.print("Invalid Command");
}
if(inData == "+++\n"){
Serial.print("OK. Press h for help.");
}
inData = ""; // Clear received message buffer
}
}
}
My problem is within the loop area. Can someone please explain why isn't behaving the way I wanted it to be?
Thank you and appreciate your help.