ESP32

SIM7600G 4G LTE GSM Module also compatible with 2G and 3G Networks

SIM7600G 4G LTE GSM:

SIM7600G 4G LTE GSM Module also compatible with 2G and 3G Networks- Now, it’s time to say goodbye to SIM900A, SIM800L, and all the other GSM/GPRS modules because the king of all GSM modules, the SIM7600G LTE module, has arrived in the market. It’s not only compatible with 4G networks but also backward compatible with 3G and 2G networks.

SIM7600G LTE GSM

I have used the SIM900A and SIM800L GSM modules in many projects, and there’s no doubt these modules were quite popular. However, as you know, these modules only work with 2G networks and support only 2G SIMs. As you may be aware, in most countries, 2G networks are being decommissioned, and even in countries where 2G services are currently functional, they will soon be phased out, given that we are now in the era of 4G and 5G.




So, guys, it’s time to stop using 2G network-supported GSM modules and switch to the SIM7600G LTE GSM Module. Today, you won’t find a better GSM module than this.

SIM7600G LTE GSM

Voltage is no longer an issue, as you can use a power supply ranging from 5V to 10V with the SIM7600G 4G LTE GSM Module. However, according to the manufacturer, the recommended voltage is 5V. Another amazing thing is whether you supply it with 5V or 10V; the TXD and RXD pins will remain at the 3.3V TTL level, which makes this module completely compatible with 3.3V controller boards like ESP32, ESP8266, STM32, RASPBERRY PI PICO, etc. Today, I am going to use it with the ESP32 WIFI + Bluetooth module because, in the upcoming project, I am planning to build an IoT-based project.

SIM7600G LTE GSM



Anyway, the default baud rate is 115200bps.

On the back side you will find a Micro Sim Card Socket.

LTE Antenna.

3G Antenna.

GPS Antenna.

NET Light Indicater LED (Green).

Power indicater LED (RED).

USB2.0. Interface. And

Thus is the power conversion chip.

The operation temperature is from -40oC to +85 oC.

SIM7600X-H is a complete multi-band LTE-FDD/LTE-DD/HSPA+/UMTS/EDGE/GPRS/GSM module solution in LCC type which supports LTE CAT4 up to 150Mbps for downlink and 50Mbps for uplink data transfer.

This module includes 7 distinct pins: G, R, T, K, V,G, and S.

SIM7600G LTE GSM

First up, we have ‘G,’ which stands for Ground and it should be connected to the Controller GND pin.

Next is ‘R,’ the Receive pin. This pin is used for serial communication, specifically for receiving data.

Next is ‘T,’ the Transmit pin. This is used to send data from module to the controller board. Together, ‘R’ and ‘T’ facilitate two-way serial communication.

K Pin is the PWRKEY and it is used to Power ON/OFF the module by default its shorted with the GND via R104.

Next is ‘V,’ the Voltage pin. This is where you will need to connect a 5V to 10V power supply. And as I said earlier; the recommend voltage is 5 volts.

Here’s another ‘G’ pin, and like the first one, it’s also a Ground pin. Having multiple ground pins can be helpful.

Lastly, we have ‘S,’ which stands for SLEEP, it controls module into sleep mode.



This is larger than the SIM800L GSM/GPRS module because the SIM800L does not have a voltage regulator, GPS, or support for the latest networks.

SIM7600G LTE GSM

And it is smaller than the SIM900A module, but still, it neither has GPS nor supports 3G and 4G networks.

SIM7600G LTE GSM

So, the SIM7600G is better in every aspect. It is also not expensive. You can purchase the SIM7600G module without GPS, which will reduce its price even further. I have purchased it from AliExpress but you can also find it on Amazon.

Let’s connect the Full Band LTE Antenna.

SIM7600G LTE GSM

This is the flexible PCB antenna FCP. Instead of using this, you can also use a Whip antenna, but personally, I like this Flexible PCB antenna.

SIM7600G LTE GSM



For now, we don’t need to connect this GPS antenna. But very soon I will use it for the real-time GPS tracking.

SIM7600G LTE GSM

