GPS+GSM+Arduino communication discussion.

Hello,

I am doing a project based on GSM+GPS+ARDUINO. I have to make communications in between them. I have divided the big project into several small parts & finally I will add them to make the final project.

Right now I am trying to make communication between Arduino & sim300.
Step 1. Arduino > SIM300
Step 2. SIM300 > Arduino

Step1 is successfully done. I can send sms by controlling the Arduino input pins as switch. Now I want to send instruction to arduino via SIM300 modem. Suppose If I send a text “ON” to SIM300 an LED will glow & If I send a text “OFF” to SIM300 the LED will be off.

current progress (Step1)

#include <SoftwareSerial.h>
SoftwareSerial mySerial(9,10);
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;    
int buttonState = 0;    
void setup()
{
mySerial.begin(9600); // the GPRS baud rate
delay(2000);
mySerial.println("AT");
delay(2000);
mySerial.println("AT+CSMP=17,167,0,0");
delay(2000);
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);   

}
void loop()
{
    // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {  
  digitalWrite(ledPin, HIGH); 
  delay(1000);
mySerial.println("AT+CMGF=1"); // set the SMS mode to text
delay(2500);
mySerial.write("AT+CMGS=");
mySerial.write(34); //ASCII of “
mySerial.write("+919681108468");
mySerial.write(34);
mySerial.write(13);
mySerial.write(10);
delay(2500);
mySerial.println("Yahoo, You are Successful...!"); //this is the message to be sent
delay(2500);
mySerial.write(26);
mySerial.write(13);
mySerial.write(10);//Ascii code of ctrl+z to send the message
delay(2500);
}

  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
}

Need help for the “Step2”. I want to control the arduino output via my sim300 modem. Kindly show me the way.

Thanks

maybe it better to do a conversion with number and the do something evaluating whAt it is number inside sns message

regards
andrea

My apologies, I cannot get it. Will you kindly suggest me any hint, clue or link of such example pages please. I tried google but all I get was the "STEP1"
:-/

You need to read from gsmSerial. In this forum you will find many more-or-less-successful attempts to make what you want. Even when unsuccessful they may be instructive. The basic steps are:

  1. connect to the modem (already done);
  2. send the AT command that asks to read the SMSs in the phone's memory (check your AT command reference);
  3. process the response (similar to what you send: a phone number followed by a message, plus date and time).

Step 3 will be the most difficult part: you will be receiving the response one character at at time, so you'll have to store what you read in a buffer (a char array); data reception will be (relatively) slow, so you'll have to wait for more characters to come. Look for examples of how to read correctly from a serial line. Or go straight to Nick Gammon's forum post on this topic, here: Gammon Forum : Electronics : Microprocessors : How to process incoming serial data without blocking.

Finally, note that the modem won't notify the Arduino when a new message arrives. It is the Arduino's responsibility to poll the modem in order to know whether there are messages to be read.

Thanks a million times sir for sharing the information. I will try the gsm serial communication & update my progress here. Thanks , thanks a lot.

Thanks for the links mate. I am now slowly reaching to my project destination. (Arduino > SIM300) & (Sim300>Arduino) parts are done. Now I will connect the GPS (Tx,Rx,GND) via software serial to arduino because I have already connected SIM300 with thr hardware serial pins.

Now I want to parse the LAT & LONG from the GPS & send it via sms to my cellphone (GPS>Arduino>SIM300>my cell phone). Any clue for doing that…? I guess I have to separate the GPS data string & store it in a buffer & then send the LAT-LONG string via sms. I am having trouble to do the string “separation-store-send” part. Any clue how to do that.? I am using two serial communication device with my arduino…

My current progress till now… I hope these codes will be helpful to someone who is also trying to accomplish similar projects. I have tested the codes with hardware & they are working perfectly.

Arduino>Sim300 (SMS)

