Issue with GSM shield recieving and processing SMS message with arduino uno

Good afternoon,

After several days of tinkering around with this project I am finally beat and I am requesting assistance. I modified a code from an instructables page, to use in my project. My goal was to be able to control 7 relays via SMS to the board from another cellphone, and use the 8th relay to control and LED to let me know the relay board was recieving power. After my modified code failed I went back to the basic code that I pulled from this web page, and still I couldn't get it to work.

I'm using a sim card from an AT&T GoPhone, arduino uno, a GSM shield that I picked up from ebay, and an 8 relay board that I also bought on ebay.

The relay shield is properly communicating with the arduino uno board, as my 8th relay is blinking my LED on and off. The other 7 relays are in a constant "HIGH" position (which is not what I want until I send an SMS telling it to do so). I've tried sending SMS to turn the relays off, and still no luck. The sim card is activated and is capable of recieving SMS when I put it in the throw away phone, and it has stored every SMS received while installed on the GSM shield and opens them up once installed back in the phone. I have looked over both the shield and the board to verify jumpers are in the correct position (I'm almost certain that they are), and still nothing.

I guess what I'm asking is for someone to look over my code and see if there are any noticable issues, make note if it's a mechanical issue, or the more likely case of user error. I'm not sure if this helps or not (I've tried it with and without), but the pin number to my sim is 4104. I may have plugged that into the wrong spot on the code.

Thank you in advance for any help someone is able to provide.


arduino cellphone.txt (5.24 KB)

Here is a copy of my code. I thought it posted properly in my original topic. Once again thank you for reviewing this.

// String buffer for the GPRS shield message
String msg = String("");
// Set to 1 when the next shield message will contain the SMS message
int SmsContentFlag = 1 ;
//control pins of relay.
int relay_a=4;
int relay_b=5;
int relay_c=6;
int relay_d=7;
int relay_e=8;
int relay_f=9;
int relay_g=10;
int ledPin = 13;                 // LED connected to digital pin 13

// Code PIN of the SIM card
// String SIM_PIN_CODE = String( "XXXX" );
void setup()
  Serial.begin(19200);                 // GPRS baud rate
  // Initialize  PINs
  pinMode( 4, OUTPUT ); 
  pinMode( 5, OUTPUT ); 
  pinMode( 6, OUTPUT ); 
  pinMode( 7, OUTPUT ); 
  pinMode( 8, OUTPUT );
  pinMode( 9, OUTPUT );
  pinMode( 10, OUTPUT );
  pinMode(ledPin, OUTPUT);      
  digitalWrite( 4, LOW); 
  digitalWrite( 5, LOW ); 
  digitalWrite( 6, LOW );
  digitalWrite( 7, LOW );
  digitalWrite( 8, LOW );
  digitalWrite( 9, LOW );
  digitalWrite( 10, LOW );
 Serial.println( "AT+CMGF=1" ); 
