Sunday, August 25, 2013

Remote Door Open by SMS using Arduino



GSM Module used:

SIM900
Wiki
Testing the module


Video:


Code:
// this code was tested using the modem SIM900

/*

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

Commands:

$ON$
$OFF$

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.begin(9600);
  Serial.begin(9600);
 
   mySerial.println("AT\r\n"); // check communication with the modem.
   delay(500);
   mySerial.println("AT\r\n");
   
   //delete all read SMS
   
   for(int x=1; x<=20; x++){
   mySerial.print("AT+CMGD=");
   mySerial.print(x);
   mySerial.print(",");
   mySerial.print("3");
   mySerial.print("\r\n");  
   delay(1000);
   }
   
  
 
}

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 = mySerial.read(); // print in data to  software serial port for debug perpose.
    
    Serial.print(inchar);

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

    if(inchar == '$'){
      dollar_count++; 
     } 
    

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


  }


}




                                                                                           By: Elimeléc 




















2 comments:

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

    ReplyDelete
  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


    Important!!!

    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:

    http://www.amazon.com/PL2303HX-RS232-Cable-module-Converter/dp/B008AGDTA4/ref=sr_1_1?s=electronics&ie=UTF8&qid=1378946584&sr=1-1&keywords=ttl+to+usb


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

    Elimeléc

    ReplyDelete

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