Amazon Links:

ESP32 WiFi + Bluetooth Module

ESP32 WiFi + Bluetooth Module from Aliexpress

SIM7600G 4G LTE Module

4-Channels Solid relay module

MLX90614 Non-contact Infrared Temperature Sensor

MLX90614 from the DFRobot

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!




For demonstration purposes, I have connected the MLX90614 non-contact infrared temperature sensor.

SIM7600G LTE GSM

and a 4-channel 5V Solid-state relays module

SIM7600G LTE GSM

that I am going to use to control these 110/220Vac bulbs.

SIM7600G LTE GSM

Instead of using solid-state relays, you can also use these SPDT type relays module.

SIM7600G LTE GSM



This is a 5V and 3A power supply which I am going to use to power up the ESP32 WiFi + Bluetooth module, SIM7600G module, and the solid-state relay module.

SIM7600G LTE GSM

If you want to make your own 5V and 3A power supply then you can watch my video. I will add a link in the description.

SIM7600G LTE GSM Practical Demonstration:

I have powered up the project.

SIM7600G LTE GSM

Remember, safety first: When the 110/220Vac supply is connected, never touch the relay contacts as it can be extremely dangerous. It is important to note that when working with mains voltage, proper safety precautions should always be taken, and it is advisable to consult relevant electrical codes and standards.

We use these commands to turn on the relays,

Relay1 on

Relay2 on

Relay3 on

Relay4 on

use these commands to turn OFF the relays,

Relay1 off

Relay2 off

Relay3 off

Relay4 off

and use this command to request the temperature.

req

So, let’s go ahead and do it.

SIM7600G LTE GSM

You can see when I turn ON or turn OFF a relay; I also get a feedback message.

SIM7600G LTE GSM

I can also request the temperature reading at anytime.

SIM7600G LTE GSM

SIM7600G LTE GSM



SIM7600G LTE GSM module interfacing with ESP32:

SIM7600G LTE GSM

Connect the VCC and GND of the MLX90614 non-contact infrared temperature sensor to the ESP32 3.3V and GND. Connect the SCL and SDA pins to the GPIOs 22 and 21.

Connect the VCC and GND pins of the Solid-state relay module to the 5V and 3A power supply 5Vand GND. Connect all the 4 solid-state relays to the GPIOs 12, 13, 14, and 27.

Connect the G and V pins of the SIM7600G LTE GSM module which are the power supply pins to the 5V and 3A power supply GND and 5V. You can see this module has 2 GND pins, these are internally connected so you can use any of these two ground pins. Connect the R and T pins to the GPIOs 2 and 4. R is the receive and T is the Transmit pin.

Connect the 5V and GND from the 5V and 3A power supply to the ESP32 5V and GND pins. You can follow this circuit diagram. In the circuit diagram you can see the 5V and GND wires, these go to the 5V and 3A power supply.

This is a circuit diagram of the 5V and 3A power supply.

SIM7600G LTE GSM



You might find this wiring quite congested and confusing, but there’s no need to worry.

SIM7600G LTE GSM

I’ve already designed a PCB in Altium Designer, where I’ve added a 5V 3A power supply, headers for the sim7600G module, and a relay.

SIM7600G LTE GSM

After designing the PCB and generating the Gerber files, I used the NextPCB free Online PCB Gerber Viewer and DFM Tool HQDFM. DFM tool can help you save time for you and the manufacturers? Bring up efficiency is a big matter for all.

SIM7600G LTE GSM

Anyway, I simply dragged and dropped the Gerber files; it quickly analyzed all the file. Next, I opened the desired layers for this, you can also use the ‘Open All’ button. Anyway, I closely checked the top and bottom sides.

SIM7600G LTE GSM




On the right side, I could also see the DFM checklist, which detected DFM problems. I fixed all the related issues,

SIM7600G LTE GSM

and since NextPCB offers PCBs at quite reasonable prices, I ordered 5 PCBs along with a stencil. Only 62 dollars for the 5 PCBs, a stencil, and also includes shipping.

SIM7600G LTE GSM

