🌐 এই লেখাটি বাংলায় পড়ুন: বাংলা সংস্করণ →

ESP32 smart energy meter project with AI appliance recognition (NILM) using ESP32-S3 and TinyML

Quick answer: This ESP32 smart energy meter project uses a split-core current transformer (SCT-013-000) clamped around one mains wire, plus an isolated 9 V AC transformer for voltage. The ESP32-S3 samples both waveforms on its ADC1 pins and calculates Vrms, Irms, real power, power factor and kWh. Each time the power steps up or down, an on-chip Edge Impulse (TinyML) model reads the step size, PF and harmonics and names the appliance: fan, fridge, AC, iron, rice cooker, LED TV or water pump.

Advertisements

This is a reference design for B.Sc. final-year and M.Sc. students. It covers the physics, a circuit diagram with verified pins, the burden and divider maths, a BOM in BDT, calibration, the key firmware pieces and mains safety. For CT basics, see our guide to CT current measurement with a microcontroller ADC. This post does not repeat it.

Why this ESP32 smart energy meter project matters in Bangladesh (2026)

In June 2026 the regulator raised the weighted average retail tariff by Tk 1.52 to Tk 10.63 per kWh, a 16.68% increase (The Business Standard). Prepaid metering is now normal too. DPDC alone had installed about 10.66 lakh smart prepaid meters by October 2025, out of roughly 19 lakh consumers (BSS).

A prepaid meter shows the balance left, not where the money went. Was it the old fridge, the pump, or an iron left on? An appliance-aware meter answers that question. Load-shedding adds another use: when power returns, many loads start together, and that inrush makes good thesis data.

Elektor’s ESP32-based energy meter series inspired this post. Its latest update covers training an Edge Impulse model to recognise household loads on an ESP32-S3. Elektor uses a metering IC. Our design samples directly with the ESP32-S3 ADC, which is cheaper and teaches more signal processing. For more ideas, see 15 Edge AI and TinyML project ideas.

How the AI energy meter works: power maths and NILM

1. Measuring power from two waveforms

Every 200 ms the ESP32-S3 captures matching voltage samples v[k] and current samples i[k]. After removing the bias and applying calibration:

  • Vrms = √(Σv²/N) and Irms = √(Σi²/N)
  • Real power P = Σ(v·i)/N, in watts. This is what you pay for.
  • Apparent power S = Vrms × Irms (VA). PF = P/S.
  • Energy = ΣP·Δt, kept in flash as Wh and kWh

2. Recognising appliances with non-intrusive load monitoring (NILM)

NILM means working out which appliances are running from a single measurement point, without a sensor on each appliance. The Sensors (MDPI) survey “Non-Intrusive Load Monitoring Approaches for Disaggregated Energy Sensing” is a good starting reference. We use the event-based method because it suits a microcontroller:

  1. Detect an event: real power changes by more than about 25 W and holds the new level for about 1 s.
  2. Extract features: ΔP, ΔQ, ΔIrms, PF, the 3rd/5th/7th current harmonics relative to the fundamental (from an FFT), crest factor, and inrush ratio (peak current in the first 200 ms ÷ steady current).
  3. Classify: a small Edge Impulse neural network outputs class probabilities.
  4. Track state: the firmware keeps a list of appliances that are ON. A matching negative step later turns one OFF, and its energy is charged to it.

Typical signatures are below. Check them on your own loads.

ApplianceTypical signature
Iron, rice cookerResistive, PF ≈ 1, few harmonics. A thermostat cycles it. A rice cooker drops to a small “warm” load.
Fridge compressorInductive motor with a big inrush. Runs, rests, repeats.
Ceiling fanSmall inductive load. BLDC fans add harmonics from their driver.
Air conditionerNon-inverter: a large step with inrush. Inverter: slow ramp, harmonic-rich current.
LED TV, chargersSMPS. Peaky current, strong 3rd harmonic, low PF.
Water pumpInduction motor with high inrush. Steady run until the tank fills.

Block diagram of the ESP32-S3 NILM energy monitor

ESP32 smart energy meter project block diagram: CT and voltage sensor, analog front end, ESP32-S3 ADC1, DSP, TinyML classifier and outputs

