SIM7600G 4G LTE GSM Module also compatible with 2G and 3G Networks
Table of Contents
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.
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.
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.
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.
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.
And it is smaller than the SIM900A module, but still, it neither has GPS nor supports 3G and 4G networks.
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.
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.
For now, we don’t need to connect this GPS antenna. But very soon I will use it for the real-time GPS tracking.
Amazon Links:
ESP32 WiFi + Bluetooth Module(Recommended)
ESP32 WiFi + Bluetooth Module from Aliexpress
MLX90614 Non-contact Infrared Temperature Sensor
*Disclosure: These are affiliate links. As an Amazon Associate I earn from qualifying purchases.
For demonstration purposes, I have connected the MLX90614 non-contact infrared temperature sensor.
and a 4-channel 5V Solid-state relays module
that I am going to use to control these 110/220Vac bulbs.
Instead of using solid-state relays, you can also use these SPDT type relays module.
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.
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.
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.
You can see when I turn ON or turn OFF a relay; I also get a feedback message.
I can also request the temperature reading at anytime.
SIM7600G LTE GSM module interfacing with ESP32:
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.
You might find this wiring quite congested and confusing, but there’s no need to worry.
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.
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.
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.
On the right side, I could also see the DFM checklist, which detected DFM problems. I fixed all the related issues,
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.
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.
then go to the sketch menu > Include Library > and then click on the Mange Libraries.
paste the library name in the search box. As you can see I have already installed this library.
Now, follow the same exact steps for the DFRobot_MLX90614 library. As you can see, I have also installed this library.
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.
For this you can read my Getting Started article on the ESP32 board installation.
SIM7600G LTE GSM ESP32 Programming:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
#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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
#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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
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:
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
Hi, i have same issues…
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 сообщения удалены.”));
}