← Smart Energy Monitoring Project 01 / Hardware design V1 / Prototype not built

DC energy monitor.
The hardware layer.

A measurement carrier between a low-voltage bench supply and a load: fuse, reverse-polarity diode, transient clamp, a 0.1 Ω shunt and an INA226 wired as the bare IC, read by an ESP32-DevKitC over I²C. The schematic is a native KiCad project that passes ERC with no errors and no warnings, and the firmware compiles for the board it targets.

Native KiCad schematic ERC: 0 errors, 0 warnings Firmware cross-compiled for ESP32 Not flashed · prototype not built
01 / WHERE THE PROJECT STANDS

Eight stages,
four of them done.

Each stage is reported at the level of evidence that actually exists. Nothing here is marked complete because it was written down.

  1. ConceptCompletedThe problem, the measurement question and the safety boundary, written before any design existed.
  2. Software modelImplemented and reference-testedThe whole measurement chain in software: source, load, sensing, ADC, sampled power, trapezoidal energy. Seven reference cases and 594 independent checks.
  3. Hardware requirementsDocumented (draft for review)E1–E12 with acceptance criteria, each marked verified against a datasheet or script, or proposed.
  4. Electrical designSchematic authored, ERC cleanNative 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.
  5. Embedded firmwareHost-tested and cross-compiledPlatformIO + 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.
  6. Physical prototypeNot builtNo component purchased, no board assembled, nothing energised.
  7. CalibrationNot performedProcedure and blank recording sheet exist; no instrument has been compared with anything.
  8. Physical validationUnavailableNo measurement against a reference meter. This is the only thing that could turn the design into an accuracy claim.

Software and hardware status are deliberately separate. A verified simulation says nothing about a circuit that has never been powered.

02 / ARCHITECTURE

Source, protection,
shunt, sensor.

Four things happen between the supply and the load, and each one costs something that is written down.

01

Input protection

A 1.1 A hold resettable fuse, a 3 A 40 V Schottky for reverse polarity, and a 15 V transient clamp that conducts at 24.4 V — below the sensor's 36 V absolute maximum.

Cost: 0.3–0.4 V of headroom and about 0.2 W at 0.5 A through the diode.

02

Current shunt

0.1 Ω, 0.5 %, 1 W in a 2512 package, in series with the load. At 0.5 A it drops 50 mV and dissipates 25 mW — 2 % of its rating.

Cost: the burden voltage, and a hard measurable limit of 0.819 A.

03

Measurement

An INA226 measures the shunt drop and the load-side bus voltage, both 16-bit, with ±81.92 mV and 0–36 V ranges. It sits on the 3.3 V rail, so no level shifting is needed.

Cost: the module is the least-defined part — see the open questions.

04

Controller and link

An ESP32-DevKitC reads the sensor over I²C at 0x40 on GPIO21/22, with 4.7 kΩ pull-ups to 3.3 V on the carrier, accumulates energy and prints CSV on the USB serial port.

Cost: no real-time clock, so timestamps are milliseconds since boot.

03 / SCHEMATIC

A native KiCad
project, not a picture.

Built from the official KiCad symbol libraries, checked with kicad-cli 9.0.2, and exported to a netlist that is compared pin-for-pin with the design file on every build.

Toolkicad-cli 9.0.2
SymbolsSensor_Energy:INA226, Device, Connector_Generic, power
ERC0 errors, 0 warnings
Netlist match42/42 pins agree with the design file
The complete schematic, exported from KiCadOpen the .kicad_sch ↗
KiCad schematic of the DCM-HW-V1 measurement carrier: DC input connector through fuse F1, reverse-protection diode D1 and shunt R1 to the load connector J2, with TVS D2 from the protected rail to ground. The INA226 is drawn with IN+ on the supply side, IN- and VBUS on the load side, A0 and A1 tied to ground, and ALERT unconnected. Decoupling C1 and C2, I2C pull-ups R2 and R3, connector J3 and the ESP32-DevKitC complete the sheet.