The sensors (CT and voltage transformer) feed an analog front end: burden, divider, mid-rail bias, anti-alias RC and clamp diodes. ADC1 runs in continuous DMA mode. Firmware then does the DSP (RMS, power, FFT, events) and TinyML inference. Results go to the OLED, a web dashboard and MQTT, and alerts go to the buzzer or a phone.

ESP32 energy meter circuit diagram and analog front-end design

ESP32 smart energy meter project circuit diagram: SCT-013-000 with 47 ohm burden to GPIO4, 9 V AC divider to GPIO5, 1.65 V bias, RC filter, OLED and buzzer

Pins are taken from Espressif’s ESP32-S3-DevKitC-1 user guide. On the ESP32-S3, ADC1 is GPIO1–GPIO10 (ADC1_CH0–CH9). ADC2 is shared with Wi-Fi, so all analog inputs stay on ADC1. GPIO3 is avoided because it is a strapping pin.

Burden resistor calculation for SCT-013-000 (with units)

The SCT-013-000 is a current-output CT: 100 A : 50 mA, a 2000:1 ratio, with no internal burden (OpenEnergyMonitor test report). Assumed maximum: 30 A rms, about 6.9 kW at 230 V, which covers a typical flat with one or two ACs.

  1. Primary peak: 30 A × √2 = 42.4 A
  2. Secondary peak: 42.4 A ÷ 2000 = 21.2 mA
  3. Allowed ADC swing: ±1.0 V around a 1.65 V bias, so the signal stays between 0.65 and 2.65 V. That is inside the S3’s effective range of about 2900 mV at 12 dB (Espressif ADC FAQ).
  4. Rburden = 1.0 V ÷ 0.0212 A = 47.2 Ω, so use 47 Ω, 1%. It dissipates (15 mA)² × 47 Ω ≈ 11 mW, so a 0.25 W part is fine.
  5. Resolution: about 3.1 V/4095 ≈ 0.76 mV per LSB, which is roughly 32 mA of primary current per LSB. Averaging improves this further.

For the full 100 A range the same maths gives about 23 Ω, so use 22 Ω, the OpenEnergyMonitor value. A bigger burden gives more resolution but more phase error. The OEM report measured just over 4° at 22 Ω and nearly 8° at 120 Ω, so you will need phase calibration.

Voltage divider and mid-rail bias network

  • Voltage: a plug-in 230 V : 9 V AC-AC adapter keeps the mains inside a certified product. Unloaded adapters often read more than 9 V. Assume 11 V at 230 V and 250 V worst-case mains: 12 V rms = 16.9 V peak. A 150 kΩ / 10 kΩ divider (ratio 0.0625) gives 1.06 V peak worst case and about 0.8 V nominal.
  • Bias: each channel has its own 10 kΩ / 10 kΩ divider from 3.3 V (1.65 V), with 10 µF + 100 nF to ground. The CT’s second lead and the adapter’s second lead connect to that node. These are the same values the OpenEnergyMonitor interfacing guide uses.
  • ZMPT101B option: its input terminals carry mains. Make sure the output stays within 0.15–2.9 V. Many modules centre at VCC/2, which is 2.5 V on 5 V and too high. Set about 1 V peak and check it on a scope.

Anti-alias filter and ADC sampling rate choice

  • Sampling: 20.48 kHz total in continuous DMA mode, which is 10.24 kHz per channel. A 2048-point FFT then spans exactly 200 ms, or 10 mains cycles. Each bin is 5 Hz, so harmonic h lands on bin 10h. The S3 allows 611 Hz to 83.3 kHz (SOC_ADC_SAMPLE_FREQ_THRES in ESP-IDF soc_caps.h).
  • Anti-alias RC: 1 kΩ in series with 47 nF to ground gives fc = 1/(2π·1 kΩ·47 nF) ≈ 3.4 kHz. One pole is only mild filtering (about −5 dB at the 5.12 kHz Nyquist), but household current above about 3 kHz is small. At M.Sc. level, oversample and decimate digitally instead. The 47 nF also gives the ADC’s sampling capacitor a charge reservoir. Both channels use identical filters, so their 0.85° phase shift cancels.
  • Protection: a BAT54S on each ADC pin clamps it to 3V3 and GND, and the 1 kΩ limits fault current.

ESP32-S3 energy meter wiring table (pin by pin)

