1. Connect the Current Sensor:
- Connect the output of the current sensor to an analog pin on the ESP32-C5.
- Connect the power and ground pins of the current sensor to the corresponding pins on the ESP32-C5.
2. Connect the Voltage Sensor:
- Connect the output of the voltage sensor to an analog pin on the ESP32-C5.
- Connect the power and ground pins of the voltage sensor to the corresponding pins on the ESP32-C5.
3. Connect the OLED Display (Optional):
- Connect the SDA and SCL pins of the OLED display to the corresponding pins on the ESP32-C5.
- Connect the power and ground pins of the OLED display to the corresponding pins on the ESP32-C5.
4. Programming:
Write a program in Arduino IDE using the ESP32 board support package. Utilize libraries for the OLED display, MQTT communication, and sensor readings.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <PubSubClient.h>
#include <WiFi.h>
// Define Wi-Fi and MQTT parameters
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
const char* mqtt_server = "your_MQTT_BROKER_IP";
// Define OLED display parameters
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Define current and voltage sensor pins
const int currentSensorPin = A0;
const int voltageSensorPin = A1;
// MQTT Client
WiFiClient espClient;
PubSubClient client(espClient);
void setup() {
// Initialize OLED display
if(!display.begin(SSD1306_I2C, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(250);
Serial.print(".");
}
Serial.println("WiFi connected");
// Connect to MQTT Broker
client.setServer(mqtt_server, 1883);
}
void loop() {
// Read current and voltage values
float current = analogRead(currentSensorPin) * (5.0 / 1023.0);
float voltage = analogRead(voltageSensorPin) * (5.0 / 1023.0) * 230.0;
// Calculate power consumption
float power = current * voltage;
// Display readings on OLED (optional)
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
display.print("Power: ");
display.print(power, 2);
display.print(" W");
display.display();
// Publish readings to MQTT Broker
if (client.connected()) {
client.publish("home/power", String(power).c_str());
}
delay(1000); // Adjust delay as needed
}
Optional Features:
- Implement deep sleep mode to conserve energy.
- Add multiple sensors for monitoring different areas.
- Integrate the energy monitor with a cloud platform for remote monitoring.
The microcontrollers serve as Internet communication devices for builders, yet the ESP32 stands out. Developing a Smart Home Energy Monitor with the ESP32-C5 provides an efficient solution for homeowners to monitor and optimize their energy consumption. This project showcases the capabilities of the ESP32-C5 in IoT applications and can serve as a foundation for expanding into more complex smart home projects.










_3tlg8LVgA6.png?auto=compress%2Cformat&w=40&h=40&fit=fillmax&bg=fff&dpr=2)

_3u05Tpwasz.png?auto=compress%2Cformat&w=40&h=40&fit=fillmax&bg=fff&dpr=2)
Comments