This is simply amazing. Click on the PCB Quote if you want to order High-quality PCBs.



SIM7600G LTE GSM ESP32 Library Installation:

If you have seen my projects related to GSM and MLX90614 non-contact infrared temperature sensor, then I don’t think you will have any difficulty in understanding this code. Anyway, first you will need to install the libraries.

For this simply, copy the library name.

SIM7600G LTE GSM

then go to the sketch menu > Include Library > and then click on the Mange Libraries.

SIM7600G LTE GSM

paste the library name in the search box. As you can see I have already installed this library.

SIM7600G LTE GSM

Now, follow the same exact steps for the DFRobot_MLX90614 library.  As you can see, I have also installed this library.

SIM7600G LTE GSM

If you are using the ESP32 WiFi + Bluetooth module for the first time, then you will also need to install the ESP32 board in the Arduino IDE.

SIM7600G LTE GSM

For this you can read my Getting Started article on the ESP32 board installation.



SIM7600G LTE GSM ESP32 Programming:

#include "Adafruit_FONA.h"
#include <HardwareSerial.h>
#include <DFRobot_MLX90614.h>
#define SerialMon Serial
#define rxPin 4 //connect the RX pin of the sim7600 with pin 2 and TX with pin 4
#define txPin 2
HardwareSerial SerialAT(1);
const int FONA_RST = 34;

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];
 float ambientTemp; 
float objectTemp;
float temp;
HardwareSerial *fonaSerial = &SerialAT;

Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);
DFRobot_MLX90614_I2C sensor;   // instantiate an object to drive our sensor

unsigned long timeout;
char charArray[20];
unsigned char data_buffer[4] = {0};
int Relay1 = 12;
int Relay2 = 13;
int Relay3 = 14;
int Relay4 = 27;


void setup() {
  SerialMon.begin(115200);
  delay(10);
  SerialMon.println("Wait...");
 fonaSerial->begin(115200,SERIAL_8N1,rxPin, txPin, false);
  delay(600);
   while( NO_ERR != sensor.begin() ){
    Serial.println("Communication with device failed, please check connection");
    delay(3000);
  }
  Serial.println("Begin ok!");

 pinMode(Relay1,OUTPUT);
 pinMode(Relay2,OUTPUT);
 pinMode(Relay3,OUTPUT);
 pinMode(Relay4,OUTPUT);
 
  Serial.println(F("FONA SMS caller ID test"));
  Serial.println(F("Initializing....(May take 3 seconds)"));
  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");
 sensor.enterSleepMode();
  delay(50);
  sensor.enterSleepMode(false);
  delay(200);

sensor.setEmissivityCorrectionCoefficient(0.91);
ambientTemp = sensor.getAmbientTempCelsius();
objectTemp = sensor.getObjectTempCelsius();

}

void loop() {
  ambientTemp = sensor.getAmbientTempCelsius();  
  temp = sensor.getObjectTempCelsius();  
  dtostrf(temp, 6, 1, charArray); // Parameters: value, width, precision, char array
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 == "Relay1 on")  //Change "Relay1 on" to something secret like "On$@8765"
      {
        digitalWrite(Relay1, HIGH);
        delay(100);
        fona.sendSMS(callerIDbuffer,"Relay1 is Turned ON" );
     
      }
      else if(smsString == "Relay1 off") //Change "off" to something secret like "Off&%4235"
      {
        digitalWrite(Relay1, LOW);
        delay(100);
        fona.sendSMS(callerIDbuffer, "Relay1 is turned OFF");
      }

if (smsString == "Relay2 on")  //Change "Relay1 on" to something secret like "On$@8765"
      {
        digitalWrite(Relay2, HIGH);
        delay(100);
        fona.sendSMS(callerIDbuffer,"Relay2 is Turned ON" );
     
      }
      else if(smsString == "Relay2 off") //Change "off" to something secret like "Off&%4235"
      {
        digitalWrite(Relay2, LOW);
        delay(100);
        fona.sendSMS(callerIDbuffer, "Relay2 is Turned OFF");
      }