FromThroughESP32-S3-DevKitC-1 pin
CT1 lead A (jack tip), with R1 47 Ω burden across A–BR3 1 kΩ; C3 47 nF to GND; D1 BAT54SGPIO4 (ADC1_CH3), J1 pin 4
CT1 lead B (sleeve)BIAS_I: R4/R5 10 kΩ, C4 10 µF + C5 100 nF3V3 (J1 pin 1) / GND
9 V AC lead 1R6 150 kΩ to node VS; R7 10 kΩ from VS to BIAS_V—
Node VSR10 1 kΩ; C7 47 nF to GND; D2 BAT54SGPIO5 (ADC1_CH4), J1 pin 5
9 V AC lead 2BIAS_V: R8/R9 10 kΩ, C8 10 µF + C9 100 nF3V3 / GND
Optional CT2Same front end as CT1GPIO6 (ADC1_CH5), J1 pin 6
OLED SSD1306 SDA / SCL4.7 kΩ pull-ups (if not on module)GPIO8 / GPIO9 (J1 pins 12 / 15)
Buzzer driver1 kΩ to S8050 base; 5 V active buzzerGPIO16 (J1 pin 9)
Status LEDOn-board RGBGPIO38 (v1.1; GPIO48 on v1.0)
PowerCertified 5 V USB chargerUSB port

Bill of materials (approx. BDT cost)

ItemQtyApprox. BDT
ESP32-S3-DevKitC-1 (N8R8/N16R8)11,100 – 1,600
YHDC SCT-013-000 100 A split-core CT1–2650 – 900 each
230 V : 9 V AC-AC adapter (or ZMPT101B 250–400)1350 – 600
0.96″ SSD1306 I2C OLED1300 – 450
1% resistors, capacitors, 2× BAT54S, 3.5 mm jackset150 – 250
Active buzzer, S8050, 1N4148140 – 60
Certified 5 V 2 A USB charger + cable1300 – 500
ABS enclosure, glands, labels1300 – 600
Veroboard / JLCPCB PCB (shipped)1150 / 1,000 – 1,500
Total≈ 3,400 – 6,500

Approx., Nov 2026, local market. Fake CT clamps are common, so see how to spot fake electronic components.

Step-by-step build guide

Step 1: Build the front end (no mains)

Solder the bias networks, burden, dividers, RC filters and clamp diodes. Power from USB only, and check for 1.65 V ±0.05 V on both BIAS nodes, GPIO4 and GPIO5. Fit the burden resistor before the CT is ever plugged in.

Step 2: Check the signals on a scope

Plug in the 9 V adapter. GPIO5 should show a clean sine of about 0.8 V peak around 1.65 V. For current, clamp the CT around one conductor of a lamp-cord extension powering a known load, such as a 1000 W iron.

Step 3: Configure ADC continuous mode

ESP-IDF v5.x. ADC1 channel 3 is GPIO4 and channel 4 is GPIO5, both at 12 dB:

#include "esp_adc/adc_continuous.h"
static adc_continuous_handle_t adc;

void adc_start(void) {
  adc_continuous_handle_cfg_t h = { .max_store_buf_size = 8192, .conv_frame_size = 1024 };
  ESP_ERROR_CHECK(adc_continuous_new_handle(&h, &adc));
  adc_digi_pattern_config_t pat[2] = {
    { .atten = ADC_ATTEN_DB_12, .channel = ADC_CHANNEL_3, .unit = ADC_UNIT_1, .bit_width = 12 }, // GPIO4 CT
    { .atten = ADC_ATTEN_DB_12, .channel = ADC_CHANNEL_4, .unit = ADC_UNIT_1, .bit_width = 12 }, // GPIO5 V
  };
  adc_continuous_config_t cfg = { .sample_freq_hz = 20480, .conv_mode = ADC_CONV_SINGLE_UNIT_1,
    .format = ADC_DIGI_OUTPUT_FORMAT_TYPE2, .pattern_num = 2, .adc_pattern = pat };
  ESP_ERROR_CHECK(adc_continuous_config(adc, &cfg));
  ESP_ERROR_CHECK(adc_continuous_start(adc));
}

Step 4: Calculate RMS, real power and PF

Convert raw counts to millivolts with the calibration driver. Remove the bias with a running mean, apply the calibration factors, then process each 2048-sample window:

typedef struct { float vrms, irms, p, s, pf; } power_t;

