The circuit is designed to monitor voltage and current, calculate power, and control lighting systems. It includes current sensors, voltage sensors, LED bulbs, a microcontroller (ESP32), a GSM module for communication, relays for controlling the lights, a battery charging module, and power supplies. The ESP32 microcontroller is programmed to read sensor data, calculate power, and send notifications via the GSM module based on predefined conditions. It also responds to SMS commands to control the lights through the relay module.
/*
* 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("A, Power 1: ");
gsm.print(power1);