GSM900 shield problem.

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.

can someone please help me

With the information you supplied? No.

The code you posted does something. You didn't explain what it does.
You want it to do something. You did not do a good job of explaining what that is.

The code produces (or should) serial output. You didn't share that. The code SHOULD produce a lot more than it currently does.

Sorry you are correct what this does is controls 4 leds over gsm sms text message i serial.print i just put there to see if something comes shows up in the serial monitor will be taking out when it's done.

Hello this is a update from the sketch i posted i looked it over thinking something was wrong with it but i found out by looking at the site stuff it works only problem is that only way from the sketch to turn off leds you either can turn on the first led like #a1 for the first led to turn on but to get another led on if you put #b1 or #c1 and #d1 nothing happens so you can either put #a1 or #a1b1c1d1 for all the leds to come on and they all come on at once i try to figure out how i can change it around but sense I'm limited on my skills for arduinos i really need help from the arduino community please I'm not how to change it so if i text #a1 turns on the first led or #b1 to turn on the second led and so forth i really need help can someone please help me out and point me in the right direction on how i can do this thank you.

Joseph

Hello this is a update from the sketch i posted i looked it over thinking something was wrong with it but i found out by looking at the site stuff it works only problem is that only way from the sketch to turn off leds you either can turn on the first led like #a1 for the first led to turn on but to get another led on if you put #b1 or #c1 and #d1 nothing happens so you can either put #a1 or #a1b1c1d1 for all the leds to come on and they all come on at once i try to figure out how i can change it around but sense I'm limited on my skills for arduinos i really need help from the arduino community please I'm not how to change it so if i text #a1 turns on the first led or #b1 to turn on the second led and so forth i really need help can someone please help me out and point me in the right direction on how i can do this thank you.

Whoa, there. Stop. Take a deep breath. Slow down. Try using some of these ............................................

They are cheap, you know. :slight_smile:

You are sending something to the Arduino. TELL US WHAT!

You are getting something on the Arduino. TELL US WHAT! If you don't know, Use (more) Serial.print() statements to find out.

Until you KNOW what you are sending, and what you are getting, dealing with the input is wishful thinking.

Hello sorry once again what I'm trying to do is send a sms text message from my cellphone to the arduino using the sim900 shield from Seeedstudio v1 i found one sketch that i posted above that i can get to work so far but not correctly i would like to turn on and off 4 leds by sending a sms text message To the arduino from my cellphone to turn on and off theses 4 leds nothing so far i mange to get the first led to work by sending a sms text value of #a1 that did turn on the first led but in order to get the rest of the other 3 leds all command to turn them on haves to be #a1b1cc1d1 if i try to send a text sms message say like #b1 or #c1 nothing happens. so I'm trying to figure out how i can change this so i can control each led by them self without having to turn them all on or off at the same time.

if i try to send a text sms message say like #b1 or #c1 nothing happens.

I can see why. Look at where you test for the second character being a b. That test only happens when the second character is an a.

If you'd indent your code properly, and make use of functions, your code would be a lot easier to debug. For instance, if you get a '#' character, call a function to read the rest of the data.

In that function, if the next character is an 'a', call dealWithA(). Else, if it's a 'b', call dealWithB().

In dealWithA(), read the next character. If it's a '0', do one thing. If it's a '1', do something else.

Soon, you'll see that dealWithA() and dealWithB() and dealWithC() are nearly identical functions, differing only in the pin that they diddle with. You can then replace dealWithA(), dealWithB(), and dealWithC(), etc. with dealWithSecondCharacter() and make that function select the pin to diddle, based on the input character.

But, before you go that route, you really should rethink your protocol. Instead of sending 4 text messages to turn on or off 4 pins, you should be able to send something like "<0010>" to turn on, or off, all 4 pins. Note that the packet includes start-of-packet marker, like you have now, AND an end-of-packet marker (that you do not have now).

Notice too, that you can read the data as fast, or slow, as it arrives, doing other things while you wait for the end of packet marker to arrive, and that you NEVER have to call delay().

Once the start of packet marker arrives, make a note of the fact that you can start storing data. When you can store data, do so. Note that the arrival of the end of packet marker signals that you can no longer store data. Note, too, that it means that you can use the data.

Something like this:

#define SOP '<'
#define EOP '>'

bool started = false;
bool ended = false;

char inData[80];
byte index;

void setup()
{
   Serial.begin(57600);
   // Other stuff...
}

void loop()
{
  // Read all serial data available, as fast as possible
  while(Serial.available() > 0)
  {
    char inChar = Serial.read();
    if(inChar == SOP)
    {
       index = 0;
       inData[index] = '\0';
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
       ended = true;
       break;
    }
    else
    {
      if(index < 79)
      {
        inData[index] = inChar;
        index++;
        inData[index] = '\0';
      }
    }
  }

  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet

    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}

You'll need to adapt this to read from the phone, rather than the serial port, but the idea is the same.

Where it says "Process the packet", you can then use the data in inData to determine which pins to turn on or off.

Hello paul thank you for the reply back. i didn't create this sketch my self i found it on another site for gssm900 stuff but i will try to adapt yours into it looking it over now and what you wrote thank you..

Joseph