SIM800L With Arduino Tutorial
Introduction to SIM800L
There are so many GSM modules that came to market right now. And SIM800L almost the cheapest. It cost under 10$ and has the same feature as other. So, this module is a great one.
This module works just like another module, it uses AT Command to communicate with arduino and has the same command. You can download the AT command list it uses here.
Just like another GSM module like SIM900A that we’ve wrote the tutorial here. This is of course use serial communication to communicate with arduino. So we need Tx and Rx here.
Arduino and SIM800L Wiring Diagram
arduino and SIM800L wiring diagramConnect your arduino and SIM800L like above. But this seems like to be wrong. Because in the datasheet it says that VCC must be at 4.4V maximum. But in last version of this module, it works given 5V for it’s VCC.
if it is doesn’t work for you can try to drop the VCC to not more than 4.4V. You can use buck converter, or the simplest way just use a diode. I will prefer use only a diode because it simplicity. So, wiring diagram become like below :
The Code
Sending a message:
In this example, we made two function that is SendMessage() and _readSerial(). SendMessage() to send message and _readSerial() to read the answer from SIM800L.
#include <SoftwareSerial.h> SoftwareSerial sim(10, 11); int _timeout; String _buffer; String number = "+6289668072234"; 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); } void loop() { SendMessage(); delay(10000); } void SendMessage() { //Serial.println ("Sending Message"); sim.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode delay(1000); //Serial.println ("Set SMS Number"); sim.println("AT+CMGS=\"" + number + "\"\r"); //Mobile phone number to send message delay(1000); String SMS = "Hello, how are you?"; sim.println(SMS); delay(100); sim.println((char)26);// ASCII code of CTRL+Z delay(1000); _buffer = _readSerial(); } String _readSerial() { _timeout = 0; while (!sim.available() && _timeout < 12000 ) { delay(13); _timeout++; } if (sim.available()) { return sim.readString(); } }
To make a call you can create another function and call that function from your loop. And this is the function :
void callNumber() { sim.print (F("ATD")); sim.print (number); sim.print (F(";\r\n")); _buffer = _readSerial(); Serial.println(_buffer);
I mixed up the code to send and receive sms and make a call. Every task in a function. So it has three function, SendMessage(), ReceiveMessage() and Call(). In this code you just type in serial monitor “s” to send, “r” to receive SMS, and “c” to make a call.
#include <SoftwareSerial.h> SoftwareSerial sim(10, 11); int _timeout; String _buffer; String number = "+6282222222222"; //-> change with your number 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"); } void loop() { if (Serial.available() > 0) switch (Serial.read()) { case 's': SendMessage(); break; case 'r': RecieveMessage(); break; case 'c': callNumber(); break; } if (sim.available() > 0) Serial.write(sim.read()); } void SendMessage() { //Serial.println ("Sending Message"); sim.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode delay(1000); //Serial.println ("Set SMS Number"); sim.println("AT+CMGS=\"" + number + "\"\r"); //Mobile phone number to send message delay(1000); String SMS = "Hello, how are you?"; sim.println(SMS); delay(100); sim.println((char)26);// ASCII code of CTRL+Z delay(1000); _buffer = _readSerial(); } void RecieveMessage() { Serial.println ("SIM800L Read an SMS"); delay (1000); sim.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS delay(1000); Serial.write ("Unread Message done"); } String _readSerial() { _timeout = 0; while (!sim.available() && _timeout < 12000 ) { delay(13); _timeout++; } if (sim.available()) { return sim.readString(); } } void callNumber() { sim.print (F("ATD")); sim.print (number); sim.print (F(";\r\n")); _buffer = _readSerial(); Serial.println(_buffer); }
And that’s all the code. That is easty Isn’t it? And if you need a tutorial on how to send data over GPRS with this module, wait our next tutorial.
Watch also complete video tutorial below :