Hello i couldn't find a sketch to control 4 leds into recently but i tried it and not working. but i did find a sketch that receives text messages and shows up on the serial monitor so i change it around a little bare in mind I'm not a program so still a little new to this whole gsm and arduino but i mange to add a few lines from the non working led gsm sketch to the gsm receiver sketch and i somehow mange to get one led to come on and off but the other 3 leds still won't work when sending the command from the cellphone to the arduino can someone please help this is the sketch below.
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);
int onoff=0; // 0 = off, 1 = on
char inchar;
int led1 = 10;
int led2 = 11;
int led3 = 12;
int led4 = 13;
char incoming_char=0;
void setup()
{
Serial.begin(19200); // for serial monitor
SIM900.begin(19200); // for GSM shield
SIM900power(); // turn on shield
delay(5000); // give time to log on to network.
SIM900.print("AT+CMGF=1\r"); // set SMS mode to text
delay(100);
SIM900.print("AT+CNMI=2,2,0,0,0\r");
// blurt out contents of new SMS upon receipt to the GSM shield's serial out
delay(100);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
}
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
digitalWrite(9, HIGH);
delay(1000);
}
void loop()
{
//If a character comes in from the cellular module...
if(SIM900.available() >0)
{
inchar=SIM900.read();
if (inchar=='#')
{
delay(10);
inchar=SIM900.read();
if (inchar=='a')
{
delay(10);
inchar=SIM900.read();
if (inchar=='0')
{
digitalWrite(led1, LOW);
Serial.println("LED 1 OFF");
}
else if (inchar=='1')
{
digitalWrite(led1, HIGH);
Serial.println("LED 1 ON");
}
delay(10);
inchar=SIM900.read();
if (inchar=='b')
{
inchar=SIM900.read();
if (inchar=='0')
{
digitalWrite(led2, LOW);
Serial.println("LED 1 OFF");
}
else if (inchar=='1')
{
digitalWrite(led2, HIGH);
Serial.println("LED 2 ON");
}
delay(10);
inchar=SIM900.read();
if (inchar=='c')
{
inchar=SIM900.read();
if (inchar=='0')
{
digitalWrite(led3, LOW);
}
else if (inchar=='1')
{
digitalWrite(led3, HIGH);
}
delay(10);
inchar=SIM900.read();
if (inchar=='d')
{
delay(10);
inchar=SIM900.read();
if (inchar=='0')
{
digitalWrite(led4, LOW);
}
else if (inchar=='1')
{
digitalWrite(led4, HIGH);
}
delay(10);
}
}
SIM900.println("AT+CMGD=1,4"); // delete all SMS
}
}
}
}
}
can someone please help me thank you.