Im really sorry but I am a beginner to Arduino and Sketches

I have an Uno with a SIM900 GSM modem piggy backed and have been playing around with some Sketch code which allows me to send the SMS #a0b1c1d0 etc, which works ok. So I decided to try an incorporate an additional function which will allow it to re-act / switch 2 outputs based on an incoming call / RING. But unfortunately it will not do this.

I can imagine that this will be easy to solve but as I say, I'm just learning.

Here is copy of Sketch code:

#include <SoftwareSerial.h>
char inchar; // Will hold the incoming character from the GSM shield
char inring;
SoftwareSerial SIM900(7, 8);

int led1 = 10; // gives the pins a name
int led2 = 11;
int led3 = 12;
int led4 = 13;
int numring=0; // variable to store number of rings
int comring=3; // variable to keep value for number of desired rings before something happens
int onoff=0; // 0 = off, 1 = on // variable to keep value of led off/on state - but is initially set as 0

void setup()
{
Serial.begin(19200);
// set up the digital pins to control
pinMode(led1, OUTPUT); // sets these as outputs
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
digitalWrite(led1, LOW); // set the powerup state of these variables
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(2, HIGH);
digitalWrite(4, LOW);

// wake up the GSM shield
SIM900power();
SIM900.begin(19200);
SIM900.print("AT+CLIP=1\r"); // turn on caller ID notification
delay(100);
}

void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(7000);
}

void doSomething()
{
if (onoff==0)
{
onoff=1;
digitalWrite(2, HIGH);
digitalWrite(4, LOW);
Serial.println("D12 high D13 low");
}
else
if (onoff==1)
{
onoff=0;
digitalWrite(2, LOW);
digitalWrite(4, HIGH);
Serial.println("D12 low D13 high");
loop();
}
}

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);
}
else if (inchar=='1')
{
digitalWrite(led1, HIGH);
}
delay(10);
inchar=SIM900.read();
if (inchar=='b')
{
inchar=SIM900.read();
if (inchar=='0')
{
digitalWrite(led2, LOW);
}
else if (inchar=='1')
{
digitalWrite(led2, HIGH);
}
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
delay(1000);

(SIM900.available() >0);
inring=SIM900.read();
if (inring=='R')
{
delay(10);
inring=SIM900.read();
if (inring=='I')
{
delay(10);
inring=SIM900.read();
if (inring=='N')
{
delay(10);
inring=SIM900.read();
if (inring=='G')
{
delay(10);
// So the phone (our GSM shield) has 'rung' once, i.e. if it were a real phone
// it would have sounded 'ring-ring' or 'blurrrrr' or whatever one cycle of your ring tone is
numring++; // add a single ring value to the numring variable
Serial.println("ring!");
if (numring==comring) // if both numring variable are the same as comring value then do the below
{
numring=0; // reset ring counter
delay (500);
doSomething();}
}
}
}
}
}
}
}
}
}
}
}

Suggestions
Read and follow the advice in read this before posting a programming question At the very least using code tags will remove the smiley from your program.
Format your program using AutoFormat before uploading it.

Sorry, I will repost again. My mistake

I have an Uno with a SIM900 GSM modem piggy backed and have been playing around with some Sketch code which allows me to send the SMS #a0b1c1d0 etc, which works ok. So I decided to try an incorporate an additional function which will allow it to re-act / switch 2 outputs based on an incoming call / RING. But unfortunately it will not do this.

I can imagine that this will be easy to solve but as I say, I'm just learning.

Here is copy of Sketch code:

``#include <SoftwareSerial.h>
char inchar; // Will hold the incoming character from the GSM shield
char inring;
SoftwareSerial SIM900(7, 8);

int led1 = 10; // gives the pins a name
int led2 = 11;
int led3 = 12;
int led4 = 13;
int numring=0; // variable to store number of rings
int comring=3; // variable to keep value for number of desired rings before something happens
int onoff=0; // 0 = off, 1 = on // variable to keep value of led off/on state - but is initially set as 0

void setup()
{
Serial.begin(19200);
// set up the digital pins to control
pinMode(led1, OUTPUT); // sets these as outputs
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
digitalWrite(led1, LOW); // set the powerup state of these variables
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(2, HIGH);
digitalWrite(4, LOW);

// wake up the GSM shield
SIM900power();
SIM900.begin(19200);
SIM900.print("AT+CLIP=1\r"); // turn on caller ID notification
delay(100);
}

void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(7000);
}

