← Projects
Software verified Hardware designed Prototype not built Project 01 · 2026-11

Smart Energy Monitoring.
A measurement chain, modelled, designed and compiled.

A low-voltage DC energy monitor built through three layers, each with its own evidence: a software model verified against reference cases, a native KiCad schematic that passes ERC, and firmware that cross-compiles for the ESP32. The prototype does not exist yet, and the page says so where it matters.

01 / ENGINEERING OBJECTIVE

How far is an energy reading from the truth?

A monitor that reports 12.00 W is making a claim about a chain of components. A divider scales the voltage, a shunt converts current into a small differential voltage, an amplifier and an ADC translate both into numbers, firmware multiplies them, and a clock decides how long to keep adding. Each stage contributes an error the others do not cancel, and some of those errors — a gain error, a stale sample, an interval integrated across missing data — look exactly like a real change in the load.

The useful engineering question is therefore not “what does it read?” but “how far can that reading be from the truth, which stage put it there, and how would anyone know?” This project answers that question three times over: once in a simulation where every stage can be varied independently, once as a schematic where the connections must be electrically legal, and once as firmware where the arithmetic has to survive real timestamps and missing samples.

In scope

Low-voltage DC (5–12 V, 0–0.5 A), a single non-isolated measurement channel, sampled power and integrated energy, and the evidence needed to check all of it.

Out of scope

Mains and AC, isolation, three-phase, battery management, wireless reporting. Any accuracy claim about physical hardware.

02 / PROJECT STATUS

Eight stages, each with the evidence it has earned.

Read this table as the project's actual state. A stage marked done has an artefact behind it, linked in the right-hand column. Nothing is marked done because it was written down.

Project stages, their status and their evidence
StageWhere it standsEvidence
ConceptCompleted

The problem, the measurement question and the safety boundary, written before any design existed.

Project record
Software modelImplemented and reference-tested

The whole measurement chain in software: source, load, sensing, ADC, sampled power, trapezoidal energy. Seven reference cases and 594 independent checks.

Model sourceReference testsIndependent testsRun the instrument
Hardware requirementsDocumented (draft for review)

E1–E12 with acceptance criteria, each marked verified against a datasheet or script, or proposed.

Electrical requirements
Electrical designSchematic authored, ERC clean

Native KiCad schematic built from official library symbols. kicad-cli 9.0.2 ERC: 0 errors, 0 warnings. The exported netlist matches the design file on all 42 pins.

KiCad schematicERC reportDesign reviewHardware design page
Embedded firmwareHost-tested and cross-compiled

PlatformIO + Xtensa GCC 14.2.0 build firmware.bin for esp32dev (25.4 % flash). 98 host checks including a mocked I²C bus. Never flashed, never run on a board.

Build evidenceApplication layerSensor driverMock-bus tests
Physical prototypeNot built

No component purchased, no board assembled, nothing energised.

Prototype review checklist
CalibrationNot performed

Procedure and blank recording sheet exist; no instrument has been compared with anything.

Calibration plan
Physical validationUnavailable

No measurement against a reference meter. This is the only thing that could turn the design into an accuracy claim.

—

What the separation means. A cross-compiled firmware is not hardware-tested firmware, and an ERC-clean schematic is not a fabricated board. The bottom three rows are deliberately empty of artefacts, because no board exists.

03 / SYSTEM ARCHITECTURE

One circuit, described three ways.

The same signal path appears as a simulatable model, as a schematic, and as firmware. Keeping the three separate is what makes it possible to check one against another.

The three layers of the project and how they relate A DC source and load are measured by a shunt and an INA226. The measurement reaches an ESP32 over I2C, which decodes, timestamps and integrates energy. The same signal path exists as a software model in the browser, which is verified against reference cases; the hardware exists as a KiCad schematic that passes ERC; and the firmware cross-compiles for the ESP32 and is tested against a mock bus. Only the prototype and the measurements are missing. THE PHYSICAL CHAIN — DESIGNED, NOT BUILT DC source Shunt 0.1 Ω+ INA226 ESP32 Energy totalCSV on serial Load THE THREE DESCRIPTIONS — EACH WITH ITS OWN EVIDENCE Software model Runs in the browser, and in Node for the tests • source and load solved together • gain, offset, noise, quantisation • trapezoidal energy on real timestamps • 67 reference + 594 independent checks VERIFIED Electrical design Native KiCad project, editable • INA226 wired as the bare IC • VBUS tied to the load side • fuse, reverse diode, TVS clamp • ERC 0 errors, 0 warnings ERC CLEAN · NOT BUILT Firmware C++17, platform-free core • register decode and calibration • wrap-safe millisecond timing • holds intervals rather than invent energy • 98 host checks, cross-compiled COMPILED · NEVER FLASHED
The three descriptions share one signal path, which is why they can be checked against each other: the KiCad netlist is compared with the design file pin by pin, and firmware test vectors are replayed through the verified software model.
04 / SOFTWARE MODEL