#include <SoftwareSerial.h>
SoftwareSerial mySerial(9,10);
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;    
int buttonState = 0;    
void setup()
{
mySerial.begin(9600); // the GPRS baud rate
delay(2000);
mySerial.println("AT");
delay(2000);
mySerial.println("AT+CSMP=17,167,0,0");
delay(2000);
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);   

}
void loop()
{
    // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {  
  digitalWrite(ledPin, HIGH); 
  delay(100);
mySerial.println("AT+CMGF=1"); // set the SMS mode to text
delay(2500);
mySerial.write("AT+CMGS=");
mySerial.write(34); //ASCII of “
mySerial.write("+1234567890");
mySerial.write(34);
mySerial.write(13);
mySerial.write(10);
delay(2500);
mySerial.println("Yahoo, You are Successful...!"); //this is the message to be sent
delay(2500);
mySerial.write(26);
mySerial.write(13);
mySerial.write(10);//Ascii code of ctrl+z to send the message
}

  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
}

Arduino>sim300 (CALL)

#include <SoftwareSerial.h>
SoftwareSerial mySerial(9,10);
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;    
int buttonState = 0;    
void setup()
{
mySerial.begin(9600); // the GPRS baud rate
delay(2000);
mySerial.println("AT");
delay(2000);

  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);   

}
void loop()
{
    // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {  
  digitalWrite(ledPin, HIGH); 
  delay(1000);
mySerial.write("ATD +1234567890;");
mySerial.write(13);
mySerial.write(10);
}

  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
}

Sim300>Arduino (Relay control)

#include <SoftwareSerial.h>
 

// EN: String buffer for the GPRS shield message
String msg = String("");
// EN: Set to 1 when the next GPRS shield message will contains the SMS message
int SmsContentFlag = 0;
//control pins of relay.
int relay_a=4;
int relay_b=5;
int relay_c=6;
int relay_d=7;

// EN: Code PIN of the SIM card (if applied)
//String SIM_PIN_CODE = String( "XXXX" );
 
void setup()
{
  Serial.begin(9600);                 // the GPRS baud rate
  // Initialize  PINs
  pinMode( 4, OUTPUT ); 
  pinMode( 5, OUTPUT ); 
  pinMode( 6, OUTPUT ); 
  pinMode( 7, OUTPUT ); 
  digitalWrite( 4, LOW ); 
  digitalWrite( 5, LOW ); 
  digitalWrite( 6, LOW );
  digitalWrite( 7, LOW );
 Serial.println( "AT+CMGF=1" ); 
 delay(200);
}
 
