Send an SMS on an Arduino Uno
The SIM800L tutorial sketch: AT, text mode, AT+CMGS and Ctrl+Z, on a simulated network. Type sms hello in the modem’s serial box to text it back. The whole build, an Arduino Uno and 2 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner Runs in your browser. Free, and no account needed.
The parts retail for about $35. On Mokxi they're free.
Step by step, with the wiring and the common mistakes: Arduino SIM800L: Send and Receive SMS, AT Commands
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Send an SMS: the SIM800L sketch every tutorial starts with.
//
// SIM800L TXD -> pin 3 (the sketch's RX)
// SIM800L RXD <- pin 2 (the sketch's TX)
// SIM800L VCC -> an 18650 cell's +, GND -> the cell's - and the Uno's GND
//
// The modem wants 3.4 to 4.4 V and 2 A peaks, so it has a Li-ion cell of its
// own. On the Uno's 5 V pin it switches itself off and back on, over and over,
// as the real one does.
//
// The Uno's one hardware serial port belongs to the serial monitor, so the
// modem gets a SoftwareSerial port at 9600 baud. A bare AT lets the modem's
// autobaud find that rate; then text mode, the number, the text, and Ctrl+Z
// (character 26) to send it.
//
// There is no real phone network here. The modem has its own line in the
// serial monitor, and that line is the simulated network: the SMS shows up
// there about three seconds after Ctrl+Z. Type sms hello in it to text the
// modem back, and the sketch prints what the modem says.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2); // RX, TX: the SIM800L's TXD and RXD
void updateSerial() {
delay(500);
while (Serial.available()) {
mySerial.write(Serial.read()); // the serial monitor to the modem
}
while (mySerial.available()) {
Serial.write(mySerial.read()); // the modem to the serial monitor
}
}
void setup() {
Serial.begin(9600);
mySerial.begin(9600);
Serial.println("Initializing...");
delay(1000);
mySerial.println("AT"); // the handshake: the modem answers OK
updateSerial();
mySerial.println("AT+CMGF=1"); // text mode
updateSerial();
mySerial.println("AT+CNMI=1,2,0,0,0"); // print new messages as they come
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 it
}
void loop() {
updateSerial();
}
Parts list
3 parts, plus the jumper wires. They retail for about $35; on Mokxi they're free.
How it is wired
4 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Ground: Arduino Uno R3 pin GND; GSM modem, SIM800L pin GND; Battery: AA, coin cell, LiPo pin V-
- Arduino Uno R3 pin 3; GSM modem, SIM800L pin TXD
- Arduino Uno R3 pin 2; GSM modem, SIM800L pin RXD
- GSM modem, SIM800L pin VCC; Battery: AA, coin cell, LiPo pin V+
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.