Hi I am new to arduino and new to this forum I have been following comments about a similar post for my project but that has closed and I can't reply there anymore. Anyways I am trying to get location, speed through neo6m and if it exceeds a certain limit I want the gsm module to send a message containing speed, latitude and longitude. I have a written a code an will be sharing that as well. I can't seem to get it work. please help in areas of the code which you think are wrong.
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <AltSoftSerial.h>
#define RX1 7
#define TX1 8
#define RX2 9
#define TX2 10
double Latitude, Longitude, Altitude, speed;
TinyGPSPlus gps;
SoftwareSerial gpsPort(RX1, TX1);
AltSoftSerial gsmPort(RX2, TX2);
void setup() {
gsmPort.begin(9600);
Serial.begin(9600);
gpsPort.begin(9600);
delay(100);
}
void loop() {
while (gpsPort.available() > 0) {
if (gps.encode(gpsPort.read()))
getGPSdata();
}
if (Serial.available() > 0)
switch (Serial.read()) {
case 'SM':
SendMessage();
break;
case 'RM':
RecieveMessage();
break;
}
if (gsmPort.available() > 0) {
Serial.write(gsmPort.read());
}
}
void getGPSdata() {
if (gps.location.isValid()) {
Latitude = gps.location.lat(), 6; // Latitude in degrees (double)
Longitude = gps.location.lng(), 6; // Longitude in degrees (double)
}
if (gps.speed.isValid()) {
speed = gps.speed.mps(); // Speed in meters per second (double)
}
if (gps.altitude.isValid()) {
Altitude = gps.altitude.meters(); // Altitude in meters (double)
}
}
void SendMessage() {
gsmPort.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
gsmPort.println("AT+CMGS=\"+923111000913\"\r"); // Replace x with mobile number
delay(1000);
gsmPort.println("OverSpeeding"); // The SMS text you want to send
gsmPort.println("Speed: ");
gsmPort.println(speed, 6);
gsmPort.println("Location: ");
gsmPort.print(Latitude, 6);
gsmPort.print(',');
gsmPort.print(Longitude, 6);
delay(100);
gsmPort.println((char)26); // ASCII code of CTRL+Z
delay(1000);
}
void RecieveMessage() {
gsmPort.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
delay(1000);
}