ESP32 and SIM800L-Based Smart Power Monitor with Voltage Sensors
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to monitor voltage and current using multiple sensors, control lights via a relay module, and send notifications through a GSM module. The core of the circuit is an ESP32 microcontroller, which reads data from voltage sensors, calculates power, and communicates with the GSM module to send alerts based on predefined conditions. The circuit also includes a power supply module to convert AC to DC, a battery management system, and a step-up boost converter.
Component List
Voltage Sensor
- Description: Measures voltage levels.
- Pins: Ground, Phase, Vcc, Out, Gnd
Mini AC-DC 110V-230V to 5V 700mA Module
- Description: Converts AC voltage to 5V DC.
- Pins: GND, 5v, Neutral, Life
TP4056
- Description: Battery charging and protection module.
- Pins: OUT-, B-, B+, OUT+, IN-, IN+
Ac Supply
- Description: Provides AC voltage.
- Pins: +ve, -ve
Step Up Boost 3v-5v
- Description: Boosts voltage from 3V to 5V.
- Pins: Vi, GND, Vo
3.7v Battery
- Description: Provides 3.7V power supply.
- Pins: +, -
ESP32 - 38 pins
- Description: Microcontroller with Wi-Fi and Bluetooth capabilities.
- Pins: 3V3, EN, SP, SN, G34, G35, G32, G33, G25, G26, G27, G14, G12, GND, G13, SD2, SD3, CMD, 5V, G23, G22, TXD, RXD, G21, G19, G18, G5, G17, G16, G4, G0, G2, G15, SD1, SD0, CLK
Sim800l
- Description: GSM module for sending and receiving SMS.
- Pins: NET, RST, VCC, RXD, TXD, GND
Wiring Details
Voltage Sensor
Vcc: Connected to:
- Voltage Sensor (Vcc)
- Sim800l (VCC)
- Step Up Boost 3v-5v (Vo)
- ESP32 - 38 pins (5V)
Out: Connected to:
- ESP32 - 38 pins (G25)
- ESP32 - 38 pins (G33)
- ESP32 - 38 pins (G34)
- ESP32 - 38 pins (G35)
- ESP32 - 38 pins (G32)
- ESP32 - 38 pins (G26)
Gnd: Connected to:
- Voltage Sensor (Gnd)
- Sim800l (GND)
- Step Up Boost 3v-5v (GND)
- TP4056 (OUT-)
- ESP32 - 38 pins (GND)
Mini AC-DC 110V-230V to 5V 700mA Module
- GND: Connected to TP4056 (IN-)
- 5v: Connected to TP4056 (IN+)
- Neutral: Connected to Ac Supply (-ve)
- Life: Connected to Ac Supply (+ve)
TP4056
- IN-: Connected to Mini AC-DC 110V-230V to 5V 700mA Module (GND)
- IN+: Connected to Mini AC-DC 110V-230V to 5V 700mA Module (5v)
- OUT-: Connected to Voltage Sensor (Gnd)
- OUT+: Connected to Step Up Boost 3v-5v (Vi)
- B-: Connected to 3.7v Battery (-)
- B+: Connected to 3.7v Battery (+)
Ac Supply
- -ve: Connected to Mini AC-DC 110V-230V to 5V 700mA Module (Neutral)
- +ve: Connected to Mini AC-DC 110V-230V to 5V 700mA Module (Life)
Step Up Boost 3v-5v
- Vi: Connected to TP4056 (OUT+)
- GND: Connected to Voltage Sensor (Gnd)
- Vo: Connected to Voltage Sensor (Vcc)
3.7v Battery
- -: Connected to TP4056 (B-)
- +: Connected to TP4056 (B+)
ESP32 - 38 pins
- 5V: Connected to Voltage Sensor (Vcc)
- GND: Connected to Voltage Sensor (Gnd)
- G25: Connected to Voltage Sensor (Out)
- G33: Connected to Voltage Sensor (Out)
- G34: Connected to Voltage Sensor (Out)
- G35: Connected to Voltage Sensor (Out)
- G32: Connected to Voltage Sensor (Out)
- G26: Connected to Voltage Sensor (Out)
- G17: Connected to Sim800l (TXD)
- G16: Connected to Sim800l (RXD)
Sim800l
- VCC: Connected to Voltage Sensor (Vcc)
- GND: Connected to Voltage Sensor (Gnd)
- TXD: Connected to ESP32 - 38 pins (G17)
- RXD: Connected to ESP32 - 38 pins (G16)
Code Documentation
Power Monitor (Power monitor.ino)
/*
* This Arduino Sketch is for an ESP32 microcontroller connected to two sets of
* voltage and current sensors, a GSM 800L module, and a 5V 2-channel relay.
* The code reads voltage and current values, calculates power, and sends
* notifications via GSM based on predefined conditions. It also controls
* two sets of lights via the relay module based on received SMS commands.
*/
#include <SoftwareSerial.h>
// Pin definitions
#define VOLTAGE_SENSOR_1_PIN 33
#define CURRENT_SENSOR_1_PIN 34
#define VOLTAGE_SENSOR_2_PIN 32
#define CURRENT_SENSOR_2_PIN 35
#define RELAY_IN1_PIN 22
#define RELAY_IN2_PIN 23
#define GSM_TX_PIN 17
#define GSM_RX_PIN 16
// Predefined power thresholds
const float power_calc_1 = 1000.0; // 1000W for set 1
const float power_calc_2 = 1000.0; // 1000W for set 2
// Variables to store sensor readings
float voltage1 = 0.0;
float current1 = 0.0;
float power1 = 0.0;
float voltage2 = 0.0;
float current2 = 0.0;
float power2 = 0.0;
// GSM module setup
SoftwareSerial gsm(GSM_RX_PIN, GSM_TX_PIN);
void setup() {
Serial.begin(115200);
gsm.begin(9600);
pinMode(RELAY_IN1_PIN, OUTPUT);
pinMode(RELAY_IN2_PIN, OUTPUT);
digitalWrite(RELAY_IN1_PIN, LOW);
digitalWrite(RELAY_IN2_PIN, LOW);
}
void loop() {
// Read sensors and calculate power
voltage1 = analogRead(VOLTAGE_SENSOR_1_PIN) * (5.0 / 1023.0);
current1 = analogRead(CURRENT_SENSOR_1_PIN) * (5.0 / 1023.0);
power1 = voltage1 * current1;
voltage2 = analogRead(VOLTAGE_SENSOR_2_PIN) * (5.0 / 1023.0);
current2 = analogRead(CURRENT_SENSOR_2_PIN) * (5.0 / 1023.0);
power2 = voltage2 * current2;
// Check for incoming SMS
if (gsm.available()) {
String message = gsm.readString();
if (message.indexOf("Status") >= 0) {
sendStatus();
} else if (message.indexOf("Light 1") >= 0) {
digitalWrite(RELAY_IN1_PIN, HIGH);
} else if (message.indexOf("Light 2") >= 0) {
digitalWrite(RELAY_IN2_PIN, HIGH);
}
}
// Check power thresholds and send notifications
if (power1 < power_calc_1) {
sendNotification("Power 1 below threshold");
}
if (power2 < power_calc_2) {
sendNotification("Power 2 below threshold");
}
delay(1000); // Delay for 1 second
}
void sendStatus() {
gsm.print("AT+CMGF=1\r");
delay(100);
gsm.print("AT+CMGS=\"+237671693917\"\r");
delay(100);
gsm.print("Voltage 1: ");
gsm.print(voltage1);
gsm.print("V, Current 1: ");
gsm.print(current1);
gsm.print("