SIM7600 controlling LED using ESP32

SIM7600 comes in different version. The one I am using is SIM7600G (Global) that can work with many bands. I checked here in Australia with two different providers (Telstra and Vodafone). Both sim cards worked fine.

The pin outs are quite simple. Connect four pins VCC,GND,UART(RX) and UART(TX), it will just work. This module includes proper power regulator, so we can connect 5V to the V pin. Also the TX/RX serial communication already includes necessary 3.3V level shifter. So we can connect to 3.3V ESP or STM microcontroller directly.

AT command manual, Schematic and Datasheet can be found in the following links. https://www.adrive.com/public/bPqyGe/BK-SIM7600E-H.zip

Items can be purchased from https://www.aliexpress.com/store/605000. I bought my items from https://www.aliexpress.com/item/4000224044192.html

Wiring diagram

Diagram

Picture

Arduino Fona Library

Click Sketch → Include Library → Manage Libraries...

Type Adafruit Fona in the Filter your search area

Click Install Adafruit Fona Library

Before uploading please click followings and type/select

File → Preferences → Type https://dl.espressif.com/dl/package_esp32_index.json in Additional Boards Manager URLs

Tools → Board → Boards Manager → Type esp32 and click install button next to esp32 by Espressif Systems

Tools → Board → ESP32 Arduino → ESP32 Wrover Module

Tools → Port (Select the correct port)

Arduino code

// Arduino Code
#include "Adafruit_FONA.h"
HardwareSerial SerialAT(1);

const int RELAY_PIN = 15;
const int FONA_RST = 4;

char replybuffer[255];
uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);
String smsString = "";
char fonaNotificationBuffer[64];          //for notifications from the FONA
char smsBuffer[250];

HardwareSerial *fonaSerial = &SerialAT;

Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);

void setup() 
{
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW);
  
  Serial.begin(115200);
  Serial.println(F("FONA SMS caller ID test"));
  Serial.println(F("Initializing....(May take 3 seconds)"));

  fonaSerial->begin(115200,SERIAL_8N1,16,17, false);
  if (! fona.begin(*fonaSerial))
  {
    Serial.println(F("Couldn't find FONA"));
    while(1);
  }
  Serial.println(F("FONA is OK"));
  
  fonaSerial->print("AT+CNMI=2,1\r\n");  //set up the FONA to send a +CMTI notification when an SMS is received
  Serial.println("FONA Ready");
}

void loop() 
{
  char* bufPtr = fonaNotificationBuffer;    //handy buffer pointer
  
  if (fona.available())      //any data available from the FONA?
  {
    int slot = 0;            //this will be the slot number of the SMS
    int charCount = 0;
    //Read the notification into fonaInBuffer
    do
    {
      *bufPtr = fona.read();
      Serial.write(*bufPtr);
      delay(1);
    } while ((*bufPtr++ != '\n') && (fona.available()) && (++charCount < (sizeof(fonaNotificationBuffer)-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(fonaNotificationBuffer, "+CMTI: " FONA_PREF_SMS_STORAGE ",%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 (! fona.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;
      if (fona.readSMS(slot, smsBuffer, 250, &smslen)) // pass in buffer and max len!
      { 
        smsString = String(smsBuffer);
        Serial.println(smsString);
      }

      if (smsString == "On")  //Change "On" to something secret like "On$@8765"
      {
        digitalWrite(RELAY_PIN, HIGH);
        Serial.println("LED is ON.");
        delay(100);
        fona.sendSMS(callerIDbuffer,"LED is ON." );
     
      }
      else if(smsString == "Off") //Change "On" to something secret like "Off&%4235"
      {
        digitalWrite(RELAY_PIN, LOW);
        Serial.println("LED is OFF.");
        delay(100);
        fona.sendSMS(callerIDbuffer, "LED is OFF.");
      }
       
      if (fona.deleteSMS(slot)) {
        Serial.println(F("OK!"));
      } else {
        Serial.print(F("Couldn't delete SMS in slot ")); Serial.println(slot);
        fona.print(F("AT+CMGD=?\r\n"));
      }
    }  
  }
}
// End of Arduino Code

Demonstration