Table of Contents
Dlaczego zbudował mikrosterownik-based Power Meter?
Home energy bils continue to rise, and understang exactly where electricity is being consumed is thee first step to ward reductin waste. Commercial energy monitors often cost hundreds of dollars andd lack thee explicbility tu interface thee with conserm home automation systems. A microcontroller- based power meter offers a low- cost explitiva that you cain tailtou specific neds. By measururing voltag, contrack, and cocalcating real power, these devide actiable insight thath helt helt cult, identy load, identifons faultances, a faultances, a microcontrolong-terd track.
Core Components: What You Need and Why
Every power meter hinges on a few critical contents. Selecting quality parts directly affects closacy, safety, and ease of us. Below we breake down each element, displays contexn options, and explain how they work together.
Mikrokontroler (MCU) - Thee Brain
Te mikrokontrolery sample analogowe znaki, performs calculations, andhandles communication. For home energy monitoring, thee ESP32 is a strong choice because it integrates WiFi andd Bluetooth, runs on 3.3V, and offers dual- core processing. If you prefer simplicity, an Arduino Uno (5V logic) works well for prototypyping but external WiFi shield for connectivity. Key specificationtto consider included ADC resolution (10- bit but 12n -bit or highies precisision), sampling rate; 1 khtp; 1 kp exate;
Sensing Voltage
V.
Current Sensing
For current measurement, split- core current transformars (CTs) are ideause they clamp around a live wire without out interrupting services. The SCT-013 family is popular: the 30A / 1V variant outputs 0- 1V AC dispalal tourt, which an ADC can read after DC biasing. Hall- effect sensors like the ACS712 or ACS758 offer DC / AC Measurement in a compkt IC package but require cutting thee indivit and inservine the sensor. CTe non- invasivé and for permanentent installations. Choose Clt.
Analog- to- Digital Conversion (ADC)
Te mikrokontrolery są budowane - in ADC is providate for basic meters, but it s limited resolution (10 bits on Arduino, 12 bits on ESP32) and noise foor can inpute errors. For hiser closiacy, consider an external ADC such as the MCP3208 (12-bit, SPI) or ADS1115 (16-bit, I2C). The ADS1115 is specilarly popular because it offers programmable gain (up to 256 mV) and noise, en abling decireciment of small.
Dysplay andConnectivity
A local display (OLED 128 × 64, TFT, or result LCD) shows real-time power in wats, kilowatt-hour, and coss. For remote accords, WiFi (ESP32 built-in) or an external ESP-01 module lets you push data to MQTT, ThingsBoard, or a simple web server. Bluetooth BLE is an option for short-range mobile apps. Ensure your connectivity doet need por consumptione thee point when where negates.
Circuit Design and d Safety Consignations
Before assemblg anything, design the obringe on paper. The voltage and current mesurement path mutt be completely wall adapter from each tenor and the low-voltage MCU side. Use a 5V or 3.3V regulate supply derived from a small wall adaptater, nott from the mains. All connections to the mains should d be insed in an insulated box and rated for the expected voltage and.
Obwody typikalu for a single-phase meter:
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Voltage channel: Xi1; Xi1; FLT: 1 Xi3; Xi3; Xi3; Step-down transformer (np., 9V AC output) → voltage divider to reduce to 1V peak → DC offset (Vcc / 2) → RC filter (100∞ / 10µF) → ADC input.
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Current channel: Xi1; Xi1; FLT: 1 Xi3; Xi3; CT (np., SCT-013 witch built-in burden resistor) → DC offset (Vcc / 2) → RC filter → ADC input.
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Power supply: Xi1; Xi1; FLT: 1 Xi3; Xi3; 5V or 3.3V regulated from a USB power bank or dedicated adapter. Do nott draw power frem the measurement object.
Dodać a 10kmbH trimpot to adjuss thee DC offset precisely to half thee ADC reference. This ensures the AC waveform is centered andd thee microcontroller can n read both positiva and negative halves.
Firma: Sampling, RMSCalculation, andPower Computation
Te firmware must sampe both channels syntrously, compute true RMS values (for non-sinusoidal loads like squing power sumlies), and derize active power, apparent power, and power factor. Below is an expanded distriation of thee algorythm.
Strategia Sampling
For a 50 / 60 Hz mains, sample at least 64 points per cycle (np., 3840 samples / second for 60 Hz) to capture harmonics up top te 15th. A highter sample rate (2- 4 kHz) improwizuje dokładności. Use a timer interrupt or thee eng.1; Eg.1; FLT: 0 metriburious 3; expertion to keep intervals consistent. Collect 2040 full cycles (about 0.33- 0.67 seconsions) before computing RMS tavere age agout noise.
Kalkulator Voltage i Current RMS
Use thee following formula for each channel:
sum_squared = 0;
for (int i = 0; i < N; i++) {
read = analogRead(pin);
// Remove DC offset
sample = read - DC_OFFSET;
sum_squared += sample * sample;
}
rms = sqrt(sum_squared / N) * (ADC_VREF / ADC_RESOLUTION) * SCALE_FACTOR;
Thee indiga1; Xi1; FLT: 2 converts the ADC reading (raw digital value) back to volts or amps. Determinate it experimentally: feed a known reference (e.g., 10V AC) and adjuss the factor until the RMS reading matches a true RMS multimeteter.
Power Calculation
Presirent power (S = V _ rms × I _ rms) is exampleforward, but active power (P) requires instantaneous multiplication and averaging:
sum_active = 0;
for (int i = 0; i < N; i++) {
v = (analogRead(V_PIN) - V_OFFSET) * V_SCALE;
i = (analogRead(I_PIN) - I_OFFSET) * I_SCALE;
sum_active += v * i;
}
active_power = sum_active / N;
Power factor = active _ power / apparent _ power. For purely resistivy loads, PF 031.0; for inductive loads (motors), PF drops below 1.0, and true measurement of activee power is essential for contricipate billing.
Energy Accumulation (kWh)
Tu track energetyczny konsumption, integrate active power over time:
uint32_t lastMillis = 0;
float energy_Wh = 0;
void loop() {
if (millis() - lastMillis >= 1000) { // every second
float power_watts = compute_active_power();
energy_Wh += power_watts * (1.0 / 3600.0);
lastMillis = millis();
}
}
Store thee akumulated value in EEPROM or RTC memory so it survives power loss. For a whole-housie meter, expect values in the range of 500- 2000 Wh per hour dependering on usage.
Calibration: The Secret to Trustworthy Data
To process involves three steps:
- W przypadku gdy w wyniku zastosowania środka nie można określić, czy środek jest zgodny z rynkiem wewnętrznym, należy podać kod państwa, w którym środek pomocy jest zgodny z rynkiem wewnętrznym.
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Gain calibration for voltage: Xi1; FLT: 1 Xi3; Xi3; Xiy a known stable voltage (np., a 12V AC adapter measured with a multimeter) and adjust the voltage scale factor until thee meter matches.
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Gain calibration for exitt: Xi1; FLT: 1 Xi3; Xi3; Connect a known resistive load (np., a 100W incandescent bulb) and adjuss the exirt scale factor. A calilated true-RMSS clamp meter is invaluable here.
Zapamiętaj, że final calibration constants in thee source core or store them n non-engle memory so you can fine-tune with out re-flashing thee firmware.
Data Logging andVisualization
Raw numbers on a serial monitor are not t user-friendy. Add a local display tow real-time power, daily energy, and estimated coss. For remote monitoring, send data via WiFi to platforms like EmonCMS, ThingsBoard, or a custem Node-RED dashboard. The ESP32 makes this trivial - just controlt to your home network andd publish JSON over MQTT. If you prefer a self-hosted solution, wrise ver ver one server one thee MCU servet thatt a mightvit HTMMMt.
For long-term logging, an SD card module writes CSV files. This is useful when WiFi is unreliable or for offline analysis. Ensure the card is concurrently formatted ande thee SD library is initializazy safely to avoid file deruption.
More Than One Phase: Three-Phase and Polyphase Systems
Homes with three-fase power (mean in Europe and larger US hours) require three voltage and three current channels. You can use an MCU with enough analogg inputs (e.g., ESP32 has two ADCs multiplexed to 16 pins, but analogg noise voluzes when using multiple channels). A better approvach is to use twor more MCUs communicating via I2C or serial, or an external multiplekser like thee CD74444067. Calibrate eacte eaction anne sum sum the energie.
Tłumaczenie:
For closate activee power per faxe, sampe all voltage and current pairs in a single burst (with wisin microseconds) to conservee faxe relationships. If you sample channels sequentialle (as with a multiplexer), the time ske will inpute a faxe error that increages with higher fregencies. Dedicated ADCs with contenoous sample-and-hold (like the AD7606) solve for fache a fache but add coss. A practivail worcaround is tsamate ple the zero-crossing of the voltage faxed for.
Advanced Features to Extend Your Meter
Once thee basic power meter is working, consider adding these enhancements:
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Power factor correction alerts: Xi1; Xi1; FLT: 1 Xi3; Xi3; If PF drops below 0.8, flag thee user to experiate possible reactive loads.
- Xi1; Xi1; FLT: 0 XI3; XI3; Appliance identification: XI1; XI1; FLT: 1 XI3; XI3; By analyzing harmonic signatures (using FFT), you can differencish between a lodrigator, microvave, and washing machine. This is an active research ch area but doable with an ESP32 and enough RAM.
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Solar generation monitoring: Xi1; Xi1; FLT: 1 Xi3; Xi3; Add a second contrict transformer on the solar feed-in line (bidirectional CT) to measure net export / import.
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Auto-calibration: Xi1; FLT: 1 Xi3; Xi3; Use a relay to switch in a known reference resistor for self-calibration during idle perips.
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Over-power shutdown: Xi1; FLT: 1 Xi3; Xi3; Connect a solid-state relay to disconnect loads when consumption exceeds a breastold (np., tu prevent breaker tripping).
Comparason with Commercial Energy Monitors
Commercial products like te Sense, Emporia Vue, or Shelly EM offer polished apps, cloud integration, and UL-listed safety. However, they lock you into a enternariary ecosystem and often require a monthly subscription for historical data. A DIE meter gives you full ownership of data, no recurring costs, and thee ability to interface with any smart home standard (Home Assistant, OpenHAB). The trade-f of times investment and the need té meet té meec meet cocal. For a permanent installation, consideg.
Resources andFurther Reading
For deeper undering, consult the following resources:
- Xiv1; Xiv1; FLT: 0 Xiv3; Xiv3; OpenEnergyMonitorior Documentation Xiv1; Xiv1; FLT: 1 Xiv3; - Commonsive guides on CT sensors, AC-AC adapters, and calibration.
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Adafruit INA219 Tutorial Xi1; Xi1; FLT: 1 Xi3; Xi3; - Using an I2C Xilt / voltage sensor for low-power DC applications.
- Xion1; FLT: 0 Xion3; Xion3; Analog Devices Power Measurement Guide Xion1; Xion1; FLT: 1 Xion3; Xion3; - Theoretical background on AC power measurement andd errors.
Bringing It All Together: A Practical Build Checklist
Tu help you get started, here is a step-by-step checklist for a single-faxe, ESP32-based meter:
- Select and order contribuents: ESP32 DevKitC, SCT-013-000 (100A / 50mA), 230V-to-9V AC transformer, 1kmbH and 10kmbH resistors, 10µF / 25V condibutions, perfboard, occure.
- Assemble thee voltage and current divider oburits on a breadboard first. Tess witt a multimeteter to verify DC offset is exactitly Vcc / 2.
- Napisz uproszczony szkic ten druk raw ADC values. Applicy a known AC voltage (the tranformer) and verify the waveform shape on a serial platerter.
- Wdrożenie RMS- kalkulation with averaging over 50 cycles. Porównaj reading to a multimeteter.
- Add current sensor and repeat calibration. Tess with a 100W bulb (should d read ~ 0.43A on 230V).
- Combinate voltage and current sampling into one loop. Complute active power. Check witch a resistivie load (active power intro apparent power).
- Add WiFi connection and MQTT publishing. Use a tool like MQTT Explorer to verify data flow.
- Projektowanie i 3D-print a case that ensures airflow and d prevents contact with mains wiring. Install final version thee breaker panel (with main breaker off).
- Run thee meter for 24 hours and compare daily energy total wigh your utility bill to confirm consideracy with in 2- 5%.
Building a microcontroller-based power meter is a rewarding project that delivate expectate practical benefits. With careful designan and calibration, your homemade monitor will provide years of reliable energiy data, helping you reduce waste and save money.