diy esp32 power meter

DIY ESP32 Power Meter: Monitor Your Energy Consumption

By Hannah Harris
AD

Ever wondered how much power your gadgets consume, or want to keep an eye on your home's energy usage? Building a DIY ESP32 power meter can help you monitor and understand your energy consumption better, all while learning about microcontrollers and power electronics. This article will guide you through the process, from understanding the theory behind power meters to soldering and programming your ESP32.

The ESP32, with its dual-core processor, Wi-Fi, and Bluetooth connectivity, is an excellent choice for building IoT projects like a power meter. By measuring the current and voltage, we can calculate the power consumption and send the data to a smartphone app or a cloud service.

Theory of Power Measurement

Before diving into the DIY aspect, let's first understand the theory behind power meters.

AD
GitHub - danpeig/ESP32EnergyMonitor: Multiple phase DIY energy consumption monitor using ESP32 and ESPHome
GitHub - danpeig/ESP32EnergyMonitor: Multiple phase DIY energy consumption monitor using ESP32 and ESPHome
DIY Smart Energy Meter With ESP32 + Home Assistant
DIY Smart Energy Meter With ESP32 + Home Assistant
IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
IoT AC Energy Meter with PZEM-004T & ESP32 WebServer

Power (P) is calculated using the formula P = U * I, where U is the voltage and I is the current. To measure power, we need to sense both voltage and current. In this project, we'll use a non-intrusive current transformer (CT) for current sensing and a simple voltage divider for voltage sensing.

Current Transformers (CT)

Current transformers areused to step down high currents to a safe, measurable level. They consist of a toroidal core with a primary winding (usually consisting of a single turn, i.e., the wire carrying the current) and a secondary winding with many turns. The current in the secondary winding is proportional to the current in the primary winding.

DIY Smart Energy Meter With ESP32 + Home Assistant
DIY Smart Energy Meter With ESP32 + Home Assistant
How to Power the ESP32 Correctly ⚡
How to Power the ESP32 Correctly ⚡
DIY Home Energy Monitor with ESP32, CT Sensor (SCT-013), and EmonLib
DIY Home Energy Monitor with ESP32, CT Sensor (SCT-013), and EmonLib

The turns ratio (N) of the transformer and the burden resistor (R) determine the sensitivity and the voltage output. You can calculate the output voltage (Vout) using the formula Vout = (N * Iprimary * R) / (sqrt(1 + (ω * L * C) + (R * R) / (ω * L)))), where ω is the angular frequency, L is the inductance of the secondary winding, and C is the parasitic capacitance.

Voltage Divider

A voltage divider is an electrical circuit that produces an output voltage (Vout) that is a fraction of the input voltage (Vin). It consists of two resistors (R1 and R2) connected in series. The output voltage is taken from a point between the two resistors.

AD

The output voltage can be calculated using the formula Vout = (R2 / (R1 + R2)) * Vin. In our case, we'll choose R1 and R2 such that the output voltage is within the safe input voltage range of the ESP32 ADC (0 to 3.3V).

DIY Real Energy Meter With Arduino and ESP8266
DIY Real Energy Meter With Arduino and ESP8266
Make Your Own Power Meter/Logger
Make Your Own Power Meter/Logger
Home Power Monitor
Home Power Monitor
ESP32 based energy meter
ESP32 based energy meter
DIY Zigbee Temperature and Humidity Meter with XIAO ESP32C6✨
DIY Zigbee Temperature and Humidity Meter with XIAO ESP32C6✨
Build a Power Meter with ESPHome and INA219
Build a Power Meter with ESPHome and INA219

Building the DIY ESP32 Power Meter

Now that we've covered the theory let's dive into the practical aspects of building the DIY ESP32 power meter.

The bill of materials for this project includes an ESP32 development board, a current transformer, a burden resistor, two resistors for the voltage divider, some jumper wires, and a breadboard to connect everything together.

AD

Hardware Setup

Connect the secondary winding of the current transformer to the burden resistor and one of the ESP32 ADC inputs (e.g., GPIO35). Connect the voltage divider to another ADC input (e.g., GPIO34). Ground both the CT secondary and the voltage divider. Connect the rest of the ESP32 pins as needed (e.g., power, reset, and any LEDs or buttons you want to add).

