Example Code for Arduino-Send SMS (AT Commands)

Last revision 2026/01/24

This article guides you through sending SMS via Arduino using AT commands, detailing hardware setup, software requirements, and using the DF Serial Debugger for effective communication between the Arduino board and SIM808 module.

Hardware Preparation

Software Preparation

Preparations

  1. Install the SIM card in the sim slot on the back of the board
    • Make sure your SIM card is available, and you can put the SIM card into the socket or get it out by sliding the metal lock.
  2. Install the GPS & GSM antennas on the board
  3. Connect with PC and power supply(there are three ways to supply the power)
    • Through 7~23V power supply jack
    • Through VIN pin on board
    • Remove the jumper on NO BAT, and connect a 3.7V Lithium Battery to BAT jack
    • After connecting the board to PC by an USB cable, the board shows up as Leonardo automatically if you have installed the Arduino by .exe file, or you will need to install the driver manually
      DFR0355_Leonardo
  4. BOOT SIM808 by pressing the BOOT white button for 2 seconds if the NET indicator LED is OFF.
  5. Upload the debugging code below to Leonardo.

Sample Code

/*
 * The sketch here will make Leonardo exchange
 * data between the USB serial port and SIM808 module.
*/

void setup() {
  Serial.begin(115200); //initialize Serial(i.e. USB port)
  Serial1.begin(115200); //initialize Serial1
}

void loop() {
  //If Serial1 receive data, print out to Serial
  while (Serial1.available()) {
    Serial.write(Serial1.read());
  }
  //If Serial receive data, print out to Serial1
  while (Serial.available()) {
    Serial1.write(Serial.read());
  }
  delay(1);  //delay for a short time to
  // avoid unstable USB communication
}

Other Preparation Work(AT command)

Open DF Serial Debugger and copy the settings according to the image below. If you cannot open the port, please check if the port is occupied by the Arduino IDE serial monitor.

  1. Send AT+CMGF=1 to set the SMS in text format. You will get OK
  2. Send *AT+CMGS="170***9217" to set the receiver number. You will see a notation >
  3. Write the content of the message
  4. Send 1A(HEX) as an end to send the message
  5. You will get OK, and the message will be sent

We recommend using DF Serial Debugger because when you are going to send the message, you have to send 0x1A in HEX. The DF Serial Debugger can send data in HEX while the Arduino IDE can't.

  • We recommend using DF Serial Debugger because when you are going to send the message, you have to send 0x1A in HEX. The DF Serial Debugger can send data in HEX while the Arduino IDE can't.
  • Do NOT tick the checkbox hex until Step 4 which is to send 0x1A in HEX.

DFR0355_phone_receive_sms

Result

DFR0355_send_sms_DF_serial

Was this article helpful?

TOP