I have a code for sending GPS coordinates in form of Google Maps link that sends every 5 seconds, I also have this code for controlling LEDs via SMS, and a code for the Motion sensor for sending SMS automatically when it is triggered. I got all of them online and I kinda revised them and I tried combining all of them but they just won't work, I didn't get any errors and the wirings are also correct. I've searched online about this but I can't seem to find anything that can help me with this issue. I'm doing an Anti-theft vehicle system that can send the GPS coordinates when the SMS sent to the GSM contains "LOCATION" on it, "RING", "STOP" and "STATE" for making the led/lights on or off and knowing it's status, and lastly automatic sending of vehicle's location when the sensor is triggered. By the way I'm just new to programming so, I really need your help.
Here's the code for the "RING", "STOP", "STATE" thing.
#include <SoftwareSerial.h>
SoftwareSerial GPRS(7, 8);
String textMessage;
String lampState = "off";
int aled = 4;
int bled = 5;
void setup() {
pinMode(aled, OUTPUT);
pinMode(bled, OUTPUT);
Serial.begin(9600);
GPRS.begin(9600);
delay(5000);
Serial.print("GPRS ready.");
GPRS.print("AT+CMGF=1\r");
delay(100);
GPRS.print("AT+CNMI=2,2,0,0,0\r");
delay(100);
}
void loop(){
if(GPRS.available()>0){
textMessage = GPRS.readString();
Serial.print(textMessage);
delay(10);
textMessage.toUpperCase();
}
if(textMessage.indexOf("RING")>=0){
digitalWrite(aled, HIGH);
digitalWrite(bled, HIGH);
lampState = "on";
Serial.println("Alarm set to ON");
textMessage = "";
}
if(textMessage.indexOf("STOP")>=0){
// Turn off relay and save current state
digitalWrite(aled, LOW);
digitalWrite(bled, LOW);
lampState = "off";
Serial.println("Alarm set to OFF");
textMessage = "";
}
if(textMessage.indexOf("STATE")>=0){
String message = "Alarm is " + lampState;
sendSMS(message);
Serial.println("Alarm state request");
textMessage = "";
}
}
void sendSMS(String message){
GPRS.print("AT+CMGF=1\r");
delay(100);
GPRS.println("AT + CMGS = \"+63*********\"");
delay(100);
GPRS.println(message);
delay(100);
GPRS.println((char)26);
delay(100);
GPRS.println();
delay(5000);
}
And here's the code for sending GPS coordinates every 5 seconds
#include <SoftwareSerial.h>
#include <TinyGPS.h>
SoftwareSerial GPS(12, 11);
SoftwareSerial GPRS(7, 8);
TinyGPS neo6m;
void setup()
{
GPRS.begin(9600);
delay(500);
GPS.begin(9600);
delay(500);
Serial.begin(9600);
}
void loop(){
while (GPS.available()) {
if (neo6m.encode(GPS.read())) {
float latitude, longitude;
neo6m.f_get_position(&latitude, &longitude);
float lat = latitude;
float lng = longitude;
String meslat = String(lat, 6);
String meslon = String(lng, 6);
String com = ",";
String link = "https://www.google.com/maps/?q=";
String txt = link + meslat + com + meslon;
Serial.println(txt);
delay(5000);
GPRS.print("\r");
delay(500);
GPRS.print("AT+CMGF=1\r");
delay(500);
GPRS.print("AT+CMGS=\"+63**********\"\r");
delay(500);
GPRS.print(txt);
delay(500);
GPRS.write(0x1A);
delay(500);
}
}
}
and the code for the Sensor sending SMS when triggered
#include <SoftwareSerial.h>
SoftwareSerial GPRS(7, 8);
boolean state, lastState;
int sw420 = 2;
void setup()
{
pinMode(sw420, INPUT_PULLUP);
state = digitalRead(sw420);
lastState = state;
GPRS.begin(9600);
Serial.begin(9600);
GPRS.println("AT+CMGF=1");
delay(1000);
}
void loop()
{
while(GPRS.available()) {
Serial.write(GPRS.read());
}
lastState = state;
state = digitalRead(sw420);
if ( state != lastState ) {
sendSMS();
}
delay(500);
}
void sendSMS() {
Serial.print("Switch was turned ");
Serial.println(state ? "on" : "off");
GPRS.println("AT+CMGS=\"+63**********\"");
delay(500);
GPRS.print("Vehicle's alarm was triggered!");
GPRS.println(state ? "on" : "off");
GPRS.write( 0x1a );
delay(500);
}
A big thanks in advance, I really need your help.