Probleme to send message through sim 900

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 = "+212679035252"; //-> 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();
  }
}


Hi, which power supply are you using? There must be separate power supplies for the Arduino and the SIM900.

yes i separate power supplies

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project.

thanks

What is the GPS module that you're using? I mean SIM900 is a GSM and GPRS module. It's not for GPS communication. Are you using any other GPS module in your setup?

yes i have GPS NEO 6m

OK? What's the power supply that you're using for the SIM 900 module? SIM900 and Arduino need separate power supplies. Are you using a separate 5V, 2A DC power supply for the SIM900?

Not sure that is quite a proper explanation. :roll_eyes:

You need a power supply that is capable of operating the SIM900 module and the Arduino.

If it is not capable of powering both, it will sag and reset either or both devices.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.