Using Arduino with SIM900/SIM800 for receiving SMS commands

The logic is quite simple, We just look for consecutive occurrence of commads like @C1, @C2 or CMD. Whenever the if condition is satisfied the code can take an action like turning ON or OFF a device which might be useful in building automation application for example.

This code is applicable for SIM800,SIM808,SIM908,SIM800C,SIM800H,SIM900A etc all modules as AT commands remain the same.

For more in depth explanation of the concept or live demo look at this video,

 


  ARDUINO CODE: 
     unsigned char Buff[250];   unsigned char BuffIndex;   void setup()   {     Serial.begin(9600);     Serial.println("GSM Tutorial, Valetron Systems @www.raviyp.com ");     delay(3000);     Serial.println("AT+CMGF=1");     delay(3000);     Serial.println("AT+CNMI=2,2,0,0,0");     memset(Buff, '', 250); // Initialize the string     BuffIndex=5;   }         void loop()   {         while(1)       {           if(Serial.available()>0)           {               Buff[BuffIndex] = Serial.read();                          if( (Buff[BuffIndex-2] == '@') && (Buff[BuffIndex-1] == 'C') && (Buff[BuffIndex] == '1'))               {                   Serial.println("Command 1");               }               if( (Buff[BuffIndex-2] == '@') && (Buff[BuffIndex-1] == 'C') && (Buff[BuffIndex] == '2'))               {                   Serial.println("Command 2");               }               if( (Buff[BuffIndex-2] == 'C') && (Buff[BuffIndex-1] == 'M') && (Buff[BuffIndex] == 'D'))               {                   Serial.println("Command CMD");               }                                     BuffIndex++;               if(BuffIndex>250)               {                   BuffIndex=5;               }           }       }           }

Also see:

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *