I'm doing a school project to finish the last year of school. I want to use the SIM800l module to send messages when the accelerometer detects that there has been an accident, but I have a problem. I bought the sensor and before having to program it for my project, I tested it first with a simple code to send messages. But it gives an error, it doesn't even get past the "Initialize" message.
The code is this:
#include <SoftwareSerial.h>
//Create software serial object to communicate with SIM800L
SoftwareSerial mySerial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2
void setup()
{
//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
//Begin serial communication with Arduino and SIM800L
mySerial.begin(9600);
Serial.println("Initializing...");
delay(1000);
mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
updateSerial();
mySerial.println("AT+CSQ"); //Signal quality test, value range is 0-31 , 31 is the best
updateSerial();
mySerial.println("AT+CCID"); //Read SIM information to confirm whether the SIM is plugged
updateSerial();
mySerial.println("AT+CREG?"); //Check whether it has registered in the network
updateSerial();
}
void loop()
{
updateSerial();
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while(mySerial.available())
{
Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
}
}
Your delay is too much. You have to read lines from the modem as fast as possible. If a line longer than 64 characters comes from the modem, with this huge delay you will lose the message.
If you think you need a delay - set it 10-20milliseconds
Add many more Serial.print() like the following, to find if your program stops.
#include <SoftwareSerial.h>
//Create software serial object to communicate with SIM800L
SoftwareSerial mySerial(3, 2); //SIM800L Tx & Rx is connected to Arduino #3 & #2
void setup()
{
//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
//Begin serial communication with Arduino and SIM800L
mySerial.begin(9600);
Serial.println("Initializing...");
delay(1000);
mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
updateSerial();
Serial.println("AT sent");
mySerial.println("AT+CSQ"); //Signal quality test, value range is 0-31 , 31 is the best
updateSerial();
Serial.println("AT+CSQ sent");
mySerial.println("AT+CCID"); //Read SIM information to confirm whether the SIM is plugged
updateSerial();
Serial.println("AT+CCID sent");
mySerial.println("AT+CREG?"); //Check whether it has registered in the network
updateSerial();
Serial.println("AT+CREG? sent");
}
void loop()
{
updateSerial();
Serial.println("void loop(){updateSerial(); sent");
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
Serial.println("updateSerial() 1");
}
while (mySerial.available())
{
Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
Serial.println("updateSerial() 2");
}
Serial.println("updateSerial() 3");
}
@beatrizc
Some more "inspection" items for your SM800L...
Is the antenna connected? (either solder-on helical or screw-on U.FL)
Simm800L needs stable operating voltage, so use an electrolytic capacitor on the +/- power of the module.
Test your network connection with this project (link).
Your code should work.Inspect and check wire interface between your arduino, sim module and power source. Sim module are power hungry. I would suggest you to use 5 volt mobile charger or any 5 volt power source that has voltage feedback as external power source for your sim module.
However, I managed to get it working. The next objective is to send a message with the help of the accelerometer and gyroscope MPU6050, when it detects an accident, the SIM800L module will send a message. It seems that joining the two codes is not the most practical solution...
I found the problem!! I went to read the SIM800L library out of curiosity and noticed that it didn't support Mega. I tested the GSM and the MPU-6050 on the UNO and I was able to get the project working