power_t calc_power(const float *v, const float *i, int n) {
  double sv = 0, si = 0, sp = 0;
  for (int k = 0; k < n; k++) {
    sv += v[k] * v[k];  si += i[k] * i[k];  sp += v[k] * i[k];
  }
  power_t r = { sqrtf(sv / n), sqrtf(si / n), (float)(sp / n), 0, 0 };
  r.s  = r.vrms * r.irms;                   // apparent power, VA
  r.pf = (r.s > 1.0f) ? r.p / r.s : 0.0f;  // real power r.p in W
  return r;
}

Step 5: Calibrate (the ESP32 ADC caveat)

The ESP32-S3 ADC is not a precision ADC. Espressif’s calibration docs say its reference is 1100 mV by design but varies from 1000 to 1200 mV between chips, and that the ADC is noise-sensitive. It is also non-linear near the ends of its range. Use the S3’s curve-fitting scheme, keep the signals mid-range, then calibrate the whole chain:

  1. Voltage: match a true-RMS multimeter on the same socket by adjusting V_CAL.
  2. Current: run a resistive load (iron or kettle) and match a true-RMS clamp meter by adjusting I_CAL. Repeat at a second load to check linearity.
  3. Phase: on the resistive load PF must read 1.00. Shift the voltage samples by a fractional sample until it does.
  4. Save the factors in NVS.

Step 6: Collect data and train the Edge Impulse model

Switch each appliance on and off 30–50 times, at different times and with other loads running, and log every event’s features to CSV. Upload the CSV to Edge Impulse and build a “Raw data” block feeding a small dense classifier. Then export a C++ or Arduino library; Edge Impulse supports ESP32 deployment via ESP-IDF and Arduino.

#include <nilm_meter_inferencing.h>   // your exported Edge Impulse library
float feat[EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE]; // dP, dQ, PF, H3, H5, H7, inrush...

const char *classify_event(float *conf) {
  signal_t sig;
  numpy::signal_from_buffer(feat, EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE, &sig);
  ei_impulse_result_t res = { 0 };
  if (run_classifier(&sig, &res, false) != EI_IMPULSE_OK) return "unknown";
  size_t b = 0;
  for (size_t k = 1; k < EI_CLASSIFIER_LABEL_COUNT; k++)
    if (res.classification[k].value > res.classification[b].value) b = k;
  *conf = res.classification[b].value;
  return res.classification[b].label;
}

Want the complete firmware? The snippets above are only the core pieces. The complete production firmware includes dual-core ADC DMA buffering, the full calibration routine with phase correction, zero-crossing-synced FFT and harmonic features, the event detector and appliance state tracker, a dataset logger, the web dashboard, MQTT/Home Assistant integration, OTA updates, prepaid-balance estimation, alerts and data logging. Message us on WhatsApp to get the full source code, circuit files and help building it.

Step 7: Dashboard, MQTT and smart alerts

The OLED shows V, A, W, PF, today’s kWh and the last appliance detected. A web page served by the ESP32 shows live power and per-appliance energy, and MQTT feeds Home Assistant or Node-RED. Example alerts:

  • “Fridge compressor running abnormally”: it has run for more than 45 minutes non-stop, or its duty cycle has jumped against the 7-day baseline. Check for an open door, a dirty condenser or low gas.
  • “Iron left on”: an iron-class load has been active for more than 20 minutes. At Tk 10.63/kWh, a 1 kW iron left on for 2 hours costs about Tk 21.
  • “Pump running too long”: the tank may be overflowing or the pump may be running dry.
  • Prepaid balance: enter your balance and tariff, and the meter estimates the days left.

How accurate is an ESP32 energy meter? Testing and results to expect

These are expectations, not measurements from a unit we tested. In our experience with similar CT-plus-MCU-ADC projects, a well-calibrated build usually lands within a few percent of a good clamp meter above a few amps. It is poorer at low current: the OEM report found readings below 250 mA unreliable with this CT, and the CT is specified at ±3% non-linearity. The classifier separates very different loads (iron vs fridge) easily, but struggles with similar loads and with loads that switch on at the same moment. Report a confusion matrix measured on events the model never saw during training.