void doSomething()
{
if (onoff==0)
{
onoff=1;
digitalWrite(2, HIGH);
digitalWrite(4, LOW);
Serial.println("D12 high D13 low");
}
else
if (onoff==1)
{
onoff=0;
digitalWrite(2, LOW);
digitalWrite(4, HIGH);
Serial.println("D12 low D13 high");
loop();
}
}

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);
}
else if (inchar=='1')
{
digitalWrite(led1, HIGH);
}
delay(10);
inchar=SIM900.read();
if (inchar=='b')
{
inchar=SIM900.read();
if (inchar=='0')
{
digitalWrite(led2, LOW);
}
else if (inchar=='1')
{
digitalWrite(led2, HIGH);
}
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
delay(1000);

(SIM900.available() >0);
inring=SIM900.read();
if (inring=='R')
{
delay(10);
inring=SIM900.read();
if (inring=='I')
{
delay(10);
inring=SIM900.read();
if (inring=='N')
{
delay(10);
inring=SIM900.read();
if (inring=='G')
{
delay(10);
// So the phone (our GSM shield) has 'rung' once, i.e. if it were a real phone
// it would have sounded 'ring-ring' or 'blurrrrr' or whatever one cycle of your ring tone is
numring++; // add a single ring value to the numring variable
Serial.println("ring!");
if (numring==comring) // if both numring variable are the same as comring value then do the below
{
numring=0; // reset ring counter
delay (500);
doSomething();}
}
}
}
}
}
}
}
}
}
}
}``

Please accept my sincere apologies for reposting twice but I stupidly did not read the guide for posting. Here is my post again:

I have an Uno with a SIM900 GSM modem piggy backed and have been playing around with some Sketch code which allows me to send the SMS #a0b1c1d0 etc, which works ok. So I decided to try an incorporate an additional function which will allow it to re-act / switch 2 outputs based on an incoming call / RING. But unfortunately it will not do this.

I can imagine that this will be easy to solve but as I say, I'm just learning.

Here is copy of Sketch code:

#include <SoftwareSerial.h>
char inchar; // Will hold the incoming character from the GSM shield
char inring;
SoftwareSerial SIM900(7, 8);
 
int led1 = 10; // gives the pins a name
int led2 = 11;
int led3 = 12;
int led4 = 13;
int numring=0; // variable to store number of rings
int comring=3; // variable to keep value for number of desired rings before something happens
int onoff=0; // 0 = off, 1 = on // variable to keep value of led off/on state - but is initially set as 0
 
void setup()
{
  Serial.begin(19200);
  // set up the digital pins to control
  pinMode(led1, OUTPUT); // sets these as outputs
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  digitalWrite(led1, LOW); // set the powerup state of these variables
  digitalWrite(led2, LOW);
  digitalWrite(led3, LOW);
  digitalWrite(led4, LOW);
  digitalWrite(2, HIGH);
  digitalWrite(4, LOW);
 
  // wake up the GSM shield
  SIM900power();
  SIM900.begin(19200);
  SIM900.print("AT+CLIP=1\r"); // turn on caller ID notification
  delay(100); 
}
 
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
  digitalWrite(9, HIGH);
  delay(1000);
  digitalWrite(9, LOW);
  delay(7000);
}

void doSomething()
{
  if (onoff==0)
  {
    onoff=1;
    digitalWrite(2, HIGH);
    digitalWrite(4, LOW);
    Serial.println("D12 high D13 low");
  }
  else
    if (onoff==1)
    {
      onoff=0;
      digitalWrite(2, LOW);
      digitalWrite(4, HIGH);
      Serial.println("D12 low D13 high");
      loop();
    }
}

  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);
        }
        else if (inchar=='1')
        {
          digitalWrite(led1, HIGH);
        }
        delay(10);
        inchar=SIM900.read();
        if (inchar=='b')
        {
          inchar=SIM900.read();
          if (inchar=='0')
          {
            digitalWrite(led2, LOW);
          }
          else if (inchar=='1')
          {
            digitalWrite(led2, HIGH);
          }
          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
          delay(1000);
         
     (SIM900.available() >0);
     inring=SIM900.read();
    if (inring=='R')
    {
      delay(10);
      inring=SIM900.read();
      if (inring=='I')
      {
        delay(10);
        inring=SIM900.read();
        if (inring=='N')
        {
          delay(10);
          inring=SIM900.read();
          if (inring=='G')
          {
            delay(10);
            // So the phone (our GSM shield) has 'rung' once, i.e. if it were a real phone
            // it would have sounded 'ring-ring' or 'blurrrrr' or whatever one cycle of your ring tone is
            numring++; // add a single ring value to the numring variable
            Serial.println("ring!");
            if (numring==comring) // if both numring variable are the same as comring value then do the below
            {
              numring=0; // reset ring counter
              delay (500);
              doSomething();}
          }
        }
      }
    }
            }
          }
        }
      }
    }
  }
}

Your code seems to depend on detecting that there is at least 1 character to read then reading numerous characters at 10 ms intervals without checking that there is anything to read. It would be better to read a single character when one is available and build a string from them until the incoming message is complete.

What does this do?

     (SIM900.available() >0);

