Arduino SIM800L GSM Send and Receive SMS: Wiring, Code and Simulator

To build this Arduino SIM800L GSM Send and Receive SMS project you need an Arduino Uno and an SIM800L GSM module and a push button. Text the lab phone when the button is pressed, and switch the LED by replying ON or OFF — AT+CMGS and pushed +CMT messages. Make the 6 connections in the wiring table, upload the Arduino C++ code, and press the button and read the SMS on the phone in the Modules tab. Reply ON. On a real build, power the SIM800L from a Li-ion cell, not 5 V.

Open this circuit in the free Arduino Uno simulator

Parts list

QtyPartWhat it does
1Arduino Unothe microcontroller board
1SIM800L GSM moduleGSM/GPRS module: VCC 3.4–4.4 V (a Li-ion cell, not 5 V), GND shared with the board, TXD → RX pin, RXD ← TX pin. Autobaud: it locks on to your first "AT". Text a phone (AT+CMGS), call (ATD), receive SMS and calls from the phone in the Modules tab, or fetch a page over GPRS.
1push buttonConnects 1 to 2 while held. Pair with INPUT_PULLUP and wire the other side to GND.

Wiring

#FromTo
1Arduino Uno 5VSIM800L GSM module VCC
2Arduino Uno GNDSIM800L GSM module GND
3Arduino Uno pin 2SIM800L GSM module TXD
4Arduino Uno pin 3SIM800L GSM module RXD
5Arduino Uno pin 4push button 2.l
6Arduino Uno GNDpush button 1.r

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
  2. Add the parts. Add an SIM800L GSM module and a push button from the parts palette.
  3. Wire 1. Connect Arduino Uno 5V to SIM800L GSM module VCC.
  4. Wire 2. Connect Arduino Uno GND to SIM800L GSM module GND.
  5. Wire 3. Connect Arduino Uno pin 2 to SIM800L GSM module TXD.
  6. Wire 4. Connect Arduino Uno pin 3 to SIM800L GSM module RXD.
  7. Wire 5. Connect Arduino Uno pin 4 to push button 2.l.
  8. Wire 6. Connect Arduino Uno GND to push button 1.r.
  9. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  10. Run it. Press Run. Press the button and read the SMS on the phone in the Modules tab. Reply ON. On a real build, power the SIM800L from a Li-ion cell, not 5 V.

Arduino C++ code

// SIM800L GSM: text the lab phone when the button is pressed, and switch the LED by SMS.
// SIM800L TXD -> pin 2, RXD <- pin 3, VCC, GND. Button on pin 4 (to GND), LED on pin 13.
// Reply "ON" or "OFF" from the phone in the Modules tab.
#include <SoftwareSerial.h>

SoftwareSerial sim(2, 3);  // RX, TX
const int BUTTON = 4;
const int LED = 13;
const char *PHONE = "+919000000001";
String line;

void cmd(const char *c, unsigned long ms) {
  sim.println(c);
  unsigned long t = millis();
  while (millis() - t < ms) while (sim.available()) Serial.write(sim.read());
}

void setup() {
  Serial.begin(115200);
  pinMode(BUTTON, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
  sim.begin(9600);
  delay(1000);
  cmd("AT", 500);          // autobaud: the module locks on to 9600 here
  cmd("AT+CSQ", 500);
  cmd("AT+CMGF=1", 500);   // text mode
  cmd("AT+CNMI=2,2,0,0,0", 500);  // push new messages straight to us
  Serial.println(F("\nReady. Press the button to send an SMS."));
}

void sendSms(const String &text) {
  sim.print(F("AT+CMGS=\""));
  sim.print(PHONE);
  sim.println('"');
  delay(300);
  sim.print(text);
  sim.write(26);  // Ctrl+Z sends it
  Serial.print(F("SMS sent: "));
  Serial.println(text);
}

void loop() {
  static bool was = HIGH;
  bool now = digitalRead(BUTTON);
  if (was == HIGH && now == LOW) sendSms("Button pressed! Uptime " + String(millis() / 1000) + " s");
  was = now;

  while (sim.available()) {
    char c = sim.read();
    Serial.write(c);
    if (c != '\n') { if (c != '\r') line += c; continue; }
    // A pushed message is +CMT: "...", then the text on the next line.
    if (line == "ON") { digitalWrite(LED, HIGH); sendSms("LED is on"); }
    if (line == "OFF") { digitalWrite(LED, LOW); sendSms("LED is off"); }
    line = "";
  }
}

What to try

Press the button and read the SMS on the phone in the Modules tab. Reply ON. On a real build, power the SIM800L from a Li-ion cell, not 5 V.

Frequently asked questions

How do I wire the SIM800L GSM Send and Receive SMS project on an Arduino Uno?

Make 6 connections: Arduino Uno 5V to SIM800L GSM module VCC; Arduino Uno GND to SIM800L GSM module GND; Arduino Uno pin 2 to SIM800L GSM module TXD; Arduino Uno pin 3 to SIM800L GSM module RXD; Arduino Uno pin 4 to push button 2.l; Arduino Uno GND to push button 1.r.

What parts do I need for this Arduino project?

An Arduino Uno and an SIM800L GSM module and a push button.

Can I simulate this Arduino project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.

What does the code do?

Text the lab phone when the button is pressed, and switch the LED by replying ON or OFF — AT+CMGS and pushed +CMT messages.

Why does my SIM800L keep restarting?

It draws bursts of up to 2 A when it transmits. A 5 V Arduino pin or a weak USB supply sags and resets it. Power it from a Li-ion cell or a buck converter set to about 4 V, with a large capacitor close to the module.

How do I send an SMS with a SIM800L?

AT+CMGF=1 for text mode, then AT+CMGS="+91XXXXXXXXXX", wait for the > prompt, send the text and finish with Ctrl+Z (byte 26). The module answers +CMGS: <reference> and OK.

How do I receive SMS on a SIM800L?

AT+CNMI=2,2,0,0,0 makes the module push each new message to the serial port as +CMT: "<number>",… followed by the text on the next line.

More Arduino Uno projects