GPS /GSM Tracker
DESC:
With this program, Arduino waits for a phone call and send a SMS with the GPS coordinates.
Disclaimer: This is my first working version, testing was ok, but i don`t make responsible of unwanted SMS sends, use for security always a pre-paid mode sim card. Use the code under your own responsability.
PICS:
CODE:
#include <nmea.h>
#include <NewSoftSerial.h>
#include <LCD4Bit.h>
#include<stdlib.h>
NMEA gps(GPRMC);
LCD4Bit lcd = LCD4Bit(4);
int luzfondo = 13 ;
char cadena [500] ;
float valor ;
float valor2 ;
int pos ;
char buf[12];
char buf2[12];
char buf3[9];
int i ;
int notificaciones;
NewSoftSerial GPS(5,6);
NewSoftSerial modem(3,4);
int esperatono ;
void setup(){
lcd.init();
pinMode(luzfondo, OUTPUT);
modem.begin (9600);
digitalWrite(luzfondo, HIGH);
GPS.begin (4800);
delay (2000);
if (GPS.available() > 0 ) {
char c = GPS.read();
lcd.printIn("GPS PREPARADO");
delay (1000);}
modem.println ("AT+CPIN=M I P I N");
lcd.clear();
lcd.cursorTo(2, 0);
lcd.printIn("INICIALIZANDO MODEM");
delay (3000);
esperatono = 1 ;
lcd.clear();
}
void loop(){
if (esperatono == 1) {
modem.flush();
lcd.clear();
lcd.cursorTo(3, 0);
lcd.printIn("ESPERANDO TONO");
cadena [0] = '\0' ;
i = 0;
do {
if (modem.available () ){
cadena [i] = (char (modem.read())) ;
i++;
}
} while ( !strstr (cadena, "RING" ));
cadena [i] = '\0' ;
modem.flush();
lcd.cursorTo(4, 0);
lcd.printIn("TONO RECIBIDO");
delay (3000);
lcd.clear();
esperatono = 0;
pos = 0 ;
}
if (GPS.available() > 0 ) {
// read incoming character from GPS
char c = GPS.read();
// check if the character completes a valid GPS sentence
if (gps.decode(c)) {
if (gps.gprmc_status() == 'A') {
pos = pos + 1;
lcd.clear () ;
}
//dtostrf(FLOAT,WIDTH,PRECSISION,BUFFER);
valor = 0;
valor2 = 0;
valor = gps.gprmc_latitude() ;
valor2 = gps.gprmc_longitude() ;
lcd.cursorTo (1,0);
lcd.printIn ("Lat: ");
dtostrf(valor, 3, 6, buf);
lcd.printIn(buf);
lcd.cursorTo (2,0);
lcd.printIn ("Lon: ");
dtostrf(valor2, 3, 6, buf2);
lcd.printIn(buf2);
lcd.cursorTo (3,0);
lcd.printIn ("Pos# ");
itoa (pos, buf3, 10);
lcd.printIn (buf3);
if (pos == 20) {
pos = 0 ;
MandaSMS();
notificaciones = notificaciones + 1 ;
esperatono = 1 ;
}
}
}
}
void MandaSMS () {
modem.println ("AT+CMGF=1");
delay (1000);
modem.println("AT+CMGS=+34M I N U M E R O D E M O V I L");
delay (2000);
modem.print("longitud: ") ;
modem.print(buf);
modem.print(" latitud: ");
modem.print(buf2);
modem.println(26,BYTE); // Escibe el Ctrl+Z
lcd.clear();
lcd.printIn("SMS");
lcd.cursorTo(2, 0);
lcd.printIn("ENVIADO");
modem.flush();
delay (60000);
if (notificaciones >= 10) {
lcd.clear();
while(true){
lcd.cursorTo(1, 0);
lcd.printIn("DETENIENDO PROGRAMA");
lcd.cursorTo(2, 0);
lcd.printIn("DEMASIADOS SMS");
delay(1000);}}
}