ProblemLikely causeFix
0.2–0.5 A shown with nothing onADC noise, Wi-Fi bursts100 nF at the pin, more averaging, a small dead-band
Reads zero with load onCT around both Live and NeutralClamp only one conductor
Negative powerCT facing the wrong wayFlip the clamp or the sign
Flat-topped waveformADC saturatingRecalculate the burden/divider and stay within 0.15–2.9 V
PF below 1 on an ironPhase errorRun phase calibration
Fan and LED TV confusedWeak features or too little dataAdd harmonic features and collect more varied events

Mains safety: read this before you connect anything

  • Work only on the low-voltage side of isolated sensors: the CT secondary, the 9 V adapter output and 3.3/5 V.
  • Do not open the distribution board yourself. A licensed electrician should fit the clamp with the supply off. Students should always work under supervision.
  • Clamp the CT around ONE conductor only.
  • Never leave the CT secondary open while current flows in the primary. Fit the burden first, and do not unplug the jack under load.
  • A ZMPT101B input is at mains voltage. It needs a closed enclosure, a fuse (for example 100 mA slow-blow) and no exposed terminals.
  • Use certified chargers and adapters only, and never a capacitor-dropper supply.

Upgrades and real-world uses

  • Metering IC (M.Sc.-level accuracy): use Microchip’s ATM90E26 single-phase metering IC (SPI/UART), or the ATM90E32AS that Elektor uses. The ESP32-S3 then only runs features and AI. Comparing both versions makes a strong thesis chapter.
  • Three-phase: add three CTs and three voltage channels; see three-phase voltage measurement with PTs.
  • NILM research: sample at a higher rate, feed V-I trajectory images to a CNN, and benchmark on public datasets. See our M.Sc. thesis topics.
  • Product ideas: a “bill coach” for flats, an audit tool for factory lines, or fridge and pump health monitoring.
  • PCB: follow our KiCad 10 to JLCPCB guide.

For other ways to add AI to an ESP32, read ESP32 AI projects: 4 ways to add AI and the ESP32 AI hardware guide.

Frequently asked questions

Can ESP32 measure AC current and voltage directly?

No. Mains must never touch an ESP32 pin. Use isolating sensors (a CT for current, a transformer or ZMPT101B for voltage) that scale the signal to about ±1 V, and add a 1.65 V bias so the ADC only sees positive voltages.

How do I calculate the burden resistor for SCT-013-000 with ESP32?

R = allowed peak voltage ÷ (Imax × √2 ÷ 2000). For 30 A and ±1.0 V that is 47 Ω. For 100 A it is about 22 Ω. Round down to the nearest standard value.

How accurate is an ESP32 smart energy meter project?

After curve-fitting, gain and phase calibration, expect a few percent above a few amps, and worse at very low current. For billing-grade accuracy, use a metering IC such as the ATM90E26.

What is NILM (non-intrusive load monitoring)?

NILM works out which appliances are running from one meter at the main supply. It uses each appliance’s electrical signature (power step, PF, harmonics, inrush) instead of a sensor on every appliance.

Can I use this with a prepaid meter in Bangladesh?

Yes, as a separate monitor on the house side of the prepaid meter. Never open or tamper with the utility meter. An electrician fits the clamp in your own distribution board.

ZMPT101B or a 9 V AC transformer: which is better for voltage sensing?

For students, the plug-in 9 V AC-AC adapter. The mains stays inside a certified product and linearity is good. The ZMPT101B is compact and cheap, but its input carries mains, so it needs an enclosure and a fuse.

Conclusion

This ESP32 smart energy meter project combines analog design, power maths, DSP and on-device AI in one practical build that Bangladeshi households actually need. Get clean, calibrated Vrms/Irms/P readings first, add event detection next, and train the model last. Good data matters more than a clever network.

Want this AI energy meter as your final-year or M.Sc. project, fully working and calibrated? We design custom PCBs, firmware and complete working prototypes for students and companies. Message us on WhatsApp or use the contact form. You can write in Bangla or English.


MKDas

Mithun K. Das. B.Sc. in Electrical and Electronic Engineering (EEE) from KUET. Senior Embedded Systems Designer at a leading international company. Welcome to my personal blog! I share articles on various electronics topics, breaking them down into simple and easy-to-understand explanations, especially for beginners. My goal is to make learning electronics accessible and enjoyable for everyone. If you have any questions or need further assistance, feel free to reach out through the Contact Us page. Thank you for visiting, and happy learning!