[
  {
    "slug": "smart-energy-monitoring",
    "title": "Smart Energy Monitoring",
    "status": "designed",
    "category": "Embedded Systems · Energy",
    "tags": [
      "concept",
      "embedded systems",
      "energy monitoring"
    ],
    "date": "2026-11",
    "summary": "A low-voltage DC energy monitor: a verified software model of the measurement chain, a native KiCad schematic that passes ERC, and firmware that cross-compiles for the ESP32. No prototype has been built.",
    "objective": "Explore how embedded measurement and electrical energy data can be combined in a documented monitoring system.",
    "problem": "Electrical energy data is only useful if the reader knows how far to trust it. A monitor that reports 12.00 W is making a claim about a whole chain — divider, shunt, amplifier, ADC, arithmetic and clock — and each link contributes an error that the others do not cancel.",
    "approach": "The chain was built in software first, so every stage could be inspected and tested: source and load solved together, sensing with gain, offset, noise and quantisation, sampled power and trapezoidal energy. The electrical design and firmware followed from that model, and each carries its own evidence — reference tests, a KiCad ERC report, a cross-compiled binary, a netlist comparison — none of which is a measurement of hardware.",
    "results_note": "Verified: a software model (67 reference assertions, 594 independent checks), a native KiCad schematic with a clean ERC report, and firmware that cross-compiles for the ESP32 and passes 98 host checks. Not done: no PCB, no assembled board, no flashed firmware, no measurement, no calibration.",
    "case_study_url": "/projects/smart-energy-monitoring.html",
    "case_study": {
      "overview": "A design brief for a low-voltage DC energy-monitoring system, and the first working artefact that follows it: a software model of the whole measurement chain — DC source, load, voltage and current sensing, ADC quantisation, sampled power and trapezoidal energy accumulation — with the formulas, source, reference cases and an independent verification suite published alongside it.",
      "application": "The intended application is low-voltage, supervised measurement of an appliance or small installation: enough to answer “what is this load actually drawing, and when?” without claiming revenue-grade accuracy or mains-connected deployment.",
      "requirements": [
        {
          "id": "R1",
          "text": "Measure voltage and current of a single low-voltage DC load at a useful rate (at least tens of samples per second) and derive power."
        },
        {
          "id": "R2",
          "text": "Keep measurement uncertainty stated, with a calibration procedure against a reference meter."
        },
        {
          "id": "R3",
          "text": "Record or display data locally so a network outage does not lose the measurement."
        },
        {
          "id": "R4",
          "text": "Stay inside a supervised, low-voltage boundary; any mains-referenced variant requires isolation review before it is attempted."
        },
        {
          "id": "R5",
          "text": "Publish the architecture, calibration method and test conditions alongside any number, so a reader can check the claim."
        }
      ],
      "sensing_options": [
        {
          "method": "Shunt resistor + current-sense amplifier",
          "note": "Best linearity and low-side simplicity; adds a small series drop and needs attention to common-mode range if used high-side."
        },
        {
          "method": "Hall-effect current sensor",
          "note": "Isolated by construction, simpler to wire, but offset drift and temperature behaviour need checking against the datasheet."
        },
        {
          "method": "Resistive divider for voltage",
          "note": "Cheap and predictable, but the divider loads the node and its impedance must suit the ADC sample-and-hold."
        },
        {
          "method": "Energy-monitoring IC with integrated ADCs",
          "note": "Fewer analog decisions to make, less of the signal chain to learn — a trade of effort against understanding."
        }
      ],
      "architecture_label": "Proposed functional roles · no component has been selected",
      "architecture": [
        {
          "name": "Electrical input",
          "detail": "A low-voltage measurement boundary; source, range and isolation approach are still open."
        },
        {
          "name": "Signal path",
          "detail": "A proposed conditioning and sampling stage; gain, filtering and reference are undecided."
        },
        {
          "name": "Embedded processing",
          "detail": "A candidate role for RMS and power computation; firmware is not written."
        },
        {
          "name": "Data use",
          "detail": "Possible logging or display direction; interface and connectivity are undecided."
        }
      ],
      "mcu_options": [
        {
          "model": "ESP32 class",
          "note": "Wi-Fi and a capable ADC on one part; ADC linearity needs care and calibration."
        },
        {
          "model": "STM32 class",
          "note": "Better analog peripherals and deterministic timing; connectivity needs additional design."
        },
        {
          "model": "External ADC + any MCU",
          "note": "Moves accuracy requirements into a component with a proper datasheet, at the cost of board complexity."
        }
      ],
      "isolation": "The first study stays low-voltage and supervised. A mains-referenced version would need galvanic isolation, creepage and clearance decisions, protective devices and review by someone qualified to sign it off — that is out of scope for this record.",
      "validation": [
        "Run the reference suite and compare its printed table with the published values before trusting any number on the site.",
        "Re-derive the power and energy relations independently; the independent suite exists so a self-consistent error cannot pass both.",
        "For hardware, compare against a calibrated reference meter at several operating points and record the instrument, wiring, load and ambient conditions.",
        "Publish failed checks as well as passing ones, and state the tolerance with every claim."
      ],
      "roadmap": [
        {
          "stage": "Concept",
          "status": "Complete",
          "deliverable": "The design brief and the open-questions list."
        },
        {
          "stage": "Requirements",
          "status": "Complete",
          "deliverable": "Requirements S1–S13 and N1–N5 with their acceptance criteria."
        },
        {
          "stage": "Architecture",
          "status": "Complete",
          "deliverable": "Signal path, module structure and the two-path truth/measurement design."
        },
        {
          "stage": "Simulation",
          "status": "Complete",
          "deliverable": "Software Model V1: model, reference tests, independent verification, datasets and instrument."
        },
        {
          "stage": "Hardware",
          "status": "Not started",
          "deliverable": "Schematic, board revision and firmware for a supervised low-voltage prototype."
        },
        {
          "stage": "Validation",
          "status": "Not started",
          "deliverable": "Bench comparison against a reference meter with conditions recorded."
        }
      ],
      "open_questions": [
        "Which measurable quantity and operating range should the first study address?",
        "Shunt, Hall-effect, or integrated monitor — which trade-off is worth learning first?",
        "How is the ADC reference stabilised so the measurement means something?",
        "What information would make the output useful without implying more accuracy than the measurement supports?"
      ],
      "future_directions": [
        "Publish the requirements table once the operating range is chosen.",
        "Compare candidate sensing approaches from datasheets and a signal-chain model.",
        "Only publish a schematic, simulation or firmware when those artifacts exist."
      ],
      "results": [
        "Software Model V1 passes 67 reference assertions (cases A–G) and 594 independent checks across ten groups.",
        "Energy matches hand-derived values exactly where the mathematics is exact: 43 200 J (12 Wh) at 12 V/1 A for 3600 s, 18 000 J (5 Wh) at 5 V/2 A for 1800 s.",
        "A step that straddles one sample interval is quantified, not hidden: 26 997.5 J against a 27 000 J continuous ideal, a 0.0093 % difference that halves with the square of the sample interval.",
        "Variable sampling is handled from real timestamps: an irregular five-interval profile integrates to the hand-computed 77.605 J, while a mean × time estimate would give 77.973 J.",
        "Measurement error behaves as the equations predict: +2 % gain and a 50 mV offset produce a 10.4 V reading of a 10 V input, and calibration recovers 10.000 V exactly.",
        "Invalid data is classified and refused rather than integrated into a plausible-looking total."
      ],
      "limitations": [
        "No hardware accuracy of any kind: no sensor, ADC, microcontroller or board has been used or measured.",
        "DC only, single channel, non-isolated: no AC, mains or grid measurement.",
        "No ADC non-idealities (INL, DNL, reference drift), no fixed-point arithmetic and no timer jitter.",
        "Loads that change faster than the sample interval are aliased, exactly as they would be in real firmware.",
        "No filtering design, no loop response, no thermal or ageing behaviour."
      ]
    },
    "software_status": "Software Model V1 — verified against reference cases",
    "hardware_status": "Hardware design prepared — prototype not built",
    "demo_url": "/projects/dc-energy-monitor.html",
    "demo_label": "Launch the DC Energy Monitor",
    "hardware_url": "/projects/dc-energy-monitor-hardware.html",
    "milestones": [
      {
        "name": "Concept",
        "state": "done",
        "status": "Completed",
        "detail": "The problem, the measurement question and the safety boundary, written before any design existed.",
        "evidence": [
          {
            "label": "Project record",
            "href": "/projects.json"
          }
        ]
      },
      {
        "name": "Software model",
        "state": "done",
        "status": "Implemented and reference-tested",
        "detail": "The whole measurement chain in software: source, load, sensing, ADC, sampled power, trapezoidal energy. Seven reference cases and 594 independent checks.",
        "evidence": [
          {
            "label": "Model source",
            "href": "/energy-monitor/model/dcem.js"
          },
          {
            "label": "Reference tests",
            "href": "/energy-monitor/tests/dcem-reference.test.js"
          },
          {
            "label": "Independent tests",
            "href": "/energy-monitor/tests/dcem-independent.test.js"
          },
          {
            "label": "Run the instrument",
            "href": "/projects/dc-energy-monitor.html"
          }
        ]
      },
      {
        "name": "Hardware requirements",
        "state": "done",
        "status": "Documented (draft for review)",
        "detail": "E1–E12 with acceptance criteria, each marked verified against a datasheet or script, or proposed.",
        "evidence": [
          {
            "label": "Electrical requirements",
            "href": "/energy-monitor/hardware/requirements/electrical-requirements.md"
          }
        ]
      },
      {
        "name": "Electrical design",
        "state": "done",
        "status": "Schematic authored, ERC clean",
        "detail": "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.",
        "evidence": [
          {
            "label": "KiCad schematic",
            "href": "/energy-monitor/hardware/kicad/dcm-hw-v1.kicad_sch"
          },
          {
            "label": "ERC report",
            "href": "/energy-monitor/hardware/kicad/erc-report.txt"
          },
          {
            "label": "Design review",
            "href": "/energy-monitor/hardware/design-review/design-review.md"
          },
          {
            "label": "Hardware design page",
            "href": "/projects/dc-energy-monitor-hardware.html"
          }
        ]
      },
      {
        "name": "Embedded firmware",
        "state": "done",
        "status": "Host-tested and cross-compiled",
        "detail": "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.",
        "evidence": [
          {
            "label": "Build evidence",
            "href": "/energy-monitor/firmware/BUILD-EVIDENCE.md"
          },
          {
            "label": "Application layer",
            "href": "/energy-monitor/firmware/src/main.cpp"
          },
          {
            "label": "Sensor driver",
            "href": "/energy-monitor/firmware/src/core/sensor.cpp"
          },
          {
            "label": "Mock-bus tests",
            "href": "/energy-monitor/firmware/test/test_sensor.cpp"
          }
        ]
      },
      {
        "name": "Physical prototype",
        "state": "pending",
        "status": "Not built",
        "detail": "No component purchased, no board assembled, nothing energised.",
        "evidence": [
          {
            "label": "Prototype review checklist",
            "href": "/energy-monitor/hardware/design-review/prototype-review-checklist.md"
          }
        ]
      },
      {
        "name": "Calibration",
        "state": "pending",
        "status": "Not performed",
        "detail": "Procedure and blank recording sheet exist; no instrument has been compared with anything.",
        "evidence": [
          {
            "label": "Calibration plan",
            "href": "/energy-monitor/verification/calibration-plan/calibration-plan.md"
          }
        ]
      },
      {
        "name": "Physical validation",
        "state": "pending",
        "status": "Unavailable",
        "detail": "No measurement against a reference meter. This is the only thing that could turn the design into an accuracy claim.",
        "evidence": []
      }
    ]
  }
]
