Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-Based Smart Energy Monitoring and Relay Control System

View and Edit Project In Cirkit DesignerImage of ESP32-Based Smart Energy Monitoring and Relay Control System

Circuit Documentation

Summary

This circuit is designed to monitor voltage and current using sensors and control a series of relays based on the sensor readings. An ESP32 microcontroller is used to read sensor data and control the relays. The circuit includes voltage sensors (ZMPT101B modules), a current sensor, multiple 1-Channel 5V 10A relays, a directional switch, an electrolytic capacitor, a 12V SMPS module, resistors, a 240V power source, a 12V battery, and LED bulbs for AC.

Component List

Microcontroller

Sensors

Relays

Switches

Passive Components

Power Sources

Load

Wiring Details

ESP32 (30 pin)

ZMPT101B (Voltage Sensor)

Current Sensor

1-Channel Relay (5V 10A)

Directional Switch

Electrolytic Capacitor

Resistor

12v SMPS Module

240v Power Source

12V Battery

LED bulb AC / Bombillo AC

Documented Code

/*
 * This Arduino Sketch is for an ESP32 microcontroller.
 * It reads current and voltage values from sensors and controls relays.
 * The sensors are connected to specific GPIO pins of the ESP32.
 * The relays are also controlled via specific GPIO pins.
 */

// Pin definitions
#define VOLTAGE_SENSOR_PIN_1 4
#define VOLTAGE_SENSOR_PIN_2 5
#define CURRENT_SENSOR_PIN 34
#define RELAY_PIN_1 13
#define RELAY_PIN_2 18
#define RELAY_PIN_3 2
#define RELAY_PIN_4 12
#define RELAY_PIN_5 14

void setup() {
  // Initialize serial communication
  Serial.begin(115200);

  // Initialize sensor pins
  pinMode(VOLTAGE_SENSOR_PIN_1, INPUT);
  pinMode(VOLTAGE_SENSOR_PIN_2, INPUT);
  pinMode(CURRENT_SENSOR_PIN, INPUT);

  // Initialize relay pins
  pinMode(RELAY_PIN_1, OUTPUT);
  pinMode(RELAY_PIN_2, OUTPUT);
  pinMode(RELAY_PIN_3, OUTPUT);
  pinMode(RELAY_PIN_4, OUTPUT);
  pinMode(RELAY_PIN_5, OUTPUT);

  // Set initial state of relays to LOW
  digitalWrite(RELAY_PIN_1, LOW);
  digitalWrite(RELAY_PIN_2, LOW);
  digitalWrite(RELAY_PIN_3, LOW);
  digitalWrite(RELAY_PIN_4, LOW);
  digitalWrite(RELAY_PIN_5, LOW);
}

void loop() {
  // Read voltage sensor values
  int voltage1 = analogRead(VOLTAGE_SENSOR_PIN_1);
  int voltage2 = analogRead(VOLTAGE_SENSOR_PIN_2);

  // Read current sensor value
  int current = analogRead(CURRENT_SENSOR_PIN);

  // Print sensor values to serial monitor
  Serial.print("Voltage 1: ");
  Serial.println(voltage1);
  Serial.print("Voltage 2: ");
  Serial.println(voltage2);
  Serial.print("Current: ");
  Serial.println(current);

  // Control relays based on sensor values
  if (voltage1 > 1000) {
    digitalWrite(RELAY_PIN_1, HIGH);
  } else {
    digitalWrite(RELAY_PIN_1, LOW);
  }

  if (voltage2 > 1000) {
    digitalWrite(RELAY_PIN_2, HIGH);
  } else {
    digitalWrite(RELAY_PIN_2, LOW);
  }

  if (current > 1000) {
    digitalWrite(RELAY_PIN_3, HIGH);
  } else {
    digitalWrite(RELAY_PIN_3, LOW);
  }

  // Add more control logic as needed

  // Delay for a short period
  delay(1000);
}

This code is responsible for initializing the GPIO pins on the ESP32, reading sensor values, and controlling the state of the relays based on the sensor readings. The serial communication is used for debugging purposes to output the sensor values to the serial monitor. The relays are initially set to a LOW state, and their state is updated in the loop function based on the conditions specified.