Help with Relay Control via SMS

Hi guys! I am trying to control a single channel relay via SMS. The problem I have is that I cannot send/receive messages or even dial the module. When I try to dial the number on the module, it doesn’t even ring on my phone (cannot be reached). I tried googling the solution but I still can’t make it work. There’s also this thing with the serial monitor where it only repeatedly displays:


I am using arduino UNO, a sim900A gsm module, and a single channel relay. I have also tried the other baud rates but the one I am using is the only one that works. Here is my code:

#include <SoftwareSerial.h> // Library for using serial communication
SoftwareSerial SIM900(7, 8); // Pins 7, 8 are used as used as software serial pins

String incomingData;   // for storing incoming serial data
String message = "";   // A String for storing the message
int relay_pin = 2;    // Initialized a pin for relay module

void setup()
  Serial.begin(9600); // baudrate for serial monitor
  SIM900.begin(115200); // baudrate for GSM shield

  pinMode(relay_pin, OUTPUT);   // Setting erlay pin as output pin
  digitalWrite(relay_pin, HIGH);  // Making relay pin initailly low

  // set SMS mode to text mode
  // set gsm module to tp show the output on serial out

void loop()
  //Function for receiving sms

  // if received command is to turn on relay
    digitalWrite(relay_pin, LOW);
    message = "Led is turned ON";
    // Send a sms back to confirm that the relay is turned on
  // if received command is to turn off relay
    digitalWrite(relay_pin, HIGH);
    message = "Led is turned OFF";
    // Send a sms back to confirm that the relay is turned off

void receive_message()
  if (SIM900.available() > 0)
    incomingData = SIM900.readString(); // Get the data from the serial port.

void send_message(String message)
  SIM900.println("AT+CMGF=1");    //Set the GSM Module in Text Mode
  SIM900.println("AT+CMGS=\"+63xxxxxxxxxx\""); // Replace it with your mobile number
  SIM900.println(message);   // The SMS text you want to send
  SIM900.println((char)26);  // ASCII code of CTRL+Z

I have already replaced the x’s with my number and the wirings are also correct if you’d ask.

Can anyone help me with this problem? I have already tried simpler codes that only focus on sending and receiving messages with the module but still, no luck. Thank you in advance!

I have what you want to do working with a Arduino Mega and a SIM7000E modem. It took hours to get everything working reliably - and ended up not using the modem libraries and process everything myself.

your modem response


is suspicious. I recommend to get the modem AT command manual and carefully check what is expected at reset. Note when using software-serial, often characters in communication are lost - leading to things not working at all.

I get the following with the SIM7000E at power on reset:

+CFUN: 1    

and then I need to enter the PIN code.

Good luck, let me know.


Hi ,
Try that
Doesn’t matter in software is SIM800. Commands are the same.
Install FONA library , from Sketch → Include library → Manage library. Type FONA and install Adafruit FONA library.
Change in software Pin number according your set-up.

Also check this :

  Tutorial: Control servo movement with gesture using ESP32 and Arduino
  - TTGO T-Call ESP32 with SIM800L GPRS Module
  - 1CH Active H/L 5V OptoCoupler Relay Module
  Connections   TTGO | Servo
                  5V - DC+
                 GND - DC-
                  IN - 14
  External libraries:
  - Adafruit Fona Library by Adafruit Version 1.3.5

#include "Adafruit_FONA.h"

#define SIM800L_RX     7
#define SIM800L_TX     8
#define SIM800L_PWRKEY 4
#define SIM800L_RST    5
#define SIM800L_POWER  23

char replybuffer[255];

HardwareSerial *sim800lSerial = &Serial1;
Adafruit_FONA sim800l = Adafruit_FONA(SIM800L_PWRKEY);

uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);

#define LED_BLUE  14
#define RELAY 13

String smsString = "";
//char imei2[16]  = {866782042363462} ;

