Example Code for Arduino-Send SMS-V1.0

Last revision 2026/01/24

This guide explains how to send SMS using Arduino with SIM800H Shield, detailing hardware and software setup, required modifications, and providing sample code for sending messages via UCS2 encoding.

Hardware Preparation

Software Preparation

NOTE: SIM800H Hardware Library Due to the incoming serial data is too large, the original Arduino serial cache buffer needs to be changed to be larger, there are two ways:

  1. If your Arduino IDE is below 1.5.5 version, cut HardwareSerial.cpp to Arduino\hardware\arduino\cores\arduino and cover the original file.
  2. If it is version 1.5.5 or later, then cut the HardwareSerial.h to Arduino\hardware\arduino\cores\arduino and cover the original file.

Modify the library:

If your Arduino IDE is below 1.5.5 version, open the HardwareSerial.cpp file in the Arduino\hardware\arduino\cores\arduino, change # define SERIAL_BUFFER_SIZE 64 to # define SERIAL_BUFFER_SIZE 140;
If the version is 1.5.5 or later, open HardwareSerial.h file and do the same modifications.
NOTE: Not compatible with Arduino IDE1.6.*, Recommand Arduino IDE 1.0.6.

Steps

  1. Insert the SIM800H GPRS Shield onto UNO board;
  2. connect UNO to PC with USB cable;
  3. Use external power supply;
  4. Turn the switch to the "NONE";
  5. Open different sketch, select the right board "UNO" and "Srial port", upload sketch to the UNO;
  6. Don't forget to turn the switch to "Arduino".
  7. Open the sketch "Examples\sim800program\SendSMS " in Arduino IDE.

Sample Code

/*
TTS Speaker

This sketch, for the Arduino SIM800H GPRS Shield,send a short message to telephone
After initialization success ,enable prompt SMS.

created Dec 2014
by zcl

This example code is in the public domain.
*/

// libraries
#include <sim800cmd.h>

//initialize the library instance
//fundebug is an application callback function,when someon is calling.
Sim800Cmd sim800demo(fundebug);

//the setup routine runs once when you press reset:
void setup()
{
    //initialize SIM800H,return 1 when initialize success.
    while((sim800demo.sim800init()) == 0);
    delay(1000);
    //enable SMS prompt
    sim800demo.setSMSEnablePrompt(OPEN);
}
void loop()
{
    //send message to telephone,use UCS2 code
    sim800demo.sendSMS("00310035003900380032003300370033003100380031","4F60597DFF0C6B228FCE4F7F752800530049004D0038003000300048");
    //while, do not return
    while(1);
}

//application callback function
//Note that not too much to handle tasks in this function
void fundebug(void)
{
}

Result

Enables SMS notification, send a text message.

Additional Information

  1. sim800demo.setSMSEnablePrompt(OPEN); This enables SMS notification;

  2. sim800demo.sendSMS("00310035003900380032003300370033003100380031","4F60597DFF0C6B228FCE4F7F752800530049004D0038003000300048"); This is to send a text message, the first parameter is a phone number, the second parameter is the content to be sent, both of these parameters is UCS2 encoding.

AT command:

AT+CMGS="00310038003600310036003300360036003500340037"\r\n

Note:

  1. the text message cannot be longer than 20 characters, or saying 80 UCS2 encoding.
  2. here need to convert string to UCS2 encoding, you can download the softeware CharCoderto transform the string to UCS2 encoding, ps: UCS2-BIG.

Was this article helpful?

TOP