This project demonstrates a SIM based 4G LTE Home Automation System that works without WiFi.
Instead of using router-based IoT, this system uses:
ESP32
- ESP32
4G LTE Module (SIM7600 / A7670C)
- 4G LTE Module (SIM7600 / A7670C)
HTTP Cloud Communication
- HTTP Cloud Communication
Web Dashboard
- Web Dashboard
Relay Control
- Relay Control
It is designed for:
Farms
- Farms
Remote water pumps
- Remote water pumps
Industrial control
- Industrial control
Street light automation
- Street light automation
Villages without broadband
- Villages without broadband
Component
Specification
ESP32 Dev Board
38 Pin or 30 Pin
4G LTE Module
SIM7600 / A7670C
Active SIM Card
4G Data Enabled
Relay Module
4 Channel 5V
Power Supply
5V 2A (ESP32)
Power Supply (LTE)
5V 2A or 12V (module specific)
โ ๏ธ Important Power NoteLTE modules draw high current (up to 2A peak).
Do NOT power LTE module from ESP32 5V pin.
- Do NOT power LTE module from ESP32 5V pin.
Use dedicated stable power supply.
- Use dedicated stable power supply.
ESP32
LTE Module
TX2 (GPIO17)
RX
RX2 (GPIO16)
TX
GND
GND
Use Serial2 for communication.
๐ ESP32 โ Relay ModuleESP32 GPIO
Relay
GPIO 4
IN1
GPIO 5
IN2
GPIO 18
IN3
GPIO 19
IN4
GND
GND
Relay VCC โ 5V external supply.
๐ 4. Software ArchitectureUser โ Web Dashboard โ Server API โ LTE Network โ ESP32 โ Relay
Communication protocol: HTTP GET & POST
๐ป 5. Server Side Setup (Important)You need:
Hosting (Shared hosting / VPS)
- Hosting (Shared hosting / VPS)
MySQL database
- MySQL database
PHP API files
- PHP API files
Create table:
CREATE TABLE relay_control (id INT PRIMARY KEY AUTO_INCREMENT,r1 INT DEFAULT 0,r2 INT DEFAULT 0,r3 INT DEFAULT 0,r4 INT DEFAULT 0);
CREATE TABLE relay_control (
id INT PRIMARY KEY AUTO_INCREMENT,
r1 INT DEFAULT 0,
r2 INT DEFAULT 0,
r3 INT DEFAULT 0,
r4 INT DEFAULT 0
);
Insert initial row:
INSERT INTO relay_control (r1, r2, r3, r4) VALUES (0, 0, 0, 0);
INSERT INTO relay_control (r1,r2,r3,r4) VALUES (0,0,0,0);
๐ getRelayState.php<?php$conn = new mysqli("localhost", "user", "pass", "database");$result = $conn->query("SELECT * FROM relay_control WHERE id=1");$row = $result->fetch_assoc();echo "R1=".$row['r1'].", R2=".$row['r2'].", R3=".$row['r3'].", R4=".$row['r4'];?>
<?php
$conn = new mysqli("localhost","user","pass","database");
$result = $conn->query("SELECT * FROM relay_control WHERE id=1");
$row = $result->fetch_assoc();
echo "R1=".$row['r1'].",R2=".$row['r2'].",R3=".$row['r3'].",R4=".$row['r4'];
?>
๐ updateRelay.php<?php$conn = new mysqli("localhost", "user", "pass", "database");$r1 = $_GET['r1'];$r2 = $_GET['r2'];$r3 = $_GET['r3'];$r4 = $_GET['r4'];$conn->query("UPDATE relay_control SET r1=$r1, r2=$r2, r3=$r3, r4=$r4 WHERE id=1");echo "Updated";?>
<?php
$conn = new mysqli("localhost","user","pass","database");
$r1 = $_GET['r1'];
$r2 = $_GET['r2'];
$r3 = $_GET['r3'];
$r4 = $_GET['r4'];
$conn->query("UPDATE relay_control SET r1=$r1,r2=$r2,r3=$r3,r4=$r4 WHERE id=1");
echo "Updated";
?>
๐ก 6. LTE Module AT Command FlowStep 1 โ Check CommunicationAT
AT
Expected Response:
OK
OK
Step 2 โ Check SIMAT+CPIN?
AT+CPIN?
Response:
READY
READY
Step 3 โ Network RegistrationAT+CREG?
AT+CREG?
Response:
0, 1 (Registered)
0,1 (Registered)
Step 4 โ Set APNExample Airtel:
AT+CGDCONT=1, "IP", "airtelgprs.com"
AT+CGDCONT=1,"IP","airtelgprs.com"
Step 5 โ Activate PDPAT+CGATT=1AT+CGACT=1, 1
AT+CGATT=1
AT+CGACT=1,1
After this module gets IP and internet is active.
๐ง 7. ESP32 Firmware Logic๐ Main Loop LogicInitialize LTE
- Initialize LTE
Connect to network
- Connect to network
Send HTTP GET request
- Send HTTP GET request
Parse response
- Parse response
Update relays
- Update relays
Delay 3โ5 seconds
- Delay 3โ5 seconds
Repeat
- Repeat
#include <HardwareSerial.h>HardwareSerial sim(2);void setup() { Serial.begin(115200); sim.begin(115200, SERIAL_8N1, 16, 17);}void loop() { sim.println("AT"); delay(1000); while(sim.available()){ Serial.write(sim.read()); } delay(5000);}
#include <HardwareSerial.h>
HardwareSerial sim(2);
void setup() {
Serial.begin(115200);
sim.begin(115200, SERIAL_8N1, 16, 17);
}
void loop() {
sim.println("AT");
delay(1000);
while(sim.available()){
Serial.write(sim.read());
}
delay(5000);
}
You will expand this for:
HTTP initialization
- HTTP initialization
URL call
- URL call
Reading HTTP response
- Reading HTTP response
Parsing relay data
- Parsing relay data
For SIM7600:
AT+HTTPINITAT+HTTPPARA="URL", "http://yourdomain.com/getRelayState.php"AT+HTTPACTION=0AT+HTTPREAD
AT+HTTPINIT
AT+HTTPPARA="URL","http://yourdomain.com/getRelayState.php"
AT+HTTPACTION=0
AT+HTTPREAD
Parse the returned string.
๐ 9. Relay Update Logic ExampleIf response:
R1=1, R2=0, R3=1, R4=0
R1=1,R2=0,R3=1,R4=0
Then:
digitalWrite(4, HIGH);digitalWrite(5, LOW);digitalWrite(18, HIGH);digitalWrite(19, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(18, HIGH);
digitalWrite(19, LOW);
๐ก 10. Stability Features To AddIf HTTP fails โ retry
- If HTTP fails โ retry
If network lost โ reinitialize PDP
- If network lost โ reinitialize PDP
If SIM not detected โ halt relay
- If SIM not detected โ halt relay
Default relay OFF on boot
- Default relay OFF on boot
Serial debug logging enabled
- Serial debug logging enabled
Borewell motor ON/OFF
- Borewell motor ON/OFF
Street light timer system
- Street light timer system
Solar inverter remote control
- Solar inverter remote control
Factory machine control
- Factory machine control
Smart irrigation system
- Smart irrigation system
HTTPS secure requests
- HTTPS secure requests
MQTT instead of HTTP
- MQTT instead of HTTP
OTA firmware update
- OTA firmware update
Mobile app dashboard
- Mobile app dashboard
Energy monitoring integration
- Energy monitoring integration
Mr. Abhishek MauryaFounder โ Yarana IoT GuruOfficial Contact: +91-7052722734
Website: https://yaranaiotguru.in
โค๏ธ Final ConclusionThis project demonstrates a complete end-to-end 4G LTE IoT automation system that works without WiFi.
From hardware wiring to server API to AT command handling โ everything is fully controlled via cellular network.
It is ideal for remote and industrial IoT deployments.













Comments