Sunday, August 25, 2013

Remote Door Open by SMS using Arduino

GSM Module used:

Testing the module


// this code was tested using the modem SIM900


this code turn "On" and "Off" an LED by SMS.



Note: the commands are case sensitive.


#include <SoftwareSerial.h>

SoftwareSerial mySerial(7, 8); // RX, TX

byte led = 13;   // use "byte" instead of "int" to save memory.
byte led_on = 0;
byte led_off = 0;
byte dollar_count = 0;

long last_millis = 0;
const int delay_time = 5000;

const int buff_size = 10;
char buffer[buff_size];

void setup()  
  pinMode(led, OUTPUT);
   mySerial.println("AT\r\n"); // check communication with the modem.
   //delete all read SMS
   for(int x=1; x<=20; x++){

void loop(){

     if ((millis() - last_millis) > delay_time ){
       mySerial.print("AT+cmgl=\"REC UNREAD\"\r\n");
       last_millis = millis();

  if (mySerial.available() > 0){

    char inchar =; // print in data to  software serial port for debug perpose.

    if(inchar == '\r' || inchar == '\n'){
      dollar_count = 0;
      led_on = 0;
      led_off = 0;

    if(inchar == '$'){

      switch (dollar_count){
      case 1:
      if(inchar == 'O' || inchar == 'N'){
      if(inchar == 'O' || inchar == 'F'){
      if(led_on == 2){
        digitalWrite(led, HIGH);
      if(led_off == 3){
        digitalWrite(led, LOW);



                                                                                           By: Elimeléc 


  1. Hi, im newbie and i load unchanged the code but does not work.. :/
    I use Duemilanove (ATmega328P)
    and this shield
    can you help me?
    (sry for my english)

  2. Hello,

    Please first make sure that the communication with the modem it's o.k, double check the jumpers configuration for the TX and RX pins of your GSM shield and make sure that TX of the GSM shield it's connected to RX (Pin 7) of arduino and RX of GSM shield must be connected to TX (Pin 8) of the arduino board.

    If the RX and TX pins of your module are on a different place you can modify the code at the followig line:

    SoftwareSerial mySerial(7, 8); // RX, TX


    Make sure to turn on your GSM module by pressing and holding for three seconds the power button.

    Also, you can test your module by sending commands using a computer but you will need a Serial to TTL Cable:

    TTL to USB amazon:

    If you need more help, feel free to contact me on Skype at "elopez27" from 9:00 AM to 5:00 PM UTC -4.



Note: Only a member of this blog may post a comment.