Arduino and the SIM800L GSM module
Beginner
Or see every lesson.
- 465parts on the bench
- 43boards running now
- 1.00xreal time, on every board
The SIM800L is the small red GSM module with a spring antenna and a SIM card slot underneath. It sends and receives text messages and phone calls. Your Arduino talks to it over a serial port with AT commands, which are short lines of text like AT+CMGF=1.
The circuit above is an Arduino Uno with a SIM800L on pins 3 and 2. It runs the "send an SMS" sketch most tutorials print, using SoftwareSerial at 9600 baud. Press Run and open the serial monitor. You see each command, the modem’s answers, and about three seconds after the text, +CMGS: 1 and OK.
There is no real phone network here. Mokxi has no radio and no SIM card, and nobody’s phone rings. The modem has its own box in the serial monitor, and that box is a simulated network. The SMS your sketch sends shows up there. Type sms hello in it and the network texts the modem back.
What you need
- An Arduino Uno
- A SIM800L module with its antenna and a SIM card
- An 18650 Li-ion cell in a holder, or a buck converter set to 4 V
- Jumper wires, and on a real desk a 1000 uF capacitor across the modem’s VCC and GND
Wiring
| Part and pin | Goes to | Note |
|---|---|---|
| SIM800L VCC | 18650 + | 3.4 to 4.4 V, up to 2 A in bursts |
| SIM800L GND | 18650 − and Uno GND | Shared ground |
| SIM800L TXD | Pin 3 | The sketch’s RX |
| SIM800L RXD | Pin 2 | The sketch’s TX; add a divider on real hardware |
| SIM800L RST | Not connected | Pulled up on the board |
Power is the hard part
The SIM800L needs 3.4 to 4.4 V, and it pulls up to 2 A for a moment each time it transmits. That is far more than an Arduino pin can give. One Li-ion cell is the easy answer: a charged cell sits inside that range and can give the current.
Do not power it from the Uno’s 5 V pin or its 3.3 V pin. The modem watches its own supply. Over 4.4 V it prints OVER-VOLTAGE POWER DOWN and turns itself off. Under 3.4 V it prints UNDER-VOLTAGE POWER DOWN. The board then turns it back on, and it happens again, so the modem resets every few seconds.
Try it in the editor: move the modem’s VCC wire to the Uno’s 5V pin and run again. The modem’s box says why it switched off. Mokxi does not model the 2 A bursts themselves, so a supply with the right voltage always works here. On a real desk, a weak supply makes the modem reset while it looks for the network.
The sketch, step by step
The first command is a bare AT. The modem ships in autobaud mode, so it says nothing until it hears AT. It measures the speed of that A and answers at the same speed from then on. That is why every sketch starts with AT, and why it answers OK.
AT+CMGF=1 puts the modem in text mode, so a message is plain text. AT+CMGS="+15551234567" starts a message to that number, and the modem answers with a > prompt. The sketch prints the text, then sends character 26, which is Ctrl+Z. That sends the message. A few seconds later the modem answers +CMGS: 1 and OK.
The modem echoes every command back, so the serial monitor shows each one twice: once from the modem, then its answer. Send ATE0 to turn the echo off.
mySerial.println("AT"); // the handshake: the modem answers OK
updateSerial();
mySerial.println("AT+CMGF=1"); // text mode
updateSerial();
mySerial.println("AT+CMGS=\"+15551234567\""); // the number to text
updateSerial();
mySerial.print("Hello from Mokxi"); // the message
updateSerial();
mySerial.write(26); // Ctrl+Z sends itReceiving a text
The example also sends AT+CNMI=1,2,0,0,0. That tells the modem to print each new message as soon as it arrives, as a +CMT line with the number and the time, then the text. Type sms hello in the SIM800L box and the Uno prints it.
Without that command, the modem stores the message on the SIM and prints +CMTI: "SM",1 instead. Read it with AT+CMGR=1, and delete it with AT+CMGD=1.
Keep messages short when you print them this way. SoftwareSerial keeps only 63 bytes, and the sketch waits in delay(500) while the modem talks. A long message comes out cut short, on a real Uno too.
Useful AT commands
AT+CSQ gives the signal strength, from 0 to 31. AT+CREG? says whether the modem is on the network: +CREG: 0,1 means registered. AT+CBC reads the supply voltage in millivolts. ATD+15551234567; calls a number (the semicolon makes it a voice call) and ATH hangs up.
With AT+CLIP=1, an incoming call prints RING and then +CLIP with the caller’s number. Type call in the SIM800L box to ring the modem, and ATA answers.
Common mistakes
Powering it from the Uno. The 5 V pin is too high and the 3.3 V pin is too low. Use a Li-ion cell or a buck converter.
TX to TX. The modem’s TXD goes to the Uno’s RX pin, which is the first number in SoftwareSerial(3, 2).
Forgetting the shared ground. The cell’s minus and the Uno’s GND must be joined, or the serial line has no reference.
No AT first. In autobaud mode the modem ignores everything until it hears AT.
Questions
How do I power a SIM800L with an Arduino?
Not from the Arduino. Give the SIM800L its own 3.4 to 4.4 V supply that can give 2 A, like an 18650 Li-ion cell or a buck converter set to 4 V. Join its ground to the Arduino’s ground.
Why does my SIM800L keep restarting?
Its supply is wrong. On 5 V it reports OVER-VOLTAGE POWER DOWN; on 3.3 V, UNDER-VOLTAGE POWER DOWN. A supply that sags during the 2 A bursts resets it too.
What baud rate does the SIM800L use?
Any common rate, from 1200 to 115200. It ships in autobaud mode and takes the speed of the first AT it hears. Most sketches use 9600.
Can Mokxi send a real text message?
No. There is no phone network in Mokxi. The SIM800L’s box in the serial monitor is a simulated network that shows what your sketch sends and can text it back. The AT commands and the serial timing are modeled, so the sketch works the same on a real modem.
Keep going
Build this for real
Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.