I want to send gps data through sim900 but i don't know why the code doesn't work i want your help please
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
SoftwareSerial sim(7, 8);
int _timeout;
String _buffer;
String number1 = "+212684547105";
String number = "+xxxxxxxxxxxx"; //-> change with your number
// Choose two Arduino pins to use for software serial
int RXPin = 2;
int TXPin = 3;
int GPSBaud = 9600;
// Create a TinyGPS++ object
TinyGPSPlus gps;
// Create a software serial port called "gpsSerial"
SoftwareSerial gpsSerial(RXPin, TXPin);
//SoftwareSerial espSerial(0, 1);
String str;
void setup() {
//delay(7000); //delay for 7 seconds to make sure the modules get the signal
Serial.begin(9600);
_buffer.reserve(50);
Serial.println("Sistem Started...");
sim.begin(9600);
delay(1000);
Serial.println("Type s to send an SMS, r to receive an SMS, and c to make a call");
// Start the Arduino hardware serial port at 9600 baud
// Start the software serial port at the GPS's default baud
gpsSerial.begin(GPSBaud);
}
void loop() {
float lati,longi,Alti;
// This sketch displays information every time a new sentence is correctly encoded.
while (gpsSerial.available() > 0)
if (gps.encode(gpsSerial.read())){
if (gps.location.isValid())
{
lati = gps.location.lat();
longi = gps.location.lng();
Alti = gps.altitude.meters();
str ="Latitude: " +String(lati)+ "longitude: " +String(longi)+ "Altitude: "+String(Alti);
sim.println("AT+CMGF=1\r"); //Sets the GSM Module in Text Mode
delay(200);
//Serial.println ("Set SMS Number");
sim.println("AT+CMGS=\"" + number + "\"\r"); //Mobile phone number to send message
delay(200);
sim.println(str);
delay(1000);
sim.println((char)26);// ASCII code of CTRL+Z
delay(200);
_buffer = _readSerial();
}
else
{
Serial.println("Location: Not Available");
}
}
// If 5000 milliseconds pass and there are no characters coming in
// over the software serial port, show a "No GPS detected" error
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println("No GPS detected");
while(true);
}
}
String _readSerial() {
_timeout = 0;
while (!sim.available() && _timeout < 12000 )
{
delay(13);
_timeout++;
}
if (sim.available()) {
return sim.readString();
}
}
I am also searching the same query if any body please discuss here
problme to send data gps through sms sim 900
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.