if (smsString == "Relay3 on")  //Change "Relay1 on" to something secret like "On$@8765"
      {
        digitalWrite(Relay3, HIGH);
        delay(100);
        fona.sendSMS(callerIDbuffer,"Relay3 is Turned ON" );
     
      }
      else if(smsString == "Relay3 off") //Change "off" to something secret like "Off&%4235"
      {
        digitalWrite(Relay3, LOW);
        delay(100);
        fona.sendSMS(callerIDbuffer, "Relay3 is Turned OFF");
      }

      if (smsString == "Relay4 on")  //Change "Relay1 on" to something secret like "On$@8765"
      {
        digitalWrite(Relay4, HIGH);
        delay(100);
        fona.sendSMS(callerIDbuffer,"Relay4 is Turned ON" );
     
      }
      else if(smsString == "Relay4 off") //Change "off" to something secret like "Off&%4235"
      {
        digitalWrite(Relay4, LOW);
        delay(100);
        fona.sendSMS(callerIDbuffer, "is Turned OFF");
      }

       else if(smsString == "req") 
      {
        fona.sendSMS(callerIDbuffer, charArray);
      }
      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"));
      }
    }  
  }
}



SIM7600G LTE GSM Code Explanation:

#include "Adafruit_FONA.h"

#include <HardwareSerial.h>

#include <DFRobot_MLX90614.h>

#define SerialMon Serial

#define rxPin 4 //connect the RX pin of the sim7600 with pin 2 and TX with pin 4

#define txPin 2

HardwareSerial SerialAT(1);

const int FONA_RST = 34;




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];

 float ambientTemp;

float objectTemp;

float temp;

HardwareSerial *fonaSerial = &SerialAT;




Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);

DFRobot_MLX90614_I2C sensor;   // instantiate an object to drive our sensor




unsigned long timeout;

char charArray[20];

unsigned char data_buffer[4] = {0};

int Relay1 = 12;

int Relay2 = 13;

int Relay3 = 14;

int Relay4 = 27;

These include Adafruit_FONA.h, HardwareSerial.h, and DFRobot_MLX90614.h, which are essential for interfacing with the FONA 3G module and the MLX90614 infrared temperature sensor. The code also defines serial monitor and pin configurations such as SerialMon, rxPin, and txPin for communication with the SIM7600. SerialAT is particularly important as it represents a hardware serial instance for communicating with the FONA module.

Regarding hardware and constant definitions, the pins FONA_RST, Relay1, Relay2, Relay3, and Relay4 are designated for resetting the FONA and controlling relays. The fonaSerial variable acts as a pointer to the serial interface of the FONA, while fona is an instance of the Adafruit FONA 3G library, critical for cellular operations. Additionally, the sensor variable is an instance of the MLX90614 sensor, integral for temperature measurements.

The code also includes various buffers and temporary variables. replybuffer, fonaNotificationBuffer, and smsBuffer are used for storing strings and messages. Variables such as ambientTemp, objectTemp, and temp are reserved for temperature readings. charArray is a utility for converting numerical data into string format, and data_buffer serves as a general buffer for data communication. Lastly, smsString is used to store SMS messages received by the system. These components together form a comprehensive system for managing temperature readings and relay control via SMS communication.




void setup() {

  SerialMon.begin(115200);

  delay(10);

  SerialMon.println("Wait...");

 fonaSerial->begin(115200,SERIAL_8N1,rxPin, txPin, false);

  delay(600);

   while( NO_ERR != sensor.begin() ){

    Serial.println("Communication with device failed, please check connection");

    delay(3000);

  }

  Serial.println("Begin ok!");




 pinMode(Relay1,OUTPUT);

 pinMode(Relay2,OUTPUT);

 pinMode(Relay3,OUTPUT);

 pinMode(Relay4,OUTPUT);




  Serial.println(F("FONA SMS caller ID test"));

  Serial.println(F("Initializing....(May take 3 seconds)"));

  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");

 sensor.enterSleepMode();

  delay(50);

  sensor.enterSleepMode(false);

  delay(200);




sensor.setEmissivityCorrectionCoefficient(0.91);

ambientTemp = sensor.getAmbientTempCelsius();

objectTemp = sensor.getObjectTempCelsius();




}

