LEDSDL: A Self-Driving Lab for Color, Built Around a Tiny Machine That Can Learn
An ESP32, a spectral sensor, and a stochastic optimizer turn RGB light into a closed-loop experiment. The result is a desk-scale lab that measures its own output, scores the result, and tries again.
- LEDSDL treats color as a physical experiment, not a set of RGB numbers, so the machine learns by measuring what it actually produced.
- The project’s real invention is its feedback loop, which combines sensor data, scoring, and stochastic search into a tiny self-driving lab.
- Its scoring function values both spectral match and brightness, so a dim near-match cannot fake success.
- The web UI and Thought buffer make the optimization process legible, which turns embedded hardware into something you can inspect as it works.
Most LED projects stop at control. LEDSDL goes further: it turns an RGB LED into an experiment that can look at its own output, judge it, and try a better guess. That makes it feel less like a gadget and more like a miniature lab bench.
The repo is built around a simple but sharp idea. Light is not just set, it is measured. A 10-channel spectral sensor reads the result, a scoring function compares it to a target, and a search loop keeps adjusting until the match improves.
Why color is harder than RGB numbers
In software, color often looks tidy. Three channels, a hex value, done. LEDSDL pushes back on that simplification by treating color as a spectrum that has to survive the physical world before it can be called correct.
That matters because the same LED setting can behave differently once the sensor, enclosure, and ambient conditions get involved. The project’s real subject is not color theory in the abstract. It is measurement under constraint.
How the machine scores itself
The heart of the repo is computeScore. It does not just ask whether the measured spectrum is close to the target spectrum. It normalizes the measurement, compares it with an L2 distance, and adds a luminosity penalty so darkness cannot cheat the result.
// Conceptual shape of the scoring logic
score = l2_distance(normalized_measured_spectrum, target_spectrum)
score += brightness_penalty_if_too_dim(measured_luminance)
// Lower is better.
// A dim near-match should lose to a bright accurate match.
That choice is small on paper and important in practice. It encodes a policy judgment: a physically good color is not just chromatically correct, it also has to be bright enough to matter. The score is a piece of engineering and a piece of taste.
The search loop: from guess to better guess
The optimizer is not trying to be clever in a grand AI sense. It is trying to be disciplined. It samples candidates, compares scores, accepts improvements, and keeps a history of what happened along the way.
That is the important distinction. This is not a scripted LED preset library. It is a stochastic search loop living inside a physical system, where every improvement has to survive measurement noise, sensor response, and the quirks of the enclosure.
The project’s language makes that visible. A Thought buffer records the machine’s latest move, the score, and whether the last candidate improved the result. That turns an embedded optimization run into something that can be watched instead of trusted on faith.
The UI makes the experiment legible
The web interface is not decoration. It is part of the instrument. Because the ESP32 serves state asynchronously, the browser can show the current score, the thought log, and the running history without pausing the loop that is doing the actual work.
That matters for two reasons. First, it makes the system debuggable. Second, it makes the optimization feel honest. You can see when the machine is exploring, when it is improving, and when it is stuck.
This is where the repo earns the phrase self-driving lab. The board is not hidden behind a serial console. It publishes its internal state to a browser, which gives the loop a public face.
What the CircuitPython fallback says about the project
| Mode | Input | Feedback loop | What it is good for | What it cannot do |
|---|---|---|---|---|
| Self-driving LEDSDL loop | Target spectrum plus stochastic candidate settings | Yes. Measure, score, accept, retry | Autonomous color search with visible reasoning | It is more complex than a basic hardware test |
| CircuitPython fallback in code.py | Manual serial commands for RGB values | No. Output is set directly | Quick bring-up and simple LED control | It cannot discover better colors on its own |
That contrast is useful because it shows the boundary of the project. code.py is scaffolding, a practical way to poke the hardware. The main C++ firmware is the actual experiment engine.
What makes this feel like a real lab, not a demo
The physical details matter. The enclosure shields the sensor from ambient light. Non-volatile storage keeps WiFi credentials across restarts. Static buffers keep memory use predictable on the ESP32. The STL files make the hardware reproducible instead of implied.
That combination is what separates a weekend proof of concept from a thoughtful instrument. LEDSDL is small, but it respects the constraints of real hardware, which is why the loop can keep running without turning into a toy.
If you zoom out, the repo is a clean example of a broader pattern: take a physical process, measure it, score it, and let software search inside that feedback loop. The result is not just automation. It is a machine that learns by doing.