And this looks confusing:

          }
        }
      }
    }
            }
          }
        }
      }
    }
  }
}
  //If a character comes in from the cellular module...
{  if(SIM900.available() >0)
  {
    inchar=SIM900.read();
    if (inchar=='#')
    {
      delay(10);
      inchar=SIM900.read();

If one character comes in from the cellular module, read two of them, is that it?

Looking at Reply #7, it seems as if the 2nd example in Serial Input Basics would be a useful way to receive the data.

...R

Sorry for the delay.

I tried to combine the features of 2 sketches that I found -

  1. Send SMS a1b1c1d1 (abcd being the outputs) & (1/0 being either high or low) - this part works ok

  2. Make a call to the modem, where the modem counts the number of "RING" notifications being received and when the variable = 3, then the device will alternate 2x LED's and when called again, it will do the opposite eg a flip-flop - this addition (based on the way I've attempted it) doesnt work as planned.

I'm just trying to learn by looking at different existing sketches and seeing how I can combine which is why I'm at this stage.

Again sorry to sound like a fool but any help or advice on how to best accomplish the above would be very much appreciated.

Thanks for your time.

There is no need to apologize. There is nothing foolish about not knowing something.

You say you have tried to combine sketches. You need to post your code so we can see where you are at.

You may find some useful ideas in Planning and Implementing a Program

...R

Thanks Robin.

Here is the 1st sketch:

#include <SoftwareSerial.h> 
char inchar; // Will hold the incoming character from the GSM shield
SoftwareSerial SIM900(7, 8);

int numring=0;
int comring=3; 
int onoff=0; // 0 = off, 1 = on

void setup()
{
 Serial.begin(19200);
 // set up the digital pins to control
 pinMode(12, OUTPUT);
 pinMode(13, OUTPUT); // LEDs - off = red, on = green
 digitalWrite(12, HIGH);
 digitalWrite(13, LOW);

 // wake up the GSM shield
 SIM900power(); 
 SIM900.begin(19200);
 SIM900.print("AT+CLIP=1\r"); // turn on caller ID notification
 delay(100);  
}

void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
 digitalWrite(9, HIGH);
 delay(1000);
 digitalWrite(9, LOW);
 delay(7000);
}

void doSomething()
{
 if (onoff==0)
 {
   onoff=1;
   digitalWrite(12, HIGH);
   digitalWrite(13, LOW);
   Serial.println("D12 high D13 low");
 } 
 else
   if (onoff==1)
   {
     onoff=0;
     digitalWrite(12, LOW);
     digitalWrite(13, HIGH);
     Serial.println("D12 low D13 high");
   }
}

void loop() 
{
 if(SIM900.available() >0)
 {
   inchar=SIM900.read(); 
   if (inchar=='R')
   {
     delay(10);
     inchar=SIM900.read(); 
     if (inchar=='I')
     {
       delay(10);
       inchar=SIM900.read();
       if (inchar=='N')
       {
         delay(10);
         inchar=SIM900.read(); 
         if (inchar=='G')
         {
           delay(10);
           // So the phone (our GSM shield) has 'rung' once, i.e. if it were a real phone
           // it would have sounded 'ring-ring' or 'blurrrrr' or whatever one cycle of your ring tone is
           numring++;
           Serial.println("ring!");
           if (numring==comring)
           {
             numring=0; // reset ring counter
             doSomething();
           }
         }
       }
     }
   }
 }
}

And here is the 2nd sketch:

#include <SoftwareSerial.h> 
char inchar; // Will hold the incoming character from the GSM shield
SoftwareSerial SIM900(7, 8);
 
int led1 = 10;
int led2 = 11;
int led3 = 12;
int led4 = 13;
 
void setup()
{
  Serial.begin(19200);
  // set up the digital pins to control
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  digitalWrite(led1, LOW);
  digitalWrite(led2, LOW);
  digitalWrite(led3, LOW);
  digitalWrite(led4, LOW);
 
  // wake up the GSM shield
  SIM900power(); 
  SIM900.begin(19200);
  delay(20000);  // 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);
  Serial.println("Ready...");
}
 
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
  digitalWrite(9, HIGH);
  delay(1000);
  digitalWrite(9, LOW);
  delay(7000);
}
 
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);
        } 
        else if (inchar=='1')
        {
          digitalWrite(led1, HIGH);
        }
        delay(10);
        inchar=SIM900.read(); 
        if (inchar=='b')
        {
          inchar=SIM900.read();
          if (inchar=='0')
          {
            digitalWrite(led2, LOW);
          } 
          else if (inchar=='1')
          {
            digitalWrite(led2, HIGH);
          }
          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
        }
      }
    }
  }
}

I was hoping you would post your attempt at combining the sketches.

You may find some useful stuff in this Simple Merge Demo

...R