The setup() function in your code is meticulously crafted to configure a system that integrates serial communication, temperature sensing, and control of external devices such as relays. It begins with the initialization of the serial monitor using SerialMon.begin(115200);, setting up a baud rate of 115200 which is a standard for debugging and communicating with the computer. A brief delay of 10 milliseconds ensures that the serial communication is properly established, followed by a prompt on the serial monitor indicating the commencement of the setup process.

Next, the function proceeds to initialize the FONA module’s serial communication. This is accomplished through fonaSerial->begin(115200, SERIAL_8N1, rxPin, txPin, false);, specifying a baud rate of 115200 and a data format of 8 data bits, no parity, and 1 stop bit, tailored for the RX and TX pins. A 600-millisecond delay is included to allow ample time for the FONA module to activate.

Attention is then shifted to the sensor initialization. A while loop diligently checks if the MLX90614 sensor successfully starts, indicated by sensor.begin() returning NO_ERR. Should there be an issue, an error message is displayed and the system pauses for 3 seconds before reattempting, ensuring a reliable start-up.

For controlling external devices, the function sets specific pins (Relay1 to Relay4) as outputs using pinMode(). These pins are likely linked to relays, enabling their control to switch on or off.

In the realm of FONA SMS configuration, the code includes diagnostic prints to the serial monitor, signaling the start of the FONA SMS caller ID test and initialization. Crucial to this section is the conditional if (! fona.begin(*fonaSerial)), which attempts to initialize the FONA module. Failure to do so triggers an error message and halts the program in an infinite loop, ensuring that the system does not proceed with an improperly configured module.

Further configuring the FONA module, the function sends an AT command (AT+CNMI=2,1\r\n) to set up SMS notifications, a critical step for the intended SMS-based control mechanism.

Finally, the sensor configuration is addressed. The code toggles the MLX90614 sensor’s power mode between sleep and active states, followed by setting an emissivity correction coefficient to 0.91, vital for precise temperature readings. The function concludes by reading and storing ambient and object temperatures into ambientTemp and objectTemp, prepping the system for its operational phase. This comprehensive setup ensures a robust and responsive system, primed for effective communication and control in its application environment.



void loop() {

  ambientTemp = sensor.getAmbientTempCelsius(); 

  temp = sensor.getObjectTempCelsius(); 

  dtostrf(temp, 6, 1, charArray); // Parameters: value, width, precision, char array

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 == "Relay1 on")  //Change "Relay1 on" to something secret like "On$@8765"

      {

        digitalWrite(Relay1, HIGH);

        delay(100);

        fona.sendSMS(callerIDbuffer,"Relay1 is Turned ON" );

    

      }

      else if(smsString == "Relay1 off") //Change "off" to something secret like "Off&%4235"

      {

        digitalWrite(Relay1, LOW);

        delay(100);

        fona.sendSMS(callerIDbuffer, "Relay1 is turned OFF");

      }




if (smsString == "Relay2 on")  //Change "Relay1 on" to something secret like "On$@8765"

      {

        digitalWrite(Relay2, HIGH);

        delay(100);

        fona.sendSMS(callerIDbuffer,"Relay2 is Turned ON" );

    

      }

      else if(smsString == "Relay2 off") //Change "off" to something secret like "Off&%4235"

      {

        digitalWrite(Relay2, LOW);

        delay(100);

        fona.sendSMS(callerIDbuffer, "Relay2 is Turned OFF");

      }




