Hello.
I'm new here.
I want to make a project like that,
In an emergency situation, I pressed a push button so that my current location will be sent to my emergency number. For this project I use
- Arduino Uno R3
- GSM: Sim 800l
- GPS: Neo-6m
I individually successfully run this as like first I push the button so messaged sent to the number and secondly, I can see my GPS location on the serial monitor. But I can't do this together. so can someone help me, please?
Gsm code :
#include <SoftwareSerial.h> //Create software serial object to communicate with SIM800L
SoftwareSerial GSM(8, 9); //SIM800L Tx & Rx is connected to Arduino #8 & #9
char phone_no[]="+8801703139601"; //change +92 with country code and 3378655465 with phone number to sms
#define bt_M A0 // Button1 Pin A0 use for Send Message
#define bt_C A1 // Button2 Pin A1 use for Call
#define LED 2 // Led Pin D2 use for LED
char inchar; // Will hold the incoming character from the GSM shield
void setup(){// put your setup code here, to run once
Serial.begin(9600);//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
GSM.begin(9600); //Begin serial communication with Arduino and SIM800L
pinMode(bt_M, INPUT_PULLUP); // declare bt_M as input
pinMode(bt_C, INPUT_PULLUP); // declare bt_C as input
pinMode(LED,OUTPUT); // declare LED as output
Serial.println("Initializing....");
initModule("AT","OK",1000); //Once the handshake test is successful, it will back to OK
initModule("ATE1","OK",1000); //this command is used for enabling echo
initModule("AT+CPIN?","READY",1000); //this command is used to check whether SIM card is inserted in GSM Module or not
initModule("AT+CMGF=1","OK",1000); //Configuring TEXT mode
initModule("AT+CNMI=2,2,0,0,0","OK",1000); //Decides how newly arrived SMS messages should be handled
Serial.println("Initialized Successfully");
}
void loop(){
if(GSM.available() >0){inchar=GSM.read(); Serial.print(inchar);
if(inchar=='R'){inchar=GSM.read();
if(inchar=='I'){inchar=GSM.read();
if(inchar=='N'){inchar=GSM.read();
if(inchar=='G'){
initModule("ATH","OK",1000); // this command is used for Call busy
}
}
}
}
else if(inchar=='L'){delay(10); inchar=GSM.read();
if(inchar=='E'){delay(10); inchar=GSM.read();
if(inchar=='D'){delay(10); inchar=GSM.read();
if(inchar=='1'){digitalWrite(LED, 1); sendSMS(phone_no,"LED is On");}
else if(inchar=='0'){digitalWrite(LED, 0); sendSMS(phone_no,"LED is Off");}
}
}
}
}
if(digitalRead (bt_M) == 0){sendSMS(phone_no,"Help me I'm in Danger . ");}
if(digitalRead (bt_C) == 0){callUp(phone_no);}
delay(5);
}
void sendSMS(char *number, char *msg){
GSM.print("AT+CMGS=\"");GSM.print(number);GSM.println("\"\r\n"); //AT+CMGS=”Mobile Number” <ENTER> - Assigning recipient’s mobile number
delay(500);
GSM.println(msg); // Message contents
delay(500);
GSM.write(byte(26)); //Ctrl+Z send message command (26 in decimal).
delay(3000);
}
void callUp(char *number){
GSM.print("ATD + "); GSM.print(number); GSM.println(";"); //Call to the specific number, ends with semi-colon,replace X with mobile number
delay(20000); // wait for 20 seconds...
GSM.println("ATH"); //hang up
delay(100);
}
void initModule(String cmd, char *res, int t){
while(1){
Serial.println(cmd);
GSM.println(cmd);
delay(100);
while(GSM.available()>0){
if(GSM.find(res)){
Serial.println(res);
delay(t);
return;
}else{Serial.println("Error");}}
delay(t);
}
}
GPS code :
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
static const int RXPin = 4, TXPin = 5;// Here we make pin 4 as RX of arduino & pin 3 as TX of arduino
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);
void setup()
{
Serial.begin(9600);
ss.begin(GPSBaud);
}
void loop()
{
while (ss.available() > 0)
if (gps.encode(ss.read()))
displayInfo();
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
while(true);
}
}
void displayInfo()
{
Serial.print(F("Location: "));
if (gps.location.isValid())
{
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(F(" Date "));
if (gps.date.isValid())
{
Serial.print(gps.date.month());
Serial.print(F("/"));
Serial.print(gps.date.day());
Serial.print(F("/"));
Serial.print(gps.date.year());
}
else
{
Serial.print(F("INVALID"));
}
Serial.println();
}