In this tutorial, we will use a SIM800L GSM Module with Arduino. SIM800L is a low-cost GSM/GPRS module that supports Quad-band GSM/GPRS networks. it can be used to make calls, and send text messages, this module can be easily interfaced with Arduino, and Raspberry Pi using the UART Interfaces.
Required Material
- SIM800L GSM/GPRS module
- Arduino Uno
- Jumper wires
- Breadboard
- SIM card
- DC-DC Adjustable Step-Down Converter
SIM800L Module
The SIM800L GSM/GPRS module is a compact and low-cost module that allows devices to connect to the GSM and GPRS networks. It is designed for use in a type of applications, such as remote monitoring, tracking, and control systems, as well as for sending and receiving SMS messages making voice calls, and receiving voice calls.
It works on frequencies EGSM 900MHz, DCS 1800MHz, and PCS 1900MHz It supports a GPRS connection with download speeds of up to 85.6kbps. it has an inbuilt TCP/IP stack that allows it to connect to the internet. SIM800L also has an inbuilt RTC and can be used to send and receive text messages (SMS).
SIM800L Pinout
The SIM800L module has 12 pins that interface it to the Microcontroller. The connections are as follows:
Pinout
-
- VCC: Supply voltage (3.4V – 4.4V)
- GND: Ground
- TXD: Transmit data
- RXD: Receive data
- RST: Reset pin
- RI: Ring Indicator
- DTR: Data Terminal
- DCD: Data carrier detect
- MIC+: Positive microphone input
- MIC-: Negative microphone input
- SPK+: Positive speaker output
- SPK-: Negative speaker output
- SIM Card Slot:
SIM800L Features and Specifications
- Quad-band GSM/GPRS module
- Support for GPRS class 10 and GSM 07.07, 07.05, and 03.40
- Integrated TCP/IP protocol stack
- Support: HTTP, FTP, SMTP, and POP3 protocols
- Serial interface: UART
- Operating voltage: 3.7V to 4.4V
- Power consumption in sleep mode: less than 1mA
- Operating temperature: -40°C to +85°C
- SIM card socket: micro SIM
- Antenna connector: IPX
- Status signaling: LED
Note: SIM800L operates on 3.7V to 4.2V, so we need to use a voltage regulator to step down the 5V from the Arduino to the required voltage.
SIM800L Applications
- Home automation
- Emergency systems
- Communication
- Remote monitoring and control
- Alarm and security systems
- SMS and MMS
- Voice call
Power Supply for SIM800L
The SIM800L module can also operate on an external power supply that provides a minimum of 3.6V and a maximum of 4.2V.
The first is to use the Arduino’s 3.3V output pin. This output pin is regulated and can provide up to 500mA of current. However, the SIM800L can consume up to 2A of current, so this is not an ideal solution.
The second way is to use an external power supply that is connected to the Arduino’s 5V output pin. This pin can provide up to 1A current, Therefore, an external 3.7V Li-ion Polymer battery is used as the power for the module.
Interfacing SIM800L GSM Module with Arduino
The SIM800L is a GSM module with a serial interface. It can send and receive text messages and receive calls. The SIM800L can be attached to a microcontroller using the serial UART interface, and in the example shown down, connected to an Arduino.
The connection between SIM800L GSM Module with Arduino
S.N. | ARDUINO | SIM800L |
1. | +5 V | VCC |
2. | GND | GND |
3. | 3 | TXD |
4. | 2 | RXD |
Note: don’t ignore connecting the ground first; add connections with your Arduino to avoid module harm or make all connections first, then power up the circuit.
Now, insert the SIM card into the back of the SIM800 module. Then, attach the SIM800 TX and RX to the Arduino D3 and D2 respectively. These are the serial UART connections that allow communication between the two modules.
Connecting the SIM800L to the Network
If the power to the SIM800L is enough, the onboard LED starts blinking. If there’s not enough power, the LED blinks for almost three seconds and then turns off.
The frequency of the blinking indicates something: Here’s a video displaying these LED indications.
- Every second: searching for a network.
- Every three seconds: connected to a network.
- Twice per second: connected through GPRS.
SIM800l Testing AT Commands Arduino Code
The below code allows Arduino to communicate with the SIM800L GSM module. It sets up the necessary serial communication and configures the module for text-based SMS messaging.
This code enables the Arduino to send and receive AT commands to the module, which can be used to perform actions like sending SMS messages or making phone calls.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#include <SoftwareSerial.h> SoftwareSerial mySerial(3, 2); void setup() { Serial.begin(9600); mySerial.begin(9600); Serial.println("Initializing..."); delay(1000); sendATCommand("AT"); sendATCommand("AT+CMGF=1"); sendATCommand("AT+CNMI=1,2,0,0,0"); } void loop() { updateSerial(); } void sendATCommand(const char* command) { mySerial.println(command); delay(500); while (mySerial.available()) { Serial.write(mySerial.read()); } Serial.println(); } void updateSerial() { delay(500); while (Serial.available()) { mySerial.write(Serial.read()); } while (mySerial.available()) { Serial.write(mySerial.read()); } } |
Once you upload the code to the Arduino board, you’ll be able to send all the AT commands in order to send/receive text messages or make calls.
SIM800l Sending SMS Arduino Code
You need to replace it with the ZZ country code and xxxxxxxxxx
with the 10-digit phone number to which you want to send the SMS.
Make sure to add the country code and remove any leading zeros from the phone number.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include <SoftwareSerial.h> SoftwareSerial mySerial(3, 2); void setup() { Serial.begin(9600); mySerial.begin(9600); Serial.println("Initializing..."); delay(1000); sendATCommand("AT"); sendATCommand("AT+CMGF=1"); sendATCommand("AT+CMGS=\"+ZZxxxxxxxxxx\""); // Enter your phone number here (prefix country code) sendATCommand("Hello from DIY Projects Lab"); // Enter your message here mySerial.write(26); } void loop() { } void sendATCommand(const char* command) { mySerial.println(command); delay(500); while (mySerial.available()) { Serial.write(mySerial.read()); } Serial.println(); } |
The screenshot below shows the SMS has been sent to the phone number.
SIM800l Receiving SMS Arduino Code
“Now, let’s program our Arduino to read incoming SMS messages.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#include <SoftwareSerial.h> SoftwareSerial mySerial(3, 2); void setup() { Serial.begin(9600); mySerial.begin(9600); Serial.println("Initializing..."); delay(1000); mySerial.println("AT"); updateSerial(); mySerial.println("AT+CMGF=1"); updateSerial(); mySerial.println("AT+CNMI=2,2,0,0,0"); updateSerial(); } void loop() { updateSerial(); // Check if a new SMS is received if (Serial.available() > 0) { String sms = Serial.readStringUntil('\n'); processSMS(sms); } } void updateSerial() { delay(500); while (Serial.available()) { mySerial.write(Serial.read()); } while (mySerial.available()) { Serial.write(mySerial.read()); } } void processSMS(String sms) { Serial.print("Received SMS: "); Serial.println(sms); } |
SIM800l Making Call Arduino Code
Making a call is an essential feature that can be implemented using an Arduino and a GSM module. This sketch can be useful when you want your Arduino to have the capability of making an SOS/distress call in critical situations.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#include <SoftwareSerial.h> SoftwareSerial mySerial(3, 2); void setup() { Serial.begin(9600); mySerial.begin(9600); Serial.println("Initializing..."); delay(1000); sendATCommand("AT"); sendATCommand("AT+CMGF=1"); sendATCommand("ATD+916209403151;"); // Enter the phone number you want to call here (prefix country code) } void loop() { // Nothing to do here } void sendATCommand(const char* command) { mySerial.println(command); delay(500); while (mySerial.available()) { Serial.write(mySerial.read()); } Serial.println(); } |
The following screenshot shows how to process a call from the SIM800L GSM module.
SIM800l Receiving Call Arduino Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
#include <SoftwareSerial.h> SoftwareSerial mySerial(3, 2); // SIM800L Tx & Rx connected to Arduino pins 3 & 2 void setup() { Serial.begin(9600); // Serial communication with Arduino IDE (Serial Monitor) mySerial.begin(9600); // Serial communication with SIM800L GSM module Serial.println("Initializing..."); delay(1000); mySerial.println("AT"); // Handshake test updateSerial(); mySerial.println("AT+CLIP=1"); // Enable caller identification updateSerial(); } void loop() { updateSerial(); // Check if there's an incoming call if (mySerial.available() > 0) { String response = mySerial.readStringUntil('\n'); if (response.indexOf("RING") >= 0) { Serial.println("Incoming call detected!"); // Handle the incoming call as needed // You can perform actions or trigger events based on the incoming call } } } void updateSerial() { delay(500); while (Serial.available()) { mySerial.write(Serial.read()); // Forward data from Serial Monitor to SIM800L } while (mySerial.available()) { Serial.write(mySerial.read()); // Forward data from SIM800L to Serial Monitor } } |
Make sure you have connected the SIM800L module correctly to the Arduino and have a valid SIM card with active calling capabilities. Upload the code to your Arduino, open the Serial Monitor, and you will start seeing a “Call Ring!” message.
In summary, we have explored how we can integrate a SIM800L GSM module with an Arduino to enable communication capabilities. We covered sending SMS messages, making calls, and receiving calls.
#include <SoftwareSerial.h>
———————————————————-
what is this???????
Hey, I can’t understand.
while(Serial.available()<=0);
while(Serial.available()<=0);
???????
Pingback: Raspberry Pi Pico Home Automation System Using GSM SIM800