Tutorial: How to use SIM800L GSM Module using Arduino | Send and Receive SMS
There are actually a lot of GSM module available in the market but I personally recommend and prefer SIM800L due to its size and simplicity. It has a small footprint so it occupies a very small space. This is because SIM800L only provides the basic core of GSM. Meaning to say, you need to provide additional circuitry to use it but don’t worry I will show you the simplest way to use it.
To send SMS:
1. Send AT+CMGF=1 <CR><LF>
– this is to configure the GSM module to text mode
CR – Cariage Return, ASCII character 13 or r
LF – Line Feed, ASCII character 10 or n
2. Sent AT+CMGS=”+ZZxxxxxxxxxx”<CR><LF>
– this is for entering the sim number
ZZ – is the country code
xx – is the 10-digit mobile number
CR – Cariage Return, ASCII character 13 or r
LF – Line Feed, ASCII character 10 or n
3. Wait for the ‘>’ reply from SIM800L before sending the next
4. When the GSM replied with ‘>’, this is the time to send your message such as:
“Hello from SIM800L”<CR><LF>
Hello from SIM800L – is the SMS you want to send.
CR – Cariage Return, ASCII character 13 or r
LF – Line Feed, ASCII character 10 or n
5. Send a CTRL+Z character or ASCII character 26.
To receive SMS:
1. Send AT+CMGF=1 <CR><LF>
– this is to configure the GSM module to text mode
CR – Cariage Return, ASCII character 13 or r
LF – Line Feed, ASCII character 10 or n
2. Send AT+CNMI=1,2,0,0,0<CR><LF>
– this is to configure the GSM module to forward via serial when SMS is receive.
CR – Cariage Return, ASCII character 13 or r
LF – Line Feed, ASCII character 10 or n
Video Demonstration:
Source Code:
#include "SoftwareSerial.h"
SoftwareSerial mySerial(2, 3);
String cmd = "";
void setup()
{
mySerial.begin(9600);
Serial.begin(9600);
Serial.println("Initializing...");
delay(1000);
mySerial.println("AT"); // Sends an ATTENTION command, reply should be OK
updateSerial();
mySerial.println("AT+CMGF=1"); // Configuration for sending SMS
updateSerial();
mySerial.println("AT+CNMI=1,2,0,0,0"); // Configuration for receiving SMS
updateSerial();
}
void loop()
{
updateSerial();
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
cmd+=(char)Serial.read();
if(cmd!=""){
cmd.trim(); // Remove added LF in transmit
if (cmd.equals("S")) {
sendSMS();
} else {
mySerial.print(cmd);
mySerial.println("");
}
}
}
while(mySerial.available())
{
Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
}
}
void sendSMS(){
mySerial.println("AT+CMGF=1");
delay(500);
mySerial.println("AT+CMGS="+639175291539"r");
delay(500);
mySerial.print("Hi! TechToTinker!");
delay(500);
mySerial.write(26);
}
If you find article helpful, please kindly Subscribe to my channel.
Thank you and have a good day.
bonjour
la 2G n'existe plus en FRANCE et je crois que le sim 800 ne fonctionne que sur la 2G
pouvez vous me dire plus
merci
translation:
hello 2G no longer exists in FRANCE and I believe that the sim 800 only works on 2G can you tell me more thank you
——
Hello dd30, thank you for visiting my blog. Yes, SIM800L is a 2G gsm module and will not work on countries with no more support for 2G network. You may still use the concept and the source code with small modification with other gsm module.
updateSerial & sendSMS use of undeclared identifier error. Kindly help to resolve issue
Does this code works with the ESP32? It does not print anything
@Omar, there could be a lot of reasons.
1. Do you have a proper power supply? How do you power the SIM800L.
2. How do you connect it to ESP32? What are your pin assignments?
3. What's the status of the onboard LED? Does it blink every seconds? or every 3 seconds?
I haven't tried it with ESP32 but it should work with ESP32.
Dear Sir, the phone number in code must be sms sender number or reciever number? When I write SIM card number inside GSM module and press "S" , I can see the money charged from that number,but where the sms was sent I don't know.When I rite my phone number in the code and press "S" nothing sent and nothing recieved.
Never mind.Now everithing is working
put reciver number with country code example +92 then reciver number then
can we ust that module with pictoblox how§