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.
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.
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.
| Stage | Where it stands | Evidence |
|---|---|---|
| Concept | Completed The problem, the measurement question and the safety boundary, written before any design existed. | Project record |
| Software model | Implemented 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 requirements | Documented (draft for review) E1–E12 with acceptance criteria, each marked verified against a datasheet or script, or proposed. | Electrical requirements |
| Electrical design | Schematic 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 firmware | Host-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 prototype | Not built No component purchased, no board assembled, nothing energised. | Prototype review checklist |
| Calibration | Not performed Procedure and blank recording sheet exist; no instrument has been compared with anything. | Calibration plan |
| Physical validation | Unavailable 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.
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.
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.
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.
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.
- 01Decode
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.
- 02Timestamp
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.
- 03Integrate
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.
- 04Report
CSV on serial: timestamp, voltage, current, power, energy, status — with comment lines for intervals that were held.
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
| Case | Input | Expected | Result |
|---|---|---|---|
| Model A | 12 V, 1 A, 3600 s | 43 200 J / 12 Wh | exact |
| Model C | 10 V, step 1 A → 0.5 A at 1800 s | 27 000 J continuous ideal | 26 997.5 J (0.0093 % low) |
| Model E | irregular timestamps, five intervals | 77.605 J, derived by hand | 77.605 J |
| Model F | +2 % gain, +50 mV offset | 10.4 V, then 10.000 V calibrated | exact both ways |
| Energy 1 s | 3 W for 1 s | 3 J = 0.000833 Wh | confirmed |
| Energy 9 s | 3 W for 9 s (the published vector) | 27 J = 0.0075 Wh | confirmed |
| Energy 1 h | 3 W for 3600 s | 10 800 J = 3 Wh | exact |
| Firmware | gap, invalid sample, 32-bit rollover | held, counted, wrap-safe | all pass |
| ESP32 build | pio run -e esp32dev | links for Xtensa LX6 | SUCCESS · 25.4 % flash |
| KiCad ERC | dcm-hw-v1.kicad_sch | no pin conflicts | 0 errors, 0 warnings |
Not in this table: sensor accuracy, bench measurements, calibration. Those need a board, and there is no board.
Choices, with what they cost.
| Decision | Alternative rejected | What it costs |
|---|---|---|
| INA226 over INA219 | INA219: 12-bit, ±320 mV, 26 V bus | Fewer bits of headroom on current; the INA226 gives 16-bit conversion for the same wiring effort. |
| 0.1 Ω shunt | 0.05 Ω for a 1 A range | Caps the design at 0.819 A. A 1 A test needs a different shunt and a fresh calibration. |
| Reverse diode upstream of the shunt | Diode after the shunt, or none | 0.3–0.4 V of headroom and ~0.2 W at 0.5 A, in exchange for a measurement the diode cannot corrupt. |
| Trapezoidal integration | Sum of power samples | One 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 intervals | Integrate across the gap | Loses a little energy instead of inventing some. The loss is counted and reported. |
| Current from V/R, not the calibration register | Use the INA226 current register | One division per sample; removes a whole class of silent error. |
| Bare IC over a breakout module | Module with an on-board shunt | Harder to assemble (VSSOP-10), but the VBUS connection is explicit instead of vendor-dependent. |
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.
- 1Review the design
Read the ERC report, the design review and the open questions. Decide bare IC or module.
- 2Identify the parts
Confirm markings against datasheets; measure the shunt; check the module's pull-up rail and VBUS connection with a multimeter.
- 3Unpowered continuity
Trace the current path; prove there is no short from the protected rail to ground.
- 4First power-up
5 V, 100 mA limit, no load, second person present. Nothing warm, no sensor error on serial.
- 5Communication
I²C scan finds 0x40; the identity registers read back correctly.
- 6Known loads
100 Ω and 47 Ω at 12 V; record voltage, current, power and energy against a multimeter.
- 7Calibration
Six points across the range against a reference meter, in a recorded environment, failures included.
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.
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 ↗
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.