SIM800L is nice and inexpensive GSM breakout board. We will set it up with Arduino and send simple text messages. The library can ofcourse be used to do more things like calls etc., We will focus on setting the module the right way because you'll have to take care of a few things like power and reset.

Hookup

We will hook up the SIM800l module with Arduino using the Soft Serial library. We will connect the Hardware serial port to the computer to debug and print messages.

0 Sim800l bb.png

Reset Circuit

Power

Note that the module requires voltage in the range of 3.17 to 4.4v . If proper voltage is not provided the module will give under and over voltage warnings. Hence we used a 3.7v LiPo battery. You may also use a regulator like LM317.

Test Code

Let us start with the simple text code that will verify if everything is setup properly. Remember to insert a SIM card before proceeding further. The code below takes commands from the Arduino terminal and sends it to the GSM Module. It also sends the commands other way around, from the GSM module to the Arduino. The code will also verify if the Software Serial library is also working fine.

#include <SoftwareSerial.h>
String Arsp, Grsp;
SoftwareSerial gsm(10, 11); // RX, TX
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Testing GSM SIM800L");
gsm.begin(4800);
}
void loop() {
// put your main code here, to run repeatedly:
if(gsm.available())
{
Grsp = gsm.readString();
Serial.println(Grsp);
}
if(Serial.available())
{
Arsp = Serial.readString();
gsm.println(Arsp);
}
}
Once you flash the code to the board, you'll be able to send all the AT commands in order to send/receive text messages or make calls. At-commands.PNG

Sending SMS

We will now use the basic Sim800l library to send messages. The code asks you to enter phone number and the message to be sent and sends the message!

/*
* Author@ExploreEmbedded
* Example to Send messages Interactively using GSM SIM800L
*
* LIBRARY CREDITS:
* Thanks to Cristian Steib(steibkhriz@gmail.com) for the library.
*
*
*
* PINOUT:
* _____________________________
* | ARDUINO UNO >>> SIM800L |
* -----------------------------
* GND >>> GND
* RX 10 >>> TX
* TX 11 >>> RX
* RESET 2 >>> RST
*
*
*/
#include <Sim800l.h>
#include <SoftwareSerial.h> //is necesary for the library!!
Sim800l Sim800l; //to declare the library
char text[161]=""; //buffer to store message
char number[11]=""; //phone number to send message
int cnt;
bool error; //to catch the response of sendSms
void setup(){
Sim800l.begin(); // initializate the library.
Serial.begin(9600);
}
void loop(){
//Read the Number
Serial.print("\nEnter 10 digit Phone Number:");
while(Serial.available()<=0);
cnt = Serial.readBytesUntil('\n',number, 11);
number[cnt] = '\0';
Serial.println(number);
//clear the serial input buffer so that no typed characters are pending
delay(1000); //delay required before clearing the input buffer
while(Serial.available()>0) //clear buffer
{
Serial.read();
}
//Read the Message to be sent
Serial.print("Enter Message:");
while(Serial.available()<=0);
cnt = Serial.readBytesUntil('\n',text, 160);
text[cnt] = '\0';
Serial.println(text);
delay(1000);
while(Serial.available()>0) //clear buffer
{
Serial.read();
}
//Send the message and display the status
error = Sim800l.sendSms(number,text);
if(error)
Serial.println("Error Sending Message");
Serial.println("Message Sent Successfully!");
}

Send msg.png

Reference and Credits

  • Thanks to Cristian Steib for the SIM800l library.


Going further we would also look to test GPRS data connectivity with this module.