void setup()
  pinMode(LED_BLUE, OUTPUT);
  pinMode(RELAY, OUTPUT);
  pinMode(SIM800L_POWER, OUTPUT);

  digitalWrite(LED_BLUE, HIGH);
  digitalWrite(SIM800L_POWER, HIGH);

  Serial.println(F("ESP32 with GSM SIM800L"));
  Serial.println(F("Initializing....(May take more than 10 seconds)"));

  // Make it slow so its easy to read!
  sim800lSerial->begin(4800, SERIAL_8N1, SIM800L_TX, SIM800L_RX);
  if (!sim800l.begin(*sim800lSerial)) {
    Serial.println(F("Couldn't find GSM SIM800L"));
    while (1);
  Serial.println(F("GSM SIM800L is OK"));
  char imei[16] = {0}; // MUST use a 16 character buffer for IMEI!
  uint8_t imeiLen = sim800l.getIMEI(imei);
  if (imeiLen > 0) {
    Serial.print("GSM IMEI: "); Serial.println(imei);
  char* imei2[16] = {imei};
   // if (imei!= imei2){
      Serial.println("GSM IMEI nu este bun!! "); 
   // }

  // Set up the FONA to send a +CMTI notification
  // when an SMS is received
  Serial.println("GSM SIM800L Ready");

long prevMillis = 0;
int interval = 1000;
char sim800lNotificationBuffer[64];          //for notifications from the FONA
char smsBuffer[250];
boolean ledState = false;

void loop()
  if (millis() - prevMillis > interval) {
    ledState = !ledState;
    digitalWrite(LED_BLUE, ledState);

    prevMillis = millis();
  char* bufPtr = sim800lNotificationBuffer;    //handy buffer pointer

  if (sim800l.available()) {
    int slot = 0; // this will be the slot number of the SMS
    int charCount = 0;

    // Read the notification into fonaInBuffer
    do {
      *bufPtr =;
    } while ((*bufPtr++ != '\n') && (sim800l.available()) && (++charCount < (sizeof(sim800lNotificationBuffer)-1)));
    //Add a terminal NULL to the notification string
    *bufPtr = 0;

    //Scan the notification string for an SMS received notification.
    //  If it's an SMS message, we'll get the slot number in 'slot'
    if (1 == sscanf(sim800lNotificationBuffer, "+CMTI: \"SM\",%d", &slot)) {
      Serial.print("slot: "); Serial.println(slot);
      char callerIDbuffer[32];  //we'll store the SMS sender number in here
      // Retrieve SMS sender address/phone number.
      if (!sim800l.getSMSSender(slot, callerIDbuffer, 31)) {
        Serial.println("Didn't find SMS message in slot!");
      Serial.print(F("FROM: ")); Serial.println(callerIDbuffer);

      // Retrieve SMS value.
      uint16_t smslen;
      // Pass in buffer and max len!
      if (sim800l.readSMS(slot, smsBuffer, 250, &smslen)) {
        smsString = String(smsBuffer);
        Serial.print(F("FROM: ")); 
        Serial.print("MESAGE SMS : ");

      if (smsString.equalsIgnoreCase("RELAY ON")) {
        Serial.println("Relay is activated.");
        digitalWrite(RELAY, HIGH);
        // Send SMS for status
        if (!sim800l.sendSMS(callerIDbuffer, "Relay is activated.")) {
         } else {
      else if (smsString.equalsIgnoreCase("RELAY OFF")) {
        Serial.println("Relay is deactivated.");
        digitalWrite(RELAY, LOW);
        // Send SMS for status
        if (!sim800l.sendSMS(callerIDbuffer, "Relay is deactivated.")) {
        } else {

      while (1) {
        if (sim800l.deleteSMS(slot)) {
          Serial.print(F("Quality signal  "));
        else {
          Serial.print(F("Couldn't delete SMS in slot ")); Serial.println(slot);
          Serial.print(F("Quality signal "));

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.