Connectivity is drawn with net labels rather than long wires, which is a normal style for a board built from connectors and modules — and it makes the netlist unambiguous. Open the .kicad_sch to edit it, or the SVG export for a vector copy.

What ERC checked

Pin conflicts, unconnected inputs, power-input pins without a driver, output-to-output clashes, and library consistency. The first run produced two real errors — two power outputs on one net — which were fixed by correcting the symbol pin types rather than by disabling the rule.

What ERC cannot check

That the circuit does the right thing. ERC does not know that VBUS must tie to the load side of the shunt, that a reverse diode must sit upstream of it, or that a 0.1 Ω shunt limits the design to 0.82 A. Those are the design review's job.

Netlist agreement

The JSON design and the KiCad project are separate descriptions of one circuit, so a script compares the netlist KiCad exports against the design file, pin by pin, as part of the test suite. 42 pins, 8 nets, no differences.

kicad-cli sch erc dcm-hw-v1.kicad_sch python3 hardware/design/compare_netlists.py
THE CORRECTION THIS REVISION MAKES

Revision A treated the sensor as a module and never modelled VBUS. On the bare INA226 that is pin 8, a separate input that must be tied to IN− for load-side measurement — the datasheet's own example does exactly that. Without it the bus reading is taken from the wrong node and every power figure is wrong while looking plausible. Revision B specifies the bare IC, wires VBUS to VLOAD, straps A0 and A1 to ground for address 0x40, and marks ALERT as a no-connect.

04 / DESIGN RULE CHECKS

Twenty-five checks,
with their margins.

Run python3 energy-monitor/hardware/design/checks.py to reproduce. Every number comes from the design file or the datasheet figure recorded beside it.

Design rule checks and their outcomes
RuleRequirementActualMarginResult
S1 bus voltage12 V inside the sensor's 0–36 V range12 V vs 36 V67 % headroomPASS
S2 shunt rangeDrop at 0.5 A inside ±81.92 mV50.0 mV61 % of full scalePASS
S3 measurable currentState the limit of the chosen shunt0.8192 Aa 1 A test needs 0.05 ΩPASS
S5 sensing pointMeasure the load side of the shuntIN− on VLOADP = V_load × IPASS
L1 logic levelsNo 5 V device on the bus3.3 V throughoutno shifter requiredPASS
L2 pull-ups1–10 kΩ for 100 kHz at 3.3 V4.7 kΩmid-rangePASS
P2 transient clampStandoff > 12 V, clamp < 36 V15 V / 24.4 V3.0 V above, 11.6 V belowPASS
P5 shunt dissipationUnder half the rating at 0.5 A25 mW in a 1 W part2 % of ratingPASS
P7 ground continuityOne common ground9 pin connectionssingle netPASS
N1 single-pin netsEvery net has ≥ 2 connectionsall except the declared NC—PASS

Ten of the twenty-five are shown above; the full table prints when you run the script. All twenty-five pass. Passing these checks means the design satisfies the rules written for it — not that the circuit works.

05 / COMPONENTS

What to buy,
and why that part.

No price is listed: no supplier was queried while writing this, and an invented price is worse than a blank one. Nothing has been purchased.

Bill of materials
RefPartFunctionKey ratingsWhy this one
J1, J2Phoenix MKDS 1/2-5.08 or equivalentInput and load terminals10 A, 300 VFar above the 1 A design current, and safe to probe
F1Bourns MF-R110Resettable fuse1.1 A hold, 2.2 A tripAt 0.5 A it sits at 45 % of hold, so it does not nuisance-trip
D1onsemi SS34Reverse-polarity protection3 A, 40 VUpstream of the shunt, so it cannot corrupt the measurement
D2Littelfuse SMBJ15ATransient clamp15 V standoff, 24.4 V clampAbove 12 V, below the sensor's 36 V maximum
R1Vishay CRCW2512 0R1Current shunt0.1 Ω, 0.5 %, 1 W50 mV at 0.5 A: 61 % of the sensor range with a 25 mW burden
U1Texas Instruments INA226AIDGSR (VSSOP-10)Voltage and current measurement0–36 V, ±81.92 mV, 2.7–5.5 VBare IC, not a module: only the IC guarantees that VBUS is a pin you can wire
U2Espressif ESP32-DevKitC-32EMicrocontroller3.3 V logicSame logic level as the sensor, documented, widely available
C1, C210 µF 1210, 100 nF 0603, 25 V X7RDecoupling25 VStandard pair at the sensor supply pin
R2, R3Yageo RC0603 4k7 1 %I²C pull-ups4.7 kΩOn the carrier, to 3.3 V, so the module's own pull-ups can be removed
J34-way 2.54 mm headerLink to the MCU3 AFour wires: 3V3, GND, SDA, SCL