DIY ESP32 Wearable: DRM Watch 3 (Suitable for Daily Use)
DIY ESP32 Wearable: DRM Watch 3 (Suitable for Daily Use)
10 ESP32 Skills Every Maker Should Learn
10 ESP32 Skills Every Maker Should Learn
Energy Monitor with ESP32
Energy Monitor with ESP32
Home Assistant/ESPHome LED Matrix Temperature and Power Meter
Home Assistant/ESPHome LED Matrix Temperature and Power Meter
Building a Smart Energy Meter With ESP32 and MQTT Alerts
Building a Smart Energy Meter With ESP32 and MQTT Alerts
Simulate ESP32 Projects in VS Code with Wokwi (Beginner Guide!)
Simulate ESP32 Projects in VS Code with Wokwi (Beginner Guide!)
MPQ5857 + ESP32-C3 Smart Power Meter Schematic MPQ5857 + ESP32-C3 Smart Power Meter
MPQ5857 + ESP32-C3 Smart Power Meter Schematic MPQ5857 + ESP32-C3 Smart Power Meter
Reduce the ESP32 Power Consumption in 3 Simple Steps
Reduce the ESP32 Power Consumption in 3 Simple Steps
Build a Cloud-Connected ESP8266 Power Meter
Build a Cloud-Connected ESP8266 Power Meter
⏱️ ESP32 NTP Time Sync – How to Get Accurate Time via Wi-Fi!
⏱️ ESP32 NTP Time Sync – How to Get Accurate Time via Wi-Fi!
DIY Arduino Multifunction Energy Meter - Share Project - PCBWay
DIY Arduino Multifunction Energy Meter - Share Project - PCBWay
Monitoring House Power Consumption with ESP32 and Shelly Power Meter
Monitoring House Power Consumption with ESP32 and Shelly Power Meter
This ESP32 project lowers your electricity bill! DIY Smart Energy Meter
This ESP32 project lowers your electricity bill! DIY Smart Energy Meter
GitHub - lmarzen/esp32-weather-epd: A low-power E-Paper weather display powered by an ESP32 microcontroller. Utilizes the OpenWeatherMap API.
GitHub - lmarzen/esp32-weather-epd: A low-power E-Paper weather display powered by an ESP32 microcontroller. Utilizes the OpenWeatherMap API.

If you're not familiar with breadboarding, here's a step-by-step guide: 1. Insert the jumper wires into the breadboard. 2. Connect the secondary winding of the CT to one end of the burden resistor and the other end to the ESP32 ADC input. 3. Connect the two resistors of the voltage divider in series and connect their midpoint to the other ESP32 ADC input. 4. Ground both the CT secondary and the voltage divider. 5. Connect the rest of the ESP32 pins as needed. 6. Plug in the power and reset the ESP32.

Firmware and Programming

To read the ADC values and calculate the power, we'll use the Arduino IDE and the ESP32 board manager. Here's a simple sketch to get you started:

AD

```cpp const int voltagePin = 34; const int currentPin = 35; const float R1 = 10000.0; // Resistor value in ohms (R1) const float R2 = 4700.0; // Resistor value in ohms (R2) const float burdenResistor = 470.0; // Burden resistor value in ohms const float A = (R2 / (R1 + R2)); // Voltage divider constant const float B = (0.01 * 230.0 * burdenResistor); // Current transformer constant void setup() { Serial.begin(115200); } void loop() { int voltage = analogRead(voltagePin); int current = analogRead(currentPin); float V = (voltage * 3.3) / 4095.0; // Convert ADC value to voltage float I = (current * 3.3) / (4095.0 * B); // Convert ADC value to current float P = V * I * 1000.0; // Calculate power in watts Serial.print("Voltage: "); Serial.print(V); Serial.print(" V, Current: "); Serial.print(I); Serial.print(" A, Power: "); Serial.print(P); Serial.println(" W"); delay(1000); } ```

This sketch reads the voltage and current, calculates the power, and prints the results to the serial monitor. You can display the data on a smartphone using a serial-to-USB converter or send it to a cloud service using the ESP32's Wi-Fi or Bluetooth capabilities.

And there you have it - a DIY ESP32 power meter! Now you can monitor your home's energy consumption, detect appliances, and even potentially identify vampire power draw.

This project is just the beginning - you can build upon it to create a more advanced power monitoring system, or use the same principles to measure other electrical parameters. Happy tinkering!

AD