Build an MHS-Inspired Light Lab¶
| Category | Creative & Real-World AI Builds |
| Status | ๐ก Partially completed |
| Repo | nextwork-build-an-mhs-inspired-light-lab |
| Original NextWork guide | nextwork.ai |
Learning project
Practice work following a NextWork guide, separate from my production projects.
๐ NextWork learning project. This is a practice project I built while working through NextWork's Build an MHS-Inspired Light Lab guide. It is part of my Learning portfolio and is fully separate from my production projects.
Category: Learning โบ Creative & Real-World AI Builds
Status: ๐ก Partial
Overview¶
Letting an AI agent touch hardware needs a boundary the hardware itself enforces. Here a small host bridge caps brightness and always switches the LED off, Claude Code may run only one approved experiment script, and every claim in the report is checked against a measured sweep.
Summary¶
Built end to end on a simulated Arduino. The firmware, bridge, client and sweep are my own code (rewritten from scratch). The firmware compiles for a real Uno and Nano with arduino-cli and runs unchanged in a firmware-in-the-loop simulator: serial over a pseudo-terminal, with a modelled PWM LED and photoresistor divider. The bounded bridge refuses 255 and switches 180 off after exactly 10 s, where the open profile left 255 on. The real Claude Code CLI ran only the allowed python run_experiment.py and was refused direct set 255 and read. The sweep wrote 50 readings with an error-bar plot, and a hidden sensor-power fault was diagnosed with bounded commands. Partial because there is no physical rig and the model behind Claude Code is a scripted stand-in.
The checks behind this are in docs/verification.txt.
Skills & tools¶
Arduino (C++), pyserial, Python sockets, Firmware-in-the-loop simulation, Claude Code permissions, matplotlib
What I built¶
arduino_driver/arduino_driver.ino: line protocol on 115200 baud (SET n0-255,READ,STOP, otherwiseERROR COMMAND).docs/firmware-compile.txt: arduino-cli compiles it for Uno and Nano (2900 bytes).sim/arduino_sim.cpp+tools/sim.sh: compiles the same sketch against a tiny Arduino API shim. Serial is a pseudo-terminal, pin 9 drives a modelled LED, and A0 returns a noisy photoresistor/10 kฮฉ divider reading. Every LED change is timestamped in a log outside the repo.bridge.py: a JSON-over-TCP bridge on 127.0.0.1. Theboundedprofile (default) has a ceiling of 180 and auto-off after 10 s;--profile openis the first unsafe version (0-255, no timer), kept for comparison.device_client.py: CLI pluslab_call()for scripts.docs/serial-monitor.txt: SET 90 โ OK SET 90, READ โ LIGHT 642, STOP, then BLINK / SET 300 โ ERROR COMMAND.docs/safety-boundary-run.txt(tools/safety_demo.sh): the open profile left 255 on for 12 s until a manual stop. The bounded profile refused 255 ("value must be 0..180") and its timer switched 180 off exactly 10.000 s later.EXPERIMENT.mdand.claude/settings.jsonallow onlyBash(python run_experiment.py).docs/claude-code-experiment-run.md: the real Claude Code CLI (scripted stand-in model) ran the sweep, anddevice_client.py set 255/readwere refused with "This command requires approval".run_experiment.pyโresults.csv(51 lines) andlight_response.png, also copied todocs/.docs/final-check.txtis the end-to-end check.REPORT.mdis one paragraph I wrote from that run (trend, repeatability โค 1.6 counts, spread, one limitation).docs/earlier-run/holds the first pass's local-model draft and my review of it.- Secret mission,
tools/secret_mission.pyโdocs/secret-mission.txt: with a hidden sensor-power fault, every command still said OK but readings stayed near 0 at all levels, which points to the sensor supply. After the fix, readings matched the earlier sweep within 2.4 counts (RECOVERED).
How to run¶
python3 -m venv ~/.nw-lightlab-venv && ~/.nw-lightlab-venv/bin/pip install pyserial==3.5 matplotlib
export PATH=~/.nw-lightlab-venv/bin:$PATH LIGHTLAB_PORT=8766
tools/sim.sh start
python tools/serial_monitor.py ~/.nw-lightlab/ttyArduino
tools/safety_demo.sh
python bridge.py ~/.nw-lightlab/ttyArduino &
python run_experiment.py
wc -l results.csv; ls light_response.png
tools/sim.sh fault-on; python tools/secret_mission.py diagnose
tools/sim.sh fault-off; python tools/secret_mission.py confirm
tools/sim.sh stop
Verification¶
I ran the verification command on 2026-12-02. The full output is in docs/verification.txt.
python3 -m py_compile bridge.py device_client.py run_experiment.py tools/secret_mission.py tools/serial_monitor.py && g++ -std=c++17 -include cstdarg -o /tmp/lightlab_sim_check sim/arduino_sim.cpp -lutil && test $(wc -l < results.csv) -eq 51 && grep -q 'value must be 0..180' docs/safety-boundary-run.txt && grep -q 'auto-off: LED stopped by the bridge timer' docs/safety-boundary-run.txt && grep -q 'RECOVERED' docs/secret-mission.txt && grep -q '"allow": \["Bash(python run_experiment.py)"\]' .claude/settings.json && grep -q 'This command requires approval' docs/claude-code-experiment-run.md && echo LIGHTLAB OK
Notes¶
Port 8765 was taken on this shared machine, so the bridge and client read LIGHTLAB_PORT (default 8765). The same build agent injected the secret-mission fault and wrote the diagnosis, so it shows the method rather than being a blind test. For headless Claude Code to apply the project allow rule, the folder was marked trusted in an isolated Claude Code config.
What isn't done, and why¶
No physical Arduino, LED or photoresistor: the measurements describe the simulator's model. Claude Code is the real CLI, but the model behind it is a scripted stand-in that only emits the tool calls under test, so Claude Code didn't write the firmware or scripts.
Original project: https://nextwork.ai/projects/6d60bf15-437e-43fc-9997-6fe849b082c0 ยท Part of my NextWork Learning portfolio (hub).
Verification output¶
From docs/verification.txt:
$ python3 -m py_compile bridge.py device_client.py run_experiment.py tools/secret_mission.py tools/serial_monitor.py && g++ -std=c++17 -include cstdarg -o /tmp/lightlab_sim_check sim/arduino_sim.cpp -lutil && test $(wc -l < results.csv) -eq 51 && grep -q 'value must be 0..180' docs/safety-boundary-run.txt && grep -q 'auto-off: LED stopped by the bridge timer' docs/safety-boundary-run.txt && grep -q 'RECOVERED' docs/secret-mission.txt && grep -q '"allow": \["Bash(python run_experiment.py)"\]' .claude/settings.json && grep -q 'This command requires approval' docs/claude-code-experiment-run.md && echo LIGHTLAB OK
LIGHTLAB OK
[exit code 0]