Everything measurable, before anything is soldered.

The software model is the project's first deliverable and its reference implementation. It solves the source and the load together — a resistive load derives its own current from the applied voltage — then passes that operating point through a configurable sensing chain and accumulates energy with the trapezoidal rule over the actual interval between samples.

What it can establish

  • The arithmetic, exactly where the arithmetic is exact: 12 V at 1 A for an hour is 12 Wh, to the last digit.
  • How much a gain error, offset, noise or quantisation step moves the reading, and whether calibration recovers it.
  • What a step that falls between two samples costs, quantified: 0.0093 % of a 27 000 J run at 1 s sampling.
  • That missing samples cannot create energy: an invalid reading costs two intervals and is counted.

What it cannot establish

  • Anything about a physical sensor. The noise source is seeded and statistical, not a characterisation of a part.
  • ADC non-idealities: no INL, DNL or reference drift.
  • Loop dynamics, thermal behaviour, or what the load does faster than the sample interval.
  • That the model's sensing chain equals the INA226's. It is a model of a chain, not of that part.

Run the model in the browser Model documentation ↗

05 / ELECTRICAL DESIGN

ESP32 and INA226, wired so the reading means something.

The measurement is a 0.1 Ω shunt in series with the load, with an INA226 reading the differential voltage across it and the bus voltage on the load side. That last detail is the reason this revision exists: on the bare INA226, VBUS is a separate pin, and if it is not tied to IN− the reported voltage comes from the wrong node and every power figure is wrong while looking perfectly plausible.

SensorINA226AIDGSR, 16-bit, 0–36 V bus, ±81.92 mV shunt
Shunt0.1 Ω, 0.5 %, 1 W — 50 mV at 0.5 A
ControllerESP32-DevKitC-32E, I²C at 0x40 on GPIO21/22
Protection1.1 A PTC, SS34 Schottky, SMBJ15A clamp
KiCad schematic of the measurement carrier: DC input through fuse, reverse-protection diode and shunt to the load, with the INA226 measuring the shunt drop and the load-side bus voltage.
The schematic as exported from KiCad. It is a native project built from official library symbols, and it passes ERC with no errors and no warnings.

Hardware design, ERC and BOM Open the .kicad_sch ↗

06 / EMBEDDED FIRMWARE

Decode, timestamp, integrate — and refuse to guess.

The firmware is split so that the arithmetic can be tested without a board. A platform-free core holds the register decode, the calibration, the energy accumulator and the missing-data policy; a thin application layer implements I²C with Wire and prints CSV over serial. The host tests drive the same core through a mock bus, so the code that compiles for the ESP32 is the code that was tested.

  1. 01
    Decode

    Signed 16-bit shunt register at 2.5 µV per bit, unsigned bus register at 1.25 mV. Current is derived from the shunt voltage and the known resistance rather than from the device's calibration register, so a mis-written register cannot silently corrupt the reading.

  2. 02
    Timestamp

    Milliseconds since boot in an unsigned 32-bit counter. Subtraction is wrap-safe, so the 49.7-day rollover is not a bug waiting to happen. There is no real-time clock in this design, so no date is claimed.

  3. 03
    Integrate

    Trapezoidal rule over the measured interval. An invalid or missing sample holds the interval instead of integrating a stale reading, and a gap longer than five seconds is not integrated at all. Both are counted, so a period with no measurement cannot look like a period of zero power.

  4. 04
    Report

    CSV on serial: timestamp, voltage, current, power, energy, status — with comment lines for intervals that were held.

07 / VERIFICATION

What was actually run, and what it produced.

Every number below is printed by a suite in the repository. Nothing in this table is a summary of an intention.

Software model

661

checks · 67 reference cases A–G and 594 independent checks across ten groups

Firmware

98

host checks · 69 arithmetic and 29 against a mock I²C bus

Electrical design

25

design-rule checks with margins printed, plus ERC at 0 errors and 0 warnings

Netlist agreement

42

pins compared between the KiCad export and the design file · 8 nets · no differences

Reference results actually produced by the test suites
CaseInputExpectedResult
Model A12 V, 1 A, 3600 s43 200 J / 12 Whexact
Model C10 V, step 1 A → 0.5 A at 1800 s27 000 J continuous ideal26 997.5 J (0.0093 % low)
Model Eirregular timestamps, five intervals77.605 J, derived by hand77.605 J
Model F+2 % gain, +50 mV offset10.4 V, then 10.000 V calibratedexact both ways
Energy 1 s3 W for 1 s3 J = 0.000833 Whconfirmed
Energy 9 s3 W for 9 s (the published vector)27 J = 0.0075 Whconfirmed
Energy 1 h3 W for 3600 s10 800 J = 3 Whexact
Firmwaregap, invalid sample, 32-bit rolloverheld, counted, wrap-safeall pass
ESP32 buildpio run -e esp32devlinks for Xtensa LX6SUCCESS · 25.4 % flash
KiCad ERCdcm-hw-v1.kicad_schno pin conflicts0 errors, 0 warnings

