Pages: [1]   Go Down
Author Topic: door opening with arduino and SIM900  (Read 1905 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi smiley
I am a student in France, and am currently working on a project to open the door remotely. Specifically with sending a sms.
I have una map R3 + arduino shield a GPRS "SIM900" (seeestudio) + a servo motor.
The problem is that I do not know what software to use with this shield, do I stay in arduino or sscom32E or AT command test?
I want a program that hen I send a sms as "open" drives the servo motor 90 and "close" the furnish to its starting position.
Thank you for your help
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To interface with the SIM900, will require the at commands http://www.simcom.us/act_admin/supportfile/SIM900_ATC_V1.00.pdf, to read the text message you can use the command AT+CMGR, and serialRead to get the reply. To control the servo use the servo library (http://arduino.cc/en/Reference/Servo) and an 'if' statement on the read serial data.
I got a sim900 module last September but have not got round to using it extensively yet, (maybe summer). Here is blog which details use of a TC35 gsm modem, which uses most of the same commands as the sim900, http://denhart.dk/2012/01/21/siemens-tc35-gsm-module-arduino/. Hope this helps.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thank you very much smiley But "siemens TC35 Module" is a software ? where can i download ?
And i have 2 little code but i don't know where include "servo"

#include <SoftwareSerial.h>
 
SoftwareSerial mySerial(7, smiley-cool;

// FR: Mémoire tampon de type string pour les messages du shield GPRS
String msg = String("");
// FR: Est mis à 1 quand le prochain message du shield GPRS contiendra le contenu du SMS
int SmsContentFlag = 0;

// FR: Pin de la LED a allumer/éteindre en fonction du message reçu
int ledPin = 13;

// FR: Code PIN de la carte SIM (si applicable)
String SIM_PIN_CODE = String( "XXXX" );
 
void setup()
{
  mySerial.begin(19200);               // the GPRS baud rate   
  Serial.begin(19200);                 // the GPRS baud rate

  // Initialize la PIN
  pinMode( ledPin, OUTPUT );
  digitalWrite( ledPin, LOW );
}
 
void loop()
{
    char SerialInByte;
     
    if(Serial.available())
    {
       mySerial.print((unsigned char)Serial.read());
     } 
    else  if(mySerial.available())
    {
        char SerialInByte;
        SerialInByte = (unsigned char)mySerial.read();
       
        // FR: Relayer l'information vers le moniteur Serie Arduino
        Serial.print( SerialInByte );
       
        // -------------------------------------------------------------------
        // FR: Le programme écoute également les messages issus du GPRS Shield.
        // -------------------------------------------------------------------
       
        // FR: Si le message se termine par un <CR> alors traiter le message
        if( SerialInByte == 13 ){
          // EN: Store the char into the message buffer
          // FR: Stocké le caractère dans le buffer de message
          ProcessGprsMsg();
         }
         if( SerialInByte == 10 ){
            // EN: Skip Line feed
            // FR: Ignorer les Line Feed
         }
         else {
           // EN: store the current character in the message string buffer
           // FR: stocker le caractère dans la mémoire tampon réservé au message
           msg += String(SerialInByte);
         }
     }   
}
// FR: Execute une action sur base du contenu d'un SMS.
//     Notez que le contenu du SMS est le résultat du traitement de plusieurs messages du shield GPRS.
void ProcessSms( String sms ){
  Serial.print( "ProcessSms for [" );
  Serial.print( sms );
  Serial.println( "]" );
 
  if( sms.indexOf("on") >= 0 ){
    digitalWrite( ledPin, HIGH );
    Serial.println( "LED IS ON" );
    return;
  }
  if( sms.indexOf("off") >= 0 ){
    digitalWrite( ledPin, LOW );
    Serial.println( "LED IS OFF" );
    return;
  }
}

// FR: Envoyer le code PIN de la carte SIM au shield GRPS
void GprsSendPinCode(){
  if( SIM_PIN_CODE.indexOf("XXXX")>=0 ){
    Serial.println( "*** OUPS! you did not have provided a PIN CODE for your SIM CARD. ***" );
    Serial.println( "*** Please, define the SIM_PIN_CODE variable . ***" );
    return;
  }
  mySerial.print("AT+CPIN=");
  mySerial.println( SIM_PIN_CODE );
}

// FR: Demande d'utiliser le mode Text pour la gestion des messages
void GprsTextModeSMS(){
  mySerial.println( "AT+CMGF=1" );
}

void GprsReadSmsStore( String SmsStorePos ){
  // Serial.print( "GprsReadSmsStore for storePos " );
  // Serial.println( SmsStorePos );
  mySerial.print( "AT+CMGR=" );
  mySerial.println( SmsStorePos );
}

// FR: efface le contenu de la mémoire tampon des messages du GPRS shield.
void ClearGprsMsg(){
  msg = "";
}

// FR: interprete le message du GPRS shield et agit en conséquence
void ProcessGprsMsg() {
  Serial.println("");
  Serial.print( "GPRS Message: [" );
  Serial.print( msg );
  Serial.println( "]" );
 
  if( msg.indexOf( "+CPIN: SIM PIN" ) >= 0 ){
     Serial.println( "*** NEED FOR SIM PIN CODE ***" );
     Serial.println( "PIN CODE *** WILL BE SEND NOW" );
     GprsSendPinCode();
  }

  if( msg.indexOf( "Call Ready" ) >= 0 ){
     Serial.println( "*** GPRS Shield registered on Mobile Network ***" );
     GprsTextModeSMS();
  }
 
  // FR: Message non sollicité quand un SMS arrive
  if( msg.indexOf( "+CMTI" ) >= 0 ){
     Serial.println( "*** SMS Received ***" );
     // FR: Rechercher la position de la virgule dans le message complet (+CMTI: "SM",6)
     //     Dans l'exemple, le SMS est stocké à la position 6
     int iPos = msg.indexOf( "," );
     String SmsStorePos = msg.substring( iPos+1 );
     Serial.print( "SMS stored at " );
     Serial.println( SmsStorePos );

     // FR: Demande de lecture du stockage SMS
     GprsReadSmsStore( SmsStorePos );
  }
   
  // FR: Lecture du stockage SMS via l'UART (résultat de la requete GprsReadSmsStore)
  if( msg.indexOf( "+CMGR:" ) >= 0 ){
    // FR: Le prochain message contiendra le contenu du SMS
    SmsContentFlag = 1;
    // FR: Les ligne suivantes sont essentielle pour ne pas effacer le flag!
    ClearGprsMsg();
    return;
  }
 
  //     (this message) will contains the SMS body
  // FR: le message +CMGR précédent indiquait que le message suivant du Shield GPRS
  //     (ce message) contient le corps du SMS
  if( SmsContentFlag == 1 ){
    Serial.println( "*** SMS MESSAGE CONTENT ***" );
    Serial.println( msg );
    Serial.println( "*** END OF SMS MESSAGE ***" );
    ProcessSms( msg );
  }
 
  ClearGprsMsg();
  // FR: Toujours mettre le flag à 0
  SmsContentFlag = 0;




--------------------------------------------





setup() {
  Serial.write("AT+CMGF=1"); //Use text mode for sms

}

loop() {
  Serial.write("AT+CMGL=\"ALL\"\r\n"); //Check which AT commands that will send you the first sms in the sms memory. If there is none you will get an error, but that is ok.
  delay(1000); //Wait for modem to send response
  a = Serial.read(); //Read the modem response
  if ( a.find("off") ) //If off is anywhere in modem response,
     servo(0);   //move servo to zero degrees
  if (a.find("90") ) //If 90 is anywhere in response
     servo(90);  /Move servo to zero degrees
  Serial.write("AT+yyyyy\r\n"); //Check which AT commands delete the first sms
  delay(1000); //Wait for modem response
  Serial.read(); //Read and throw away modem response
}


Logged

Pages: [1]   Go Up
Jump to: