Pages: 1 2 3 [4] 5   Go Down
Author Topic: reading sms  (Read 7323 times)
0 Members and 1 Guest are viewing this topic.
South Africa
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
this sketch reads incoming sms's and stores it perfectly,the stored sms  doesnt show the contents of it,the word 'on' doesnt appear anywhere on the serial monitor only the cellphone number and some other details,according to the sketch it should activate the led when an sms 'on' is sent,i checked all AT commands they seem to be right,not sure how to modify the part that is responsible for reading the sms,


 #define _SS_MAX_RX_BUFF 128 // RX buffer size
#include <SoftwareSerial.h>
 
SoftwareSerial mySerial(7, 8);

// EN: String buffer for the GPRS shield message
// FR: Mémoire tampon de type string pour les messages du shield GPRS
String msg = String("");
// EN: Set to 1 when the next GPRS shield message will contains the SMS message
// FR: Est mis à 1 quand le prochain message du shield GPRS contiendra le contenu du SMS
int SmsContentFlag = 0;

// EN: Pin of the LED to turn ON and OFF depending on the received message
// FR: Pin de la LED a allumer/éteindre en fonction du message reçu
int ledPin = 13;

// EN: Code PIN of the SIM card (if applied)
// 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();
        
        // EN: Relay to Arduino IDE Monitor
        // FR: Relayer l'information vers le moniteur Serie Arduino
        Serial.print( SerialInByte );
        
        // -------------------------------------------------------------------
        // EN: Program also listen to the GPRS shield message.
        // FR: Le programme écoute également les messages issus du GPRS Shield.
        // -------------------------------------------------------------------
        
        // EN: If the message ends with <CR> then process the message
        // 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);
         }
     }  
}

// EN: Make action based on the content of the SMS.
//     Notice than SMS content is the result of the processing of several GPRS shield messages.
// 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;
  }
}

// EN: Send the SIM PIN Code to the GPRS shield
// 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 );
}

// EN: Request Text Mode for SMS messaging
// 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 );
}

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

// EN: interpret the GPRS shield message and act appropiately
// 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();
  }
  
  // EN: unsolicited message received when getting a SMS message
  // FR: Message non sollicité quand un SMS arrive
  if( msg.indexOf( "+CMTI" ) >= 0 ){
     Serial.println( "*** SMS Received ***" );
     // EN: Look for the coma in the full message (+CMTI: "SM",6)
     //     In the sample, the SMS is stored at position 6
     // 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 );
    
     // EN: Ask to read the SMS store
     // FR: Demande de lecture du stockage SMS
     GprsReadSmsStore( SmsStorePos );
  }
  
  // EN: SMS store readed through UART (result of GprsReadSmsStore request)  
  // FR: Lecture du stockage SMS via l'UART (résultat de la requete GprsReadSmsStore)
  if( msg.indexOf( "+CMGR:" ) >= 0 ){
    // EN: Next message will contains the BODY of SMS
    // FR: Le prochain message contiendra le contenu du SMS
    SmsContentFlag = 1;
    // EN: Following lines are essentiel to not clear the flag!
    // FR: Les ligne suivantes sont essentielle pour ne pas effacer le flag!
    ClearGprsMsg();
    return;
  }
  
  // EN: +CMGR message just before indicate that the following GRPS Shield message
  //     (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();
  // EN: Always clear the flag
  // FR: Toujours mettre le flag à 0
  SmsContentFlag = 0;
}


Code:
GPRS Message: []

NORMAL POWER DOWN

GPRS Message: [
NORMAL POWER DOWN]

Àÿÿÿÿÿÿÿÿ

GPRS Message: [
Àÿÿÿÿÿÿÿÿ]

RDY

GPRS Message: [
RDY]



GPRS Message: [
]

+CFUN: 1

GPRS Message: [
+CFUN: 1]



GPRS Message: [
]

+CPIN: READY

GPRS Message: [
+CPIN: READY]



GPRS Message: [
]

Call Ready

GPRS Message: [
Call Ready]
*** GPRS Shield registered on Mobile Network ***

AT+CMGF=1

GPRS Message: [
AT+CMGF=1]



GPRS Message: [
]

OK

GPRS Message: [
OK]



GPRS Message: [
]

+CMTI: "SM",9

GPRS Message: [
+CMTI: "SM",9]
*** SMS Received ***
SMS stored at 9

AT+CMGR=9

GPRS Message: [
AT+CMGR=9]



GPRS Message: [
]

+CMGR: "REC UNREAD","+27764569***","","13/01/12,17:13:31+08"