void loop()
{
    char SerialInByte;
    if(Serial.available())
    {       
        SerialInByte = (unsigned char)Serial.read();
       delay(5);
        
        // -------------------------------------------------------------------
        // EN: Program also listen to the GPRS shield message.
        // -------------------------------------------------------------------
       // EN: If the message ends with <CR> then process the message
        if( SerialInByte == 13 ){
          // EN: Store the char into the message buffer
          ProcessGprsMsg();
         }
         if( SerialInByte == 10 ){
            // EN: Skip Line feed
         }
         else {
           // EN: store the current character in the message string buffer
           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.
void ProcessSms( String sms ){
  
  if( sms.indexOf("ona") >= 0 ){
    digitalWrite( relay_a, HIGH );
  }
   if( sms.indexOf("onb") >= 0 ){
    digitalWrite(  relay_b, HIGH );
  }
   if( sms.indexOf("onc") >= 0 ){
    digitalWrite(  relay_c, HIGH );
  }
  if( sms.indexOf("ond") >= 0 ){
    digitalWrite(  relay_d, HIGH );
  }
  if( sms.indexOf("offa") >= 0 ){
    digitalWrite(  relay_a, LOW );
  }
  if( sms.indexOf("offb") >= 0 ){
    digitalWrite(  relay_b, LOW );
  }
  if( sms.indexOf("offc") >= 0 ){
    digitalWrite(  relay_c, LOW );
  }
  if( sms.indexOf("offd") >= 0 ){
    digitalWrite(  relay_d, LOW );
  }
}
// EN: Request Text Mode for SMS messaging
void GprsTextModeSMS(){
  Serial.println( "AT+CMGF=1" );
}

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

// EN: Clear the GPRS shield message buffer
void ClearGprsMsg(){
  msg = "";
}

// EN: interpret the GPRS shield message and act appropiately
void ProcessGprsMsg() {
  if( msg.indexOf( "Call Ready" ) >= 0 ){
   //  Serial.println( "*** GPRS Shield registered on Mobile Network ***" );
     GprsTextModeSMS();
  }
  
  // EN: unsolicited message received when getting a SMS message
  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
     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
     GprsReadSmsStore( SmsStorePos );
  }
  
  // EN: SMS store readed through UART (result of GprsReadSmsStore request)  
  if( msg.indexOf( "+CMGR:" ) >= 0 ){
    // EN: Next message will contains the BODY of SMS
    SmsContentFlag = 1;
    // EN: Following lines are essentiel to not clear the flag!
    ClearGprsMsg();
    return;
  }
  
  // EN: +CMGR message just before indicate that the following GRPS Shield message 
  //     (this message) will contains the SMS body 
  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
  SmsContentFlag = 0; 
}

Kindly help me with the GPS data string send techniques via sms…

Now I want to parse the LAT & LONG from the GPS & send it via sms to my cellphone (GPS>Arduino>SIM300>my cell phone). Any clue for doing that..?

For doing which part?

The TinyGPS library bears looking at. It will handle collecting the GPS data and parsing it to extract meaningful data for lat and lon.

The GPS data will be used in the "Arduino>SIM300" example. If The Button pin reads HIGH, then Arduino will collect the GPS data & separate the LAT & LONG value & inject it in a SMS that I will receive in my cell phone. This is the next part of the project. how to do this...? Any clue??? at least examples.! tried googling. There are very few of them & most of them are using specific GSM & GPS shield. I dont have shields, I have naked tx, rx & GND pins for both my GPS& GSM modem. Kindly help.

any clue?

If The Button pin reads HIGH, then Arduino will collect the GPS data & separate the LAT & LONG value & inject it in a SMS that I will receive in my cell phone. This is the next part of the project. how to do this...? Any clue???

Hi. I want to bake a wedding cake for 400 people, and deliver to the church on time, frosted and ready to heat. How do I do this?

You have no idea whether my problem is a lack of recipe, a lack if ingredients, a lack of an oven, a lack of a delivery mechanism, no idea where the church is, a lack of frosting skills, or some other problem.

What part of what you need to do are you having issues with?

  1. Can you read the switch pin?
  2. Can you determine if the value is HIGH?
  3. Can you collect the GPS data?
  4. Can you use TinyGPS to collect and parse the data?
  5. Can you use the appropriate function to get the LAT and LON values?
  6. Can you use sprintf() to construct the message to send?
  7. Can you send any SMS now?

Which number are you stuck at?

Sorry for the late reply. Actually I was busy doing the Arduino+GMS communication part. Since the Arduino+GSM communication part is completed more or less, my next step is to communicate Arduino+GPS.

I have this GPS module. ( http://robokits.co.in/shop/index.php?main_page=product_info&cPath=69&products_id=289 )
It comes with a USB port, any clue how to use it with Arduino??? because it does not have Tx & Rx pin-outs for pin to pin connection?

It comes with a USB port, any clue how to use it with Arduino?

That device is a USB slave. The Arduino is a USB slave. Without a USB Master (also known as a USB Host) around, the slaves sit around all ay drinking beer, doing nothing.

You'll need a USB Host shield and a lot of programming.

I'd suggest getting a GPS shield instead of a USB slave device.

Get your GPS module and carefully unsolder the two green circuit boards apart.

The one with the square thing looks like a standard GPS module, which outputs serial data.

The one with the USB plug is a serial-to-USB converted. You don't need it. Cut it off and chuck it away.

You will then have 4 or maybe 5 pins on the GPS module. These will be for power, ground, RX, TX and maybe an interrupt pin.

You can connect these pins to the arduino.

Thanks for the idea… Will it be a problem if there is no interrupt pin out of the GPS device…? Are you talking about the Enable pin (Pin 2) of the Device…? I shall be obliged if you kindly go though the attached document, Page no.8 .

Thanks for all your support.

Robokits_GPS_02.pdf (672 KB)

That document describes the GPS chip and its ten contacts. Not all of those contacts are connected to the USB module. The only important ones are the Vcc, the ground, the Tx and the Rx.

Various GPS modules have other connections for enable, fix ready, 1 second pulse, sleep mode, but these are all inessential.

When you separate the two modules, at least one of them will probably be labelled with the 4 important connections. Otherwise, you can determine which ones are connected to the ten connectors on the side of the chip itself, the order of which is labelled in your document.