if (smsString == "Relay3 on")  //Change "Relay1 on" to something secret like "On$@8765"

      {

        digitalWrite(Relay3, HIGH);

        delay(100);

        fona.sendSMS(callerIDbuffer,"Relay3 is Turned ON" );

    

      }

      else if(smsString == "Relay3 off") //Change "off" to something secret like "Off&%4235"

      {

        digitalWrite(Relay3, LOW);

        delay(100);

        fona.sendSMS(callerIDbuffer, "Relay3 is Turned OFF");

      }




      if (smsString == "Relay4 on")  //Change "Relay1 on" to something secret like "On$@8765"

      {

        digitalWrite(Relay4, HIGH);

        delay(100);

        fona.sendSMS(callerIDbuffer,"Relay4 is Turned ON" );

    

      }

      else if(smsString == "Relay4 off") //Change "off" to something secret like "Off&%4235"

      {

        digitalWrite(Relay4, LOW);

        delay(100);

        fona.sendSMS(callerIDbuffer, "is Turned OFF");

      }




       else if(smsString == "req")

      {

        fona.sendSMS(callerIDbuffer, charArray);

      }

      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"));

      }

    } 

  }

}

In the void loop() function of your code, the primary operations of your system are executed, primarily focusing on continuously monitoring for and responding to incoming SMS messages. This involves controlling relays and providing temperature readings. The function begins by reading ambient and object temperatures using the MLX90614 sensor, storing these readings in ambientTemp and temp respectively. The object temperature is then converted into a formatted string using dtostrf() and stored in charArray for later use.

The next crucial part of the function is SMS handling, where it checks for data availability from the FONA module. If data is present, it is read and stored into fonaNotificationBuffer. The function meticulously parses this buffer to identify SMS notifications, specifically looking for a format that includes the slot number where the SMS is stored. Upon detecting an SMS, it retrieves the sender’s number and the SMS content, storing them in callerIDbuffer and smsBuffer.

The function then moves to a critical phase of relay control and SMS response. It examines the content of the received SMS (smsString) and compares it with predefined commands like “Relay1 on” or “Relay1 off”. Depending on the command, it controls the state of the corresponding relay using digitalWrite(), and subsequently sends a confirmation SMS back to the sender.

A unique feature of the system is its ability to handle a special command for temperature requests. If an SMS contains a command like “req”, the system responds by sending back the current temperature reading from charArray via SMS.

Finally, the function concludes by attempting to delete the processed SMS from the FONA module’s memory, thereby conserving space. It also outputs a message to the serial monitor indicating the success or failure of the SMS deletion process. Overall, this loop function forms the backbone of a responsive and interactive system capable of remote relay control and temperature monitoring through SMS commands. So, thats all about the SIM7600G LTE GSM module.



Watch Video Tutorial:

 

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

3 Comments

  1. hello, fahed, thank you for this wonderful tutorial!
    I have a small problem receiving messages, error “+FULL SMS” I deleted all the messages, but still the same thing! do you have an idea on the solution? Thank you for your answer. Have a good day

    1. I fifed with this code
      Serial.println(F(“Очистка всех SMS сообщений…”));
      // Установка формата текстового режима для чтения сообщений
      fona.sendCheckReply(F(“AT+CMGF=1”), F(“OK”), 20000);

      // Выбор хранилища сообщений
      fona.sendCheckReply(F(“AT+CPMS=\”SM\””), F(“OK”), 20000);

      // Чтение списка всех сообщений для получения их индексов
      fonaSerial->println(“AT+CMGL=\”ALL\””);
      delay(1000); // Даем время на получение ответа

      bool foundSMS = false;
      // Предполагаем, что у нас есть функция для чтения ответов от FONA, здесь используем упрощенный подход
      while (fonaSerial->available()) {
      String line = fonaSerial->readStringUntil(‘\n’);
      if (line.startsWith(“+CMGL: “)) {
      foundSMS = true;
      int index = line.substring(7, line.indexOf(‘,’)).toInt(); // Получаем индекс сообщения
      Serial.print(F(“Удаляем сообщение с индексом: “));
      Serial.println(index);

      // Формируем команду для удаления сообщения
      String delCmd = “AT+CMGD=” + String(index);
      fonaSerial->println(delCmd);
      delay(500); // Даем время на выполнение команды
      }
      }

      if (!foundSMS) {
      Serial.println(F(“Сообщения для удаления не найдены.”));
      } else {
      Serial.println(F(“Все SMS сообщения удалены.”));
      }

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button