I am working on a project where i use and arduino uno(drfduino uno, i understand that is very similar) integrated with 2 modules(one is GSM --SIM800l-- and the one is GPS --GY-NEO6MV2--.
If i use them separately they are working but when they are all put together in a code, i cant listen to to the ports(software serial). I am testing the code inside so the GPS wouldnt work anyway but when i put the ss.listen() in the void loop(); the SIM800l.listen(); isnt working neither. Can you guys give me and advice pls.
#include <SoftwareSerial.h> //Software Serial header to communicate with GSM module
#include <TinyGPS++.h>
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial SIM800(11, 10); // RX, TX
SoftwareSerial ss(RXPin, TXPin);
String Link = "The current Location is https://www.google.com/maps/place/"; //we will append the Lattitude and longitude value later int the program
String responce = "";
String Longitude = "";
String Latitude = "";
String Date ="";
String Time ="";
String result2 = "";
String SIM800_send(String incoming) //Function to communicate with SIM800 module
{
SIM800.println(incoming); delay(100); //Print what is being sent to GSM module
String result = "";
while (SIM800.available()) //Wait for result
{
char letter = SIM800.read();
result = result + String(letter); //combine char to string to get result
}
return result; //return the result
}
void setup() {
//PWRKY pin of GSM module has to be pulled low for 1sec to enable the module
Serial.begin(9600); //Serial COM for debugging
ss.begin(9600);
SIM800.begin(9600); //Software serial called SIM800 to speak with SIM800 Module
delay(1000); //wait for serial COM to get ready
responce = SIM800_send("ATE1"); //Enable Echo if not enabled by default
Serial.print ("Responce:"); Serial.println(responce);
delay(1000);
responce = SIM800_send("AT+CGATT=1"); //Set the SIM800 in GPRS mode
Serial.print ("Responce:"); Serial.println(responce);
delay(1000);
responce = SIM800_send("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\" "); //Activate Bearer profile
Serial.print ("Responce:"); Serial.println(responce);
delay(1000);
responce = SIM800_send("AT+SAPBR=3,1,\"APN\",\"net\""); //Set VPN options => 'RCMNET' 'www'
Serial.print ("Responce:"); Serial.println(responce);
delay(2000);
responce = SIM800_send("AT+SAPBR=1,1"); //Open bearer Profile
Serial.print ("Responce:"); Serial.println(responce); //Open bearer Profile
delay(2000);
responce = SIM800_send("AT+SAPBR=2,1"); //Get the IP address of the bearer profile
Serial.print ("Responce:"); Serial.println(responce);
delay(1000);
}
void prepare_message()
{
//Sample Output for AT+CLBS=1,1 ==> +CIPGSMLOC: 75.802460,26.848892,550 //where 26.8488832 is Lattitude and 75.802460 is longitute
int first_comma = responce.indexOf(','); //Find the position of 1st comma
int second_comma = responce.indexOf(',', first_comma+1); //Find the position of 2nd comma
int third_comma = responce.indexOf(',', second_comma+1); //Find the position of 3rd comma
for(int i=first_comma+1; i<second_comma; i++) //Values form 1st comma to 2nd comma is Longitude
Longitude = Longitude + responce.charAt(i);
for(int i=second_comma+1; i<third_comma; i++) //Values form 2nd comma to 3rd comma is Latitude
Latitude = Latitude + responce.charAt(i);
Serial.println(Latitude); Serial.println(Longitude);
Link = Link + Latitude + "," + Longitude; //Update the Link with latitude and Logitude values
Serial.println(Link);
}
String incoming = "";
void loop() {
ss.listen();
while (ss.available() > 0)
{
gps.encode(ss.read());
if (gps.location.isUpdated())
{
// Latitude in degrees (double)
Serial.print("Latitude= ");
Serial.print(gps.location.lat(), 6);
Latitude = gps.location.lat();
// Longitude in degrees (double)
Serial.print(" Longitude= ");
Longitude = gps.location.lng();
Serial.println(gps.location.lng(), 6);
Link = Link + Latitude + "," + Longitude;
// Raw latitude in whole degrees
Serial.print("Raw latitude = ");
Serial.print(gps.location.rawLat().negative ? "-" : "+");
Serial.println(gps.location.rawLat().deg);
// ... and billionths (u16/u32)
Serial.println(gps.location.rawLat().billionths);
// Raw longitude in whole degrees
Serial.print("Raw longitude = ");
Serial.print(gps.location.rawLng().negative ? "-" : "+");
Serial.println(gps.location.rawLng().deg);
// ... and billionths (u16/u32)
Serial.println(gps.location.rawLng().billionths);
// Raw date in DDMMYY format (u32)
Serial.print("Raw date DDMMYY = ");
Serial.println(gps.date.value());
Date = gps.date.value();
// Year (2000+) (u16)
Serial.print("Year = ");
Serial.println(gps.date.year());
// Month (1-12) (u8)
Serial.print("Month = ");
Serial.println(gps.date.month());
// Day (1-31) (u8)
Serial.print("Day = ");
Serial.println(gps.date.day());
// Raw time in HHMMSSCC format (u32)
Serial.print("Raw time in HHMMSSCC = ");
Serial.println(gps.time.value());
Time = gps.time.value();
// Hour (0-23) (u8)
Serial.print("Hour = ");
Serial.println(gps.time.hour());
// Minute (0-59) (u8)
Serial.print("Minute = ");
Serial.println(gps.time.minute());
// Second (0-59) (u8)
Serial.print("Second = ");
Serial.println(gps.time.second());
// 100ths of a second (0-99) (u8)
Serial.print("Centisecond = ");
Serial.println(gps.time.centisecond());
}
}
SIM800.listen();
if (SIM800.available())
{ //Check if the SIM800 Module is telling anything
char a = SIM800.read();
Serial.write(a); //print what the module tells on serial monitor
incoming = incoming + String(a);
if (a == 13) //check for new line
incoming =""; //clear the string if new line is detected
incoming.trim(); //Remove /n or /r from the incomind data
if (incoming=="RING") //If an incoming call is detected the SIM800 module will say "RING" check for it
{
Serial.println ("Sending sms"); delay(1000);
responce = SIM800_send("ATH"); //Hand up the incoming call using ATH
delay (1000);
responce = SIM800_send("ATE0"); //Disable Echo
delay (1000);
responce = "";
if ( (Latitude=="") && (Longitude=="") )
{
SIM800.println("AT+CLBS=1,1"); delay(5000); //Request for location data
while (SIM800.available())
{
char letter = SIM800.read();
responce = responce + String(letter); //Store the location information in string responce
}
Serial.print("Result Obtained as:"); Serial.print(responce); Serial.println("*******");
prepare_message(); delay(1000); //use prepare_message funtion to prepare the link with the obtained LAT and LONG co-ordinates
}
SIM800.println("AT+CMGF=1"); //Set the module in SMS mode
delay(1000);
SIM800.println("AT+CMGS=\"+40753159104\""); //Send SMS to this number
delay(1000);
SIM800.println(Link); // we have send the string in variable Link
delay(1000);
SIM800.println((char)26);// ASCII code of CTRL+Z - used to terminate the text message
delay(1000);
}
}
if (Serial.available())
{ //For debugging
SIM800.write(Serial.read());
}
}
Thank you for posting the code, but, could you please place all of it within the CODE tags? As presented, it is very difficult to read as the formatting is lost.
If i am using an arduino mega, the thing i should change in the code is to remove software serial and instead of ss. and SIM800l. i use Serial. and Serial1. ?
I tried to use this, it seems to be working, i mean the GSM is working. I changed the GPS pins, how should i put the pins TX from GPS to RX to arduino and Rx from GPS to Tx to arduino?
Not quite sure what question you are asking here? Have you switched to using a Mega 2560 board as per srnet's suggestion? If so, then on this board, pins 14,15 will be the pins for Serial 3, pins 16,17 for Serial 2 and pins 18,19 will be for Serial 3. It should be printed on the PCB.
No, i tried to use with arduino uno the hardware serial(i switched the pins for GPS) and the software serial at the same time. It seems to be working in the Serial Monitor but i have this error
Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Uno"
Sketch uses 15254 bytes (47%) of program storage space. Maximum is 32256 bytes.
Global variables use 1458 bytes (71%) of dynamic memory, leaving 590 bytes for local variables. Maximum is 2048 bytes.
An error occurred while uploading the sketch
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Yeah, i tried this code, the sim800l seems to be working but it shows a bunch of bullshit from the GPS, he s supposed to not be working because im inside the building
#include <SoftwareSerial.h> //Software Serial header to communicate with GSM module
#include <TinyGPS++.h>
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial SIM800(11, 10); // RX, TX
String Link = "The current Location is https://www.google.com/maps/place/"; //we will append the Lattitude and longitude value later int the program
String responce = "";
String Longitude = "";
String Latitude = "";
String Date ="";
String Time ="";
String result2 = "";
String SIM800_send(String incoming) //Function to communicate with SIM800 module
{
SIM800.println(incoming); delay(100); //Print what is being sent to GSM module
String result = "";
while (SIM800.available()) //Wait for result
{
char letter = SIM800.read();
result = result + String(letter); //combine char to string to get result
}
return result; //return the result
}
void setup() {
//PWRKY pin of GSM module has to be pulled low for 1sec to enable the module
Serial.begin(9600); //Serial COM for debugging
SIM800.begin(9600); //Software serial called SIM800 to speak with SIM800 Module
delay(1000); //wait for serial COM to get ready
responce = SIM800_send("ATE1"); //Enable Echo if not enabled by default
Serial.print ("Responce:"); Serial.println(responce);
delay(1000);
responce = SIM800_send("AT+CGATT=1"); //Set the SIM800 in GPRS mode
Serial.print ("Responce:"); Serial.println(responce);
delay(1000);
responce = SIM800_send("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\" "); //Activate Bearer profile
Serial.print ("Responce:"); Serial.println(responce);
delay(1000);
responce = SIM800_send("AT+SAPBR=3,1,\"APN\",\"net\""); //Set VPN options => 'RCMNET' 'www'
Serial.print ("Responce:"); Serial.println(responce);
delay(2000);
responce = SIM800_send("AT+SAPBR=1,1"); //Open bearer Profile
Serial.print ("Responce:"); Serial.println(responce); //Open bearer Profile
delay(2000);
responce = SIM800_send("AT+SAPBR=2,1"); //Get the IP address of the bearer profile
Serial.print ("Responce:"); Serial.println(responce);
delay(1000);
}
void prepare_message()
{
//Sample Output for AT+CLBS=1,1 ==> +CIPGSMLOC: 75.802460,26.848892,550 //where 26.8488832 is Lattitude and 75.802460 is longitute
int first_comma = responce.indexOf(','); //Find the position of 1st comma
int second_comma = responce.indexOf(',', first_comma+1); //Find the position of 2nd comma
int third_comma = responce.indexOf(',', second_comma+1); //Find the position of 3rd comma
for(int i=first_comma+1; i<second_comma; i++) //Values form 1st comma to 2nd comma is Longitude
Longitude = Longitude + responce.charAt(i);
for(int i=second_comma+1; i<third_comma; i++) //Values form 2nd comma to 3rd comma is Latitude
Latitude = Latitude + responce.charAt(i);
Serial.println(Latitude); Serial.println(Longitude);
Link = Link + Latitude + "," + Longitude; //Update the Link with latitude and Logitude values
Serial.println(Link);
}
String incoming = "";
void loop() {
while (Serial.available() > 0)
{
gps.encode(Serial.read());
if (gps.location.isUpdated())
{
// Latitude in degrees (double)
Serial.print("Latitude= ");
Serial.print(gps.location.lat(), 6);
Latitude = gps.location.lat();
// Longitude in degrees (double)
Serial.print(" Longitude= ");
Longitude = gps.location.lng();
Serial.println(gps.location.lng(), 6);
Link = Link + Latitude + "," + Longitude;
// Raw latitude in whole degrees
Serial.print("Raw latitude = ");
Serial.print(gps.location.rawLat().negative ? "-" : "+");
Serial.println(gps.location.rawLat().deg);
// ... and billionths (u16/u32)
Serial.println(gps.location.rawLat().billionths);
// Raw longitude in whole degrees
Serial.print("Raw longitude = ");
Serial.print(gps.location.rawLng().negative ? "-" : "+");
Serial.println(gps.location.rawLng().deg);
// ... and billionths (u16/u32)
Serial.println(gps.location.rawLng().billionths);
// Raw date in DDMMYY format (u32)
Serial.print("Raw date DDMMYY = ");
Serial.println(gps.date.value());
Date = gps.date.value();
// Year (2000+) (u16)
Serial.print("Year = ");
Serial.println(gps.date.year());
// Month (1-12) (u8)
Serial.print("Month = ");
Serial.println(gps.date.month());
// Day (1-31) (u8)
Serial.print("Day = ");
Serial.println(gps.date.day());
// Raw time in HHMMSSCC format (u32)
Serial.print("Raw time in HHMMSSCC = ");
Serial.println(gps.time.value());
Time = gps.time.value();
// Hour (0-23) (u8)
Serial.print("Hour = ");
Serial.println(gps.time.hour());
// Minute (0-59) (u8)
Serial.print("Minute = ");
Serial.println(gps.time.minute());
// Second (0-59) (u8)
Serial.print("Second = ");
Serial.println(gps.time.second());
// 100ths of a second (0-99) (u8)
Serial.print("Centisecond = ");
Serial.println(gps.time.centisecond());
}
}
SIM800.listen();
if (SIM800.available())
{ //Check if the SIM800 Module is telling anything
char a = SIM800.read();
Serial.write(a); //print what the module tells on serial monitor
incoming = incoming + String(a);
if (a == 13) //check for new line
incoming =""; //clear the string if new line is detected
incoming.trim(); //Remove /n or /r from the incomind data
if (incoming=="RING") //If an incoming call is detected the SIM800 module will say "RING" check for it
{
Serial.println ("Sending sms"); delay(1000);
responce = SIM800_send("ATH"); //Hand up the incoming call using ATH
delay (1000);
responce = SIM800_send("ATE0"); //Disable Echo
delay (1000);
responce = "";
if ( (Latitude=="") && (Longitude=="") )
{
SIM800.println("AT+CLBS=1,1"); delay(5000); //Request for location data
while (SIM800.available())
{
char letter = SIM800.read();
responce = responce + String(letter); //Store the location information in string responce
}
Serial.print("Result Obtained as:"); Serial.print(responce); Serial.println("*******");
prepare_message(); delay(1000); //use prepare_message funtion to prepare the link with the obtained LAT and LONG co-ordinates
}
SIM800.println("AT+CMGF=1"); //Set the module in SMS mode
delay(1000);
SIM800.println("AT+CMGS=\"+40753159104\""); //Send SMS to this number
delay(1000);
SIM800.println(Link); // we have send the string in variable Link
delay(1000);
SIM800.println((char)26);// ASCII code of CTRL+Z - used to terminate the text message
delay(1000);
}
}
if (Serial.available())
{ //For debugging
SIM800.write(Serial.read());
}
}