The full BOM with rationale and datasheet links for every line is in the download package. Three build options exist and they are not interchangeable: the bare IC (what the schematic describes), a breakout module (a shortcut that must be checked against the schematic pin by pin), and a custom PCB (not designed). This revision documents the bare IC; if you build with a module, the checklist explains what to verify.

06 / FIRMWARE

A core that runs
on a desktop.

The arithmetic lives in a platform-free C++ core with no Arduino headers, so it can be compiled and tested without a board. The application layer that touches I²C and the serial port is separate.

Modules

  • Register decode (INA226, no I²C)
  • Calibration per channel
  • Power and trapezoidal energy
  • Missing-data policy and counters
  • I²C and serial application layer

Missing-data policy

An invalid reading costs two intervals — the one ending at it and the one starting from it. 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.

Timing

Milliseconds since boot in an unsigned 32-bit counter; subtraction wraps correctly after 49.7 days. There is no real-time clock in this design, so no date or time of day is claimed.

What has run

Three host suites — 69 + 29 + 10 checks — and a real cross-compilation: PlatformIO 6.2.0 with the espressif32 8.0.0 platform and the Xtensa GCC 14.2.0 toolchain builds firmware.bin for esp32dev, using 25.4 % of flash and 7.2 % of RAM, with no warnings at -Wall -Wextra. It has never been flashed or run.

pio run -e esp32dev g++ -std=c++17 -I include -o /tmp/t src/core/*.cpp test/test_core.cpp
Firmware vector sets and expected results
Vector setDataDurationExpected energyIntegrated / held / gaps
constant12 V, 0.25 A, sampled every 1 s9 s (10 samples)0.007500000 Wh = 27 J9 / 0 / 0
stepCurrent step at 2.5 s, between samples4 s (5 samples)0.003250000 Wh4 / 0 / 0
irregularUneven timestamps: 0, 700 … 3800 ms3.8 s (5 samples)0.002964861 Wh4 / 0 / 0
gap7 s hole between samples at 2 s and 9 s10 s (5 samples)0.004000000 Wh3 / 1 / 1
invalidSensor NACK at 2 s4 s (5 samples)0.001666667 Wh2 / 2 / 0
rollover32-bit millisecond counter wraps2.5 s (3 samples)0.002083333 Wh2 / 0 / 0
zero-currentVoltage present, no load5 s (6 samples)0.000000000 Wh5 / 0 / 0
calibrated+2 % gain, +30 mV offset1 s (2 samples)0.000843563 Wh1 / 0 / 0

The same vectors are fed back through the verified browser model; where the two policies agree the energies match to 1e-12 Wh, and where they differ the difference is asserted rather than hidden.

07 / OPEN QUESTIONS

What only the
physical module can answer.

Six questions that must be answered with a multimeter before the ESP32 is connected to anything.

  1. Address strapsDoes the module actually sit at 0x40? Read it with an I²C scanner.
  2. Pull-up railDo the module's pull-ups go to 3.3 V, 5 V, or the module supply? Measure before wiring.
  3. VBUS connectionIs the bus voltage taken at IN−? If the pin is separate, wire it there.
  4. On-board shuntWhat value is fitted, and does it sit in parallel with the external 0.1 Ω?
  5. Common-mode rangeDoes the module's amplifier accept a 12 V common-mode at the shunt?
  6. Supply qualityDoes the 3.3 V rail hold up under I²C traffic?
DOWNLOAD THE PACKAGE