Not in this table: sensor accuracy, bench measurements, calibration. Those need a board, and there is no board.

08 / ENGINEERING DECISIONS

Choices, with what they cost.

Design decisions, the alternative and the cost
DecisionAlternative rejectedWhat it costs
INA226 over INA219INA219: 12-bit, ±320 mV, 26 V busFewer bits of headroom on current; the INA226 gives 16-bit conversion for the same wiring effort.
0.1 Ω shunt0.05 Ω for a 1 A rangeCaps the design at 0.819 A. A 1 A test needs a different shunt and a fresh calibration.
Reverse diode upstream of the shuntDiode after the shunt, or none0.3–0.4 V of headroom and ~0.2 W at 0.5 A, in exchange for a measurement the diode cannot corrupt.
Trapezoidal integrationSum of power samplesOne stored sample and two multiplications. The alternative is not an approximation: it is dimensionally wrong, and out by 2× at 0.5 s sampling.
Hold missing intervalsIntegrate across the gapLoses a little energy instead of inventing some. The loss is counted and reported.
Current from V/R, not the calibration registerUse the INA226 current registerOne division per sample; removes a whole class of silent error.
Bare IC over a breakout moduleModule with an on-board shuntHarder to assemble (VSSOP-10), but the VBUS connection is explicit instead of vendor-dependent.
09 / BUILD AND TEST PLAN

From schematic to first reading.

The plan is deliberately slow, because every stage is cheaper to fail than the one after it. Each step has an observable exit condition, and the stop conditions are written down before anything is energised.

  1. 1
    Review the design

    Read the ERC report, the design review and the open questions. Decide bare IC or module.

  2. 2
    Identify the parts

    Confirm markings against datasheets; measure the shunt; check the module's pull-up rail and VBUS connection with a multimeter.

  3. 3
    Unpowered continuity

    Trace the current path; prove there is no short from the protected rail to ground.

  4. 4
    First power-up

    5 V, 100 mA limit, no load, second person present. Nothing warm, no sensor error on serial.

  5. 5
    Communication

    I²C scan finds 0x40; the identity registers read back correctly.

  6. 6
    Known loads

    100 Ω and 47 Ω at 12 V; record voltage, current, power and energy against a multimeter.

  7. 7
    Calibration

    Six points across the range against a reference meter, in a recorded environment, failures included.

Prototype review checklist Calibration plan ↗

10 / OUTSTANDING WORK

What this project does not have.

  • No prototype. No component has been purchased, assembled or energised. Everything above was verified without touching hardware.
  • No PCB. The schematic is a schematic. No layout, routing or design-rule check exists.
  • No flashed firmware. The binary compiles and links for the target; it has never been uploaded to a board.
  • No measurements. Not one number in this project came from a physical sensor.
  • No calibration. The procedure exists; the results do not.
  • No accuracy claim. Until a reference-meter comparison exists, the design has a stated target of ±1 % voltage and ±2 % current and no evidence for it.
11 / REPRODUCIBILITY

Check it without trusting this page.

Node, g++ and Python 3 are enough for the software side; KiCad 9 and PlatformIO reproduce the electrical and firmware results. No paid tools, no accounts, no network.

node energy-monitor/tests/dcem-reference.test.js        # 67 reference assertions
node energy-monitor/tests/dcem-independent.test.js      # 594 independent checks
node energy-monitor/tests/energy-duration.test.js       # 1 s, 9 s, 1 h, irregular, invalid
node energy-monitor/tests/config-consistency.test.js    # schematic = firmware = site
node energy-monitor/tests/hardware-package.test.js      # claims match artefacts

g++ -std=c++17 -I include -o t src/core/*.cpp test/test_core.cpp && ./t
pio run -e esp32dev                                      # cross-compile for the ESP32

kicad-cli sch erc dcm-hw-v1.kicad_sch                    # ERC
python3 energy-monitor/hardware/design/compare_netlists.py

Evidence hub Technical dossier (PDF, 10 pages)Markdown source ↗

12 / DEVELOPMENT ATTRIBUTION

Who did what.

Produced with AI assistance

The model, the test suites, the schematic generator, the firmware, the documentation and this page were written with AI assistance during the construction of this site. That is stated because it is material.

Specified by the founder

The project direction; the decision to stay low-voltage and DC; the operating envelope; the requirement that hardware claims stay separate from software claims; and the instruction that no measurement, credential or result be invented.

Still to be done by the founder

Read the model and re-derive the power and energy relations independently; run the suites and break something on purpose; review the schematic pin by pin; decide whether the trade-offs in section 08 are the ones he wants to defend; and then build the board.

Nothing on this page is presented as the founder's independent engineering design. The project will mean more once he has built and measured it, and that is the point of the next stage.