void loop()
    char SerialInByte;
        SerialInByte = (unsigned char);
        // -------------------------------------------------------------------
        // Program listens to the GPRS shield message.
        // -------------------------------------------------------------------
       // If the message ends with <CR> then process the message
        if( SerialInByte == 13 ){
          // EN: Store the char into the message buffer
         if( SerialInByte == 10 ){
            // Skip Line feed
         else {
           // store the current character in the message string buffer
           msg += String(SerialInByte);
   digitalWrite(ledPin, HIGH);   // sets the LED on
   delay(1000);                  // waits for 1 second
   digitalWrite(ledPin, LOW);    // sets the LED off
   delay(1000);                  // waits for 1 second
// Action based on the content of SMS. 
// Notice that SMS content is the result of processing several GPRS shield messages.
void ProcessSms( String sms ){
  if( sms.indexOf("ona") >= 0 ){
    digitalWrite( relay_a, HIGH );
    digitalWrite( relay_a, LOW );
   if( sms.indexOf("onb") >= 0 ){
    digitalWrite(  relay_b, HIGH );
    digitalWrite( relay_b, LOW );
   if( sms.indexOf("onc") >= 0 ){
    digitalWrite(  relay_c, HIGH );
    digitalWrite( relay_c, LOW );
  if( sms.indexOf("ond") >= 0 ){
    digitalWrite(  relay_d, HIGH );
    digitalWrite( relay_d, LOW );
  if( sms.indexOf("one") >= 0 ){
    digitalWrite( relay_e, HIGH );
    digitalWrite( relay_e, LOW );
  if( sms.indexOf("onf") >= 0 ){
   digitalWrite( relay_f, HIGH);
   digitalWrite( relay_f, LOW );
  if( sms.indexOf("ong") >= 0 ){
   digitalWrite( relay_g, HIGH);
   digitalWrite( relay_g, LOW );
  if( sms.indexOf("offa") >= 0 ){
    digitalWrite(  relay_a, LOW );
  if( sms.indexOf("offb") >= 0 ){
    digitalWrite(  relay_b, LOW );
  if( sms.indexOf("offc") >= 0 ){
    digitalWrite(  relay_c, LOW );
  if( sms.indexOf("offd") >= 0 ){
    digitalWrite(  relay_d, LOW );
  if( sms.indexOf("offe") >= 0 ){
    digitalWrite( relay_e, LOW );
  if( sms.indexOf("offf") >= 0 ){
    digitalWrite( relay_f, LOW );
  if( sms.indexOf("offg") >= 0 ){
    digitalWrite( relay_g, LOW );
// Request Text Mode for SMS messaging
void GprsTextModeSMS(){
  Serial.println( "AT+CMGF=1" );

void GprsReadSmsStore( String SmsStorePos ){
  Serial.print( "AT+CMGR=1" );
  Serial.println( SmsStorePos );

// Clear the GPRS shield message buffer
void ClearGprsMsg(){
  msg = "clear";

// interpret the GPRS shield message and act appropiately
void ProcessGprsMsg() {
  if( msg.indexOf( "Call Ready" ) >= 0 ){
   // Serial.println( "*** GPRS Shield registered on Mobile Network ***" );
  // unsolicited messages received when getting a SMS message
  if( msg.indexOf( "+CMTI" ) >= 0 ){
   //  Serial.println( "*** SMS Received ***" );
     // Look for the coma in the full message (+CMTI: "SM",6)
     // In the sample, the SMS is stored at position 6
     int iPos = msg.indexOf( "," );
     String SmsStorePos = msg.substring( iPos+1 );
   //  Serial.print( "SMS stored at " );
  //   Serial.println( SmsStorePos );     
     //Ask to read the SMS store
     GprsReadSmsStore( SmsStorePos );
  // SMS store read through UART (result of GprsReadSmsStore request)  
  if( msg.indexOf( "+CMGR:" ) >= 0 ){
    // Next message will contains the BODY of SMS
    SmsContentFlag = 1;
    // The following lines are essentiel to not clear the flag!
  // +CMGR message just before indicate that the following GRPS Shield message 
  //     (this message) will contains the SMS body 
  if( SmsContentFlag == 1 ){
 //   Serial.println( "*** SMS MESSAGE CONTENT ***" );
 //   Serial.println( msg );
 //   Serial.println( "*** END OF SMS MESSAGE ***" );
    ProcessSms( msg );

As far as I know the shield is not going to respond on the standard Serial port.. thats the USB port, you should be using Software Serial library if its a UNO ,or one of the other Serial ports on a Mega ?

I am completely new to this, is Software Serial library something I have to insert into the code? Or is it an I/O pin? I would also like to note that I would like this to be completely stand alone from a computer having to process information and send commands to the arduino board, i.e. built into a project enclosure. This is possible right?

~yes the arduino can be stand alone just needs PSU or a Battery

Yhe Uno board uses its only Serial Port on the USB to allow you to upload programs and debiug by printing to the Serial Monitor.

The GSM shield has a serial port sending data via the pins on shield to the U?NO I don't use the UNO so don't have details to hand. Software Serial is a library of software that lets and of the I>O pins on the UNO to become a Serial port ..

I think before you go any further you need to

  1. Read the various tutorials on the Aeduino site.

  2. Google for information about send / receive sms it not as easy as it first seems..

Keep going the light will come on and you will see how it all fits together

Happy coding..
8) 8)