Good day, I have a GSM module and a GPS module… I found and tested the code for each one successfully… now i need to put them both together… what i need is 1) take an initial reading from GPS and save it 2) keep reading from GPS untill getting new latitude > old latitude +10 OR new logitude > old longitude +10… 3) if this happens I need to send an SMS using GSM…
Here is the code for GPS:
#include <string.h>
#include <ctype.h>
int ledPin = 13; // LED test pin
int rxPin = 0; // RX PIN
int txPin = 1; // TX TX
int byteGPS=-1;
char linea[300] = "";
char comandoGPR[7] = "$GPRMC";
int cont=0;
int bien=0;
int conta=0;
int indices[13];
void setup() {
pinMode(ledPin, OUTPUT); // Initialize LED pin
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
Serial.begin(9600);
for (int i=0;i<300;i++){ // Initialize a buffer for received data
linea[i]=' ';
}
}
void loop() {
digitalWrite(ledPin, HIGH);
byteGPS=Serial.read(); // Read a byte of the serial port
if (byteGPS == -1) { // See if the port is empty yet
delay(100);
} else {
linea[conta]=byteGPS; // If there is serial port data, it is put in the buffer
conta++;
//Serial.print(byteGPS, BYTE);
if (byteGPS==13){ // If the received byte is = to 13, end of transmission
digitalWrite(ledPin, LOW);
cont=0;
bien=0;
for (int i=1;i<7;i++){ // Verifies if the received command starts with $GPR
if (linea[i]==comandoGPR[i-1]){
bien++;
}
}
if(bien==6){ // If yes, continue and process the data
for (int i=0;i<300;i++){
if (linea[i]==','){ // check for the position of the "," separator
indices[cont]=i;
cont++;
}
if (linea[i]=='*'){ // ... and the "*"
indices[12]=i;
cont++;
}
}
Serial.println(""); // ... and write to the serial port
Serial.println("");
Serial.println("---------------");
for (int i=2;i<5;i+=2){
switch(i){
case 2 :Serial.print("Latitude: ");break;
case 4 :Serial.print("Longitude: ");break;
}
for (int j=indices[i];j<(indices[i+1]-1);j++){
Serial.print(linea[j+1]);
}
Serial.println("");
}
Serial.println("---------------");
}
conta=0; // Reset the buffer
for (int i=0;i<300;i++){ //
linea[i]=' ';
}
}
}
}
Here Is the code for GSM
#include <NewSoftSerial.h>
NewSoftSerial cell(2,3); // We need to create a serial port on D2/D3 to talk to the GSM module
char mobile[xxxxxxxxxx] = "xxxxxxxx"; // Replace xxxxxxxx with the recipient's mobile number
void setup()
{ //Initialize serial ports for communication.
cell.begin(9600);
delay(35000); // give the GSM module time to initialise, locate network etc.
// this delay time varies. Use example 26.1 sketch to measure the amount
// of time from board reset to SIND: 4, then add five seconds just in case
}
void loop()
{
cell.println("AT+CMGF=1"); // set SMS mode to text
cell.print("AT+CMGS="); // now send message...
cell.print(34,BYTE); // ASCII equivalent of "
cell.print(mobilenumber);
cell.println(34,BYTE); // ASCII equivalent of "
delay(500); // give the module some thinking time
cell.print("Arduino"); // our message to send
cell.println(26,BYTE); // ASCII equivalent of Ctrl-Z
delay(15000); // the SMS module needs time to return to OK status
do //to send 1 msg only
{
delay(1);
}
while (1>0);
}