GPRS Message: [
+CMGR: "REC UNREAD","+27764569***","","13/01/12,17:13:31+08"]



GPRS Message: [
]
*** SMS MESSAGE CONTENT ***


*** END OF SMS MESSAGE ***
ProcessSms for [
]

OK

GPRS Message: [
OK]



GPRS Message: [
]

NORMAL POWER DOWN

GPRS Message: [
NORMAL POWER DOWN]

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
this sketch reads incoming sms's and stores it perfectly,the stored sms  doesnt show the contents of it,the word 'on' doesnt appear anywhere on the serial monitor only the cellphone number and some other details,according to the sketch it should activate the led when an sms 'on' is sent,i checked all AT commands they seem to be right,not sure how to modify the part that is responsible for reading the sms,
The is NOT code. Learn how to post comments OUTSIDE of the code tags.

Code:
    if(Serial.available())
    else  if(mySerial.available())
Why are these exclusive?

Code:
        char SerialInByte;
        SerialInByte = (unsigned char)mySerial.read();
Why are you separating the declaration and the initialization?

Code:
        char SerialInByte = (unsigned char)mySerial.read();
Casting to an unsigned char to store in a signed char is a bad idea, by the way. The cast is not needed at all.

Code:
        // FR: Si le message se termine par un <CR> alors traiter le message
        if( SerialInByte == 13 ){
Why not make it clear what the code is doing?
Code:
        if( SerialInByte == '\n' ){
If you can add a space after the open parenthesis, why can't you add one after the close parenthesis? Studying the code every time is a waste of time. Organize the code so it is readable.

Code:
         if( SerialInByte == 10 ){
            // EN: Skip Line feed
Again, why not make the code clearer?
Code:
         if( SerialInByte == '\r' ) {

Code:
           msg += String(SerialInByte);
Invoking the constructor, the copy constructor, the assignment operator, and the destructor for the String class to add one character is a waste of resources. The += operator is overloaded to add a character. Use that overload instead of converting the one character to a new String.

In fact, you should get rid of the String class, altogether.

Anyway, none of this has anything to do with why the AT commands are not returning entirely what you expect. That doesn't mean that they should not be fixed. What it tells me is that you are issuing the wrong AT command to read the SMS.
Logged

South Africa
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi, sorry about posting the code with unnecessary text,will clean it up when i make another post,i spent many hours researching strings and looking at other sketches,trying to read an sms and activate the led,finally don't think i understand the strings well enough to modify it and get it to work,so ill have to go back to controlling leds ,sensors ,motors and sending sms's,had no difficulty modifing these sketches and getting them to work,think the best is to use my shield for sending sms's only.
sorry for any inconvenience
Thank you for your help,
Logged

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

I'm fighting with a similar issue. I have a bit different code, and yes, it is far away from optimized or good-looking or professional etc. code. But, never mind, it works almost. I took it from the GeeTech GPRS module wiki page and made some modifications.

This code waits and reacts when a new SMS has received. It reads it (or try to read) and in the future it should do something based on the message content and then delete it. Currently it only deletes it. This part works, it notices a new SMS, reads it and deletes it. Next SMS works similar way.

The problem is in the message itself. If I send a SMS "Testing", only part of it will be displayed, like in the example output below, there is only "Test". If I wrote a longer SMS, the result is not truncated but contains random letters from the SMS sent. Any ideas why?

All I want is to get it working, may the code be brilliant or not  smiley

Code:
#include <SoftwareSerial.h>
#include <string.h>
SoftwareSerial GSM(7, 8);

char buffer[300];

boolean clear = true;

int count=0;

void setup ()
{
  GSM.begin (19200);
  Serial.begin (19200);
  delay (4000);
}

void ClearBufferArray ()
{
  for (int i=0; i<count; i++)
      buffer[i] = NULL;
}

void loop ()
{
  if (clear) {

// First delete possibly existing messages and put into text mode
// Somehow these does not work in Setup (), maybe...
   
    GSM.println ("AT+CMGD=1,4");
    clear = false; 
    Serial.println ("Existing SMSs deleted");
    delay (1000);
    GSM.println ("AT+CMGF=1");
    Serial.println ("Text mode");
  }

  if (GSM.available()) {
   
//Read data from GSM into buffer

    while (GSM.available ()) {
     
      buffer[count++] = GSM.read ();
      buffer[count] = '\0';
     
// Avoid overflow     
      if(count == 300)
        break;
    }

//New message arrives, print the message announcement
   
    if (strstr (buffer,"+CMTI:")) {
 
      Serial.println ("SMS Received");

// Send reading command to GSM     
     
      GSM.println ("AT+CMGR=1");   
    }

// Handle the message
   
    if (strstr (buffer,"+CMGR:")) {

// So far only print the new one and delete it (all)
     
      Serial.println ("Reading SMS");
      GSM.println ("AT+CMGD=1,4");
    } 
   
// If no more data, transmission ends, print the buffer

    Serial.println (buffer);           

    ClearBufferArray ();
    count = 0;
  }

  if (Serial.available ())
    GSM.write (Serial.read ());
}

And output:

Code:
Existing SMSs deleted
Text mode
AT+CMGD=1,4

OK

AT+CMGF=1

OK

SMS Received

+CMTI: "SM",1

AT+CMGR=1

Reading SMS

+CMGR: "REC UNREAD","+358405833XXX","","13/01/21,23:56:46+08"
Test

OK

AT+CMGD=1,4


OK

Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12577
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If I send a SMS "Testing", only part of it will be displayed, like in the example output below, there is only "Test". If I wrote a longer SMS, the result is not truncated but contains random letters from the SMS sent. Any ideas why?

Code:
while (GSM.available ()) {

buffer[count++] = GSM.read ();
buffer[count] = '\0';

// Avoid overflow      
if(count == 300)
break;
}
I doubt that it is causing you any problems, but for robustness you should do the overflow check before appending the received character to the buffer rather than after.

In your message handling code you assume that a complete message has been received as soon as GSM.available() returns zero, but all that really means is that the Arduino is reading characters from the serial connection faster than the GSM module is writing them. You should keep reading until you know you have received the complete response to your command. I don't know why you're seeing garbled messages but the fact you may only be reading the first few characters of each response from the GSM module could mean that the serial connection is overflowing at the sending side so perhaps that is the problem. In any case you need to sort out the serial port handling here before you look for any further problems.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

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


In your message handling code you assume that a complete message has been received as soon as GSM.available() returns zero, but all that really means is that the Arduino is reading characters from the serial connection faster than the GSM module is writing them. You should keep reading until you know you have received the complete response to your command. I don't know why you're seeing garbled messages but the fact you may only be reading the first few characters of each response from the GSM module could mean that the serial connection is overflowing at the sending side so perhaps that is the problem. In any case you need to sort out the serial port handling here before you look for any further problems.

Sounds very reasonable, but how can I be sure that the serial input is actually finished? I'm not so familiar with these. Or should I read until "\nOK" is received? I think it is in the end of the message given by AT command (if everything goes right). Adding some delay did not work and is not a good idea anyway.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12577
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds very reasonable, but how can I be sure that the serial input is actually finished? I'm not so familiar with these. Or should I read until "\nOK" is received? I think it is in the end of the message given by AT command (if everything goes right). Adding some delay did not work and is not a good idea anyway.

A delay is certainly not the way to do it, agreed.

You need to work out how to detect the end of the response. If you know that each command response is followed by "\nOK\n" then you could wait until you receive that.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

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

Sorry for bumping an old thread but Google led me here so this might help others.

You are probably overflowing the SoftwareSerial buffer which is set to 64 bytes.

You can confirm this by checking GSM.overflow() returns true

(reference http://arduino.cc/en/Reference/SoftwareSerialOverflow)

A dirty hack is to increase the SoftwareSerial buffer. Under libraries/SoftwareSerial/SoftwareSerial.h you'll find this line:

Code:
#define _SS_MAX_RX_BUFF 64 // RX buffer size

Increase it, keeping in mind the SRAM limitations on your Arduino device.

Edit:

After playing around a bit more I found the following in addition:

  • I had to change _SS_MAX_RX_BUFF directly in the SoftwareSerial.h class. Trying to #define it in my own project (either before or after the #include) resulted in failures still. I'm not sure why...printing out _SS_MAX_RX_BUFF and doing a sizeof(_receive_buffer) matched my values but it was still overflowing at 64.
  • I get corruption if I use any buffer size that isn't a power of 2. I don't know why.
  • To use a buffer size over 255 (well, 128) the variables _receive_buffer_tail and _receive_buffer_head need to be changed from uint8_t to uint16_t. I couldn't go above 128 without making that change.

Some reference info related to the two above things I found at http://arduino.cc/forum/index.php/topic,128544.msg967171.html

« Last Edit: March 27, 2013, 06:19:18 pm by DigitalDash » Logged

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

Hello,

Has someone come up with a solution with the above stated problem?

We are using Arduino Duemilanove and SIM 900 GSM module (http://robokits.co.in/shop/index.php?main_page=product_info&products_id=303)

We've tried to work on the similar problem of lightning Leds from port 9-12 when we send an sms #aibicidi, where i = 0 or 1, 0 =off, 1=on.
Eg. #a1b1c1d1 will switch on all the Led's.

When we upload the code and run it through serial monitor and enter the #a1b1c1d1 in the serial monitor, we can see all the led's lighten up.  But if we send the sms with having content "#a1b1c1d1", we dont see any function of leds.

It would be great if anyone can give some guidance about the same.


Code:


 char inchar; //Will hold the incoming character from the Serial Port.


 int led1 = 9;
 int led2 = 10;
 int led3 = 11;
 int led4 = 12;

 void setup()
 {
 // prepare the digital output pins
 pinMode(led1, OUTPUT);
 pinMode(led2, OUTPUT);
 pinMode(led3, OUTPUT);
 pinMode(led4, OUTPUT);
 digitalWrite(led1, LOW);
 digitalWrite(led2, LOW);
 digitalWrite(led3, LOW);
 digitalWrite(led4, LOW);
 //Initialize GSM module serial port for communication.
 
 
 Serial.begin(9600);
 delay(3000); // give time for GSM module to register on network etc.
 Serial.println("AT+CMGF=1"); // set SMS mode to text
 delay(200);
 Serial.println("AT+CNMI=3,3,0,0"); // set module to send SMS data to serial out upon receipt
 delay(200);
 }

 void loop()
 {
 //If #a1b1c1d1 comes as sms, all led's should light up.
 if(Serial.available() >0)
 {
 inchar=Serial.read();
 if (inchar=='#')
   {
   delay(10);
   inchar=Serial.read();
   
 //first led
   if (inchar=='a')
     {
   delay(10);
   inchar=Serial.read();
   
 if (inchar=='0')
   {
   digitalWrite(led1, LOW);
   }
 else if (inchar=='1')
   {
   digitalWrite(led1, HIGH);
   }
 delay(10);

 
 //Second led
 inchar=Serial.read();
 
 if (inchar=='b')
   {
   inchar=Serial.read();
 if (inchar=='0')
 {
 digitalWrite(led2, LOW);
 }
 
 else if (inchar=='1')
 {
 digitalWrite(led2, HIGH);
 }
 delay(10);
 
 // Third led
 inchar=Serial.read();
 if (inchar=='c')
 {
 inchar=Serial.read();
 if (inchar=='0')
 {
 digitalWrite(led3, LOW);
 }
 else if (inchar=='1')
 {
 digitalWrite(led3, HIGH);
 }
 delay(10);
 
 //Fourth led
 
 inchar=Serial.read();
 if (inchar=='d')
 {
 delay(10);
 inchar=Serial.read();
 if (inchar=='0')
 {
 digitalWrite(led4, LOW);
 }
 else if (inchar=='1')
 {
 digitalWrite(led4, HIGH);
 }
 delay(10);
 }
 }
 Serial.println("AT+CMGD=1,4"); // delete all SMS
 }
 }
 }
 }
 }
Logged

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

We were able to lighten up the LED with an sms.

Keeping the code below. This code will lighten 9 leds which are kept from port 4 to 12. The sms code is "0#iii#iii#iii, where i =0 or 1 meaning off or on respectively. Ex. 0#111#111#111 will switch on all the leds.

The modification was AT+CNMI=2,2,0,0,0 instead of AT+CNMI=3,3,0,0 from our previous code.

Code:
char inchar; //Will hold the incoming character from the Serial Port.


 int led1 = 4;
 int led2 = 5;
 int led3 = 6;
 int led4 = 7;
 int led5 = 8;
 int led6 = 9;
 int led7 = 10;
 int led8 = 11;
 int led9 = 12;

 void setup()
 {
 // prepare the digital output pins
 pinMode(led1, OUTPUT);
 pinMode(led2, OUTPUT);
 pinMode(led3, OUTPUT);
 pinMode(led4, OUTPUT);
 pinMode(led5, OUTPUT);
 pinMode(led6, OUTPUT);
 pinMode(led7, OUTPUT);
 pinMode(led8, OUTPUT);
 pinMode(led9, OUTPUT);
 
 
 // initially all are off
 digitalWrite(led1, LOW);
 digitalWrite(led2, LOW);
 digitalWrite(led3, LOW);
 digitalWrite(led4, LOW);
 digitalWrite(led5, LOW);
 digitalWrite(led6, LOW);
 digitalWrite(led7, LOW);
 digitalWrite(led8, LOW);
 digitalWrite(led9, LOW);
 
 
 
 
 //Initialize GSM module serial port for communication.
 Serial.begin(9600);
 delay(3000); // give time for GSM module to register on network etc.
 Serial.println("AT+CMGF=1\r"); // set SMS mode to text
 delay(200);
 Serial.println("AT+CSMS=1\r");
 delay(200);
 
// Serial.println("AT+CNMI=3,3,0,0"); // set module to send SMS data to serial out upon receipt
 Serial.println("AT+CNMI=2,2,0,0,0"); // set module to send SMS data to serial out upon receipt

 delay(200);
 }

 void loop()
 {
 //If a character comes in from the Serialular module...

 if(Serial.available() >0)
 { 

 delay(10);
 inchar=Serial.read();
 if (inchar=='0')   // to catch the 1st 0 in our string 0#101#101#101
 {     
       // digitalWrite(13, HIGH);
       // for #101________________
       inchar=Serial.read(); // read next char i.e '#'
       if (inchar=='#')
       {
             inchar=Serial.read(); //read next char i.e 1
             if (inchar=='0')
             {
                 digitalWrite(led1, LOW);
             }
             else if (inchar=='1')
             {
                 digitalWrite(led1, HIGH);
             }
             
             
       delay(10);
             inchar=Serial.read(); //read next char i.e 0
             if (inchar=='0')
             {
                 digitalWrite(led2, LOW);
             }
             else if (inchar=='1')
             {
                 digitalWrite(led2, HIGH);
             }
             
       delay(10);
             inchar=Serial.read(); //read next char i.e 1
             if (inchar=='0')
             {
                 digitalWrite(led3, LOW);
             }
             else if (inchar=='1')
             {
                 digitalWrite(led3, HIGH);
             }     
       } //end of  1st 'if char==#' loop
       
       
       
       
       //for _____  #101  _______
       inchar=Serial.read(); // read next char i.e '#'
       if (inchar=='#')
       {
             inchar=Serial.read(); //read next char i.e 1
             if (inchar=='0')
             {
                 digitalWrite(led4, LOW);
             }
             else if (inchar=='1')
             {
                 digitalWrite(led4, HIGH);
             }
             
             
       delay(10);
             inchar=Serial.read(); //read next char i.e 0
             if (inchar=='0')
             {
                 digitalWrite(led5, LOW);
             }
             else if (inchar=='1')
             {
                 digitalWrite(led5, HIGH);
             }
             
       delay(10);
             inchar=Serial.read(); //read next char i.e 1
             if (inchar=='0')
             {
                 digitalWrite(led6, LOW);
             }
             else if (inchar=='1')
             {
                 digitalWrite(led6, HIGH);
             }     
       } //end of 2nd 'if char==#' loop
       
       
       
       
       //for _____ _____ #101
       inchar=Serial.read(); // read next char i.e '#'
       if (inchar=='#')
       {
             inchar=Serial.read(); //read next char i.e 1
             if (inchar=='0')
             {
                 digitalWrite(led7, LOW);
             }
             else if (inchar=='1')
             {
                 digitalWrite(led7, HIGH);
             }
             
             
       delay(10);
             inchar=Serial.read(); //read next char i.e 0
             if (inchar=='0')
             {
                 digitalWrite(led8, LOW);
             }
             else if (inchar=='1')
             {
                 digitalWrite(led8, HIGH);
             }
             
       delay(10);
             inchar=Serial.read(); //read next char i.e 1
             if (inchar=='0')
             {
                 digitalWrite(led9, LOW);
             }
             else if (inchar=='1')
             {
                 digitalWrite(led9, HIGH);
             }     
       } //end of 3rd 'if char==#' loop
       
       
       
 } // "ckeck 0 in front of string" wala loop close

 //Serial.println("AT+CMGD=1,4"); // delete all SMS
 
 } // serial available condition close
 
 
//   Serial.println("AT+CMGR=1\r");
//   delay(4000);
 } // LOOP function close
Logged

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

hello i am doing the same thing tried to use the above code but it is not working

i can control the led pin 13 using serial consol by sending 0#1 and can make off by 0#0  but when i am sending the message 0#1 the led is not glowing here is my code
can anybody tell me what is the problem??
Code:
char inchar; //Will hold the incoming character from the Serial Port.


 int led1 = 13;
void setup()
 {
 // prepare the digital output pins
 pinMode(led1, OUTPUT);

 // initially all are off
 digitalWrite(led1, LOW);
//Initialize GSM module serial port for communication.
 Serial.begin(9600);
 delay(3000); // give time for GSM module to register on network etc.
 Serial.println("AT+CMGF=1\r"); // set SMS mode to text
 delay(200);
 Serial.println("AT+CSMS=1\r");
 delay(200);
 
//Serial.println("AT+CNMI=3,3,0,0"); // set module to send SMS data to serial out upon receipt
 Serial.println("AT+CNMI=2,2,0,0,0"); // set module to send SMS data to serial out upon receipt
//Serial.println("AT+CSMP=17,167,0,0");
 delay(200);
 }
void loop()
 {
 //If a character comes in from the Serialular module...
if(Serial.available() >0)
 { 

 delay(10);
 inchar=Serial.read();
 if (inchar=='0')   // to catch the 1st 0 in our string 0#101#101#101
 {     
      // digitalWrite(led1, HIGH);
       // for #101________________
       inchar=Serial.read(); // read next char i.e '#'
       if (inchar=='#')
       {
             inchar=Serial.read(); //read next char i.e 1
             if (inchar=='0')
             {
                 digitalWrite(led1, LOW);
             }
             else if (inchar=='1')
             {
                 digitalWrite(led1, HIGH);
             }
                  } //end of 3rd 'if char==#' loop
       
       } // "ckeck 0 in front of string" wala loop close

 //Serial.println("AT+CMGD=1,4"); // delete all SMS
  } // serial available condition close
 
 //   Serial.println("AT+CMGR=1\r");
//   delay(4000);
 } // LOOP function close
Logged

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

Hi,

The code was working properly in my case of Arduino Duemilanove and SIM 900 gsm module.  Which one are you using?

Your can verify the below points.
1. See that you close the serial console, when you are messaging to the gsm module.  The arduino should be connected to the laptop only for power supply.

2. See that you connection properly Rx of arduino to Tx of gsm, Tx of arduino to Rx of gsm. Connect both the ground together and DONT connect the Vin of arduino and gsm module together, otherwise there are high chances of damaging the arduino as gsm module is using lot of power to send/receive messages.

I will look try to run your code on my arduino and let you know its outcome.  But keep on trying...
Logged

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

hi

thanks for the instant reply

i am using  arduino freeduino(ATMEGA 328) and  sim 900(which i bought from rhydolabs)


i am using pin2 as rx and pin3 as tx is it correct????

here are my connections

Rx of arduino(pin no-2)to Tx of gsm sim900
Tx of arduino(pin no-3)to Rx of gsm sim900
Vinterface  of sim900   to 3.3v of arduino  
i am using USB cable for arduino supply so i don't require any external power supply
i am using  arduino 5v supply for powering up the sim900
i have also connected ground together

 but unfortunately stilll didnt work????????? smiley-confuse

have you tried this code in your laptop??

thanks again for your intrest in my post

« Last Edit: April 22, 2013, 04:10:57 am by dhruvit » Logged

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

Ok,

According to this image of freeduino: http://www.freeduino.org/images/freeduino_serial2.jpg
The Rx is pin 0(the first pin from right on digital side) and Tx is pin 1(second pin from right) on the digital side.

The GSM module will require another power supply from an adapter of 12Vdc , 2amps (you need to buy on).  The power supply from USB is not enough to power the GSM module.  Once you give the power supply to GSM module, DONT connect the Vinterface of sim900 to 3.3v of arduino (as the arduino may get damaged).  The power supply from USB is enough for arduino.

So now you have only three connection, Rx, Tx and ground.  I will try your code in the coming days.  It should work.

P.S.:
The gsm module from rhydolabs
eg. http://www.rhydolabz.com/index.php?main_page=product_info&cPath=122&products_id=1088
tells that it would require input voltage of 12V.  Confirm yours.
Logged

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

ok
thanks but  my GSM module is this

http://www.rhydolabz.com/index.php?main_page=product_info&products_id=1080

and my freeduino is this
http://www.embeddedmarket.com/products/Arduino-Compatible-Freeduino-DU/

it can work on 5v and it is working well  for me  as i can send ths sms and also can recive them by above connections
which i have mentioned in my earlier post

i am keep trying......... and also waiting for your reply



« Last Edit: April 22, 2013, 09:21:40 am by dhruvit » Logged

Pages: 1 2 3 [4] 5   Go Up
Jump to: