Go Down

Topic: strcmp() function and led on off problem with sim900 (Read 2364 times) previous topic - next topic


hello friends

i am trying to control the LED pin13 by using sim 900
so i first tried it to control LED by serial consol and its working fine i.e if i am sending "ON" led is turning on and for "OFF" via serial consol so  everything is fine
now i want to control the same via sms using SIM900 so whenever i am sending sms ON the 13 number LED shoul be ON and viceversa

i am using sim900 gsm library and try to do it but its  not working  i have modified the code and the code is compiling but led is not glowing when i send on or off
what is the problem in this code??

Code: [Select]
#include "SIM900.h"
#include <SoftwareSerial.h>
//If not used, is better to exclude the HTTP library,
//for RAM saving.
//If your sketch reboots itself proprably you have finished,
//your memory available.
//#include "inetGSM.h"

//If you want to use the Arduino functions to manage SMS, uncomment the lines below.
#include "sms.h"

//To change pins for Software Serial, use the two lines in GSM.cpp.

//GSM Shield for Arduino
//this code is based on the example of Arduino Labs.

//Simple sketch to send and receive SMS.

int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];

void setup()
 //Serial connection.
 Serial.println("GSM Shield testing.");
 //Start configuration of shield with baudrate.
 //For http uses is raccomanded to use 4800 or slower.
 if (gsm.begin(2400)){
 else Serial.println("\nstatus=IDLE");
pinMode( 13, OUTPUT );
   //Enable this two lines if you want to send an SMS.
   //if (sms.SendSMS("3471234567", "Arduino SMS"))
   //Serial.println("\nSMS sent OK");


void loop()


   //Read if there are messages on SIM card and print them.
   if(gsm.readSMS(smsbuffer, 160, n, 20))//n=array for the sender's number  //smsBuffer=array for the sender's message
     char inSerial[5];  
 int i=0;
 if (Serial.available() > 0)
      while (Serial.available() > 0) {
        inSerial[i]=Serial.read(); //read data  

void Check_Protocol(char inStr[])
 Serial.print("Command: ");
 if(!strcmp(inStr,"ON")) digitalWrite(13,HIGH);
 if(!strcmp(inStr,"OFF")) digitalWrite(13,LOW);


If, instead of just printing raw bits of data to the serial monitor, you actually identified what that data was, I think you'd see what the problem is.

Instead of
Code: [Select]
Code: [Select]
            Serial.print("smsbuffer: [";

That way, you know where the data is stored on the Arduino.

Then, look at where you actually use the data from the text message. Nowhere, that is.
The art of getting good answers lies in asking good questions.


Code: [Select]
Serial.print("smsbuffer: [";

i tried this but not able to even print on or off
i am very confused!!!!!!!!!!!!!!!!!!!!!


Did you get any output to the serial monitor when you printed smsbuffer as suggested ?  If so, what was it ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.


Apr 21, 2013, 06:21 am Last Edit: Apr 21, 2013, 06:34 am by chintan123 Reason: 1
it is printing like this for on but for off strangely its not printing anything!!!! :smiley-surprise:

this is what my serial moniter say when i send on but nothing is happenging

thanks for your intrest in my post
what should be the problem???

GSM Shield testing.

smsbuffer: [on


it is printing like this for on but for off strangely its not printing anything!!!!

OK.... Then,,,, you have three problems....

One, you are not getting correct data in smsbuffer in all cases. That could be a library problem (unlikely) or some network issue or something outside the Arduino.

Two, you have smsbuffer that sometimes contains correct data. Now, look at your code, and see where you USE smsbuffer after you print it. Nowhere. Does that seem right? Not to me. Do you now know what you need to do?

Third, your ! key is sticking, and your shift key is not working. I'd suggest that you get your keyboard cleaned.
The art of getting good answers lies in asking good questions.

Go Up