Laser Blinkenlights

Posted:

This project is a replacement for a device I made many years ago to decorate someone else's PC with LEDs that flashed based on CPU usage. The original stopped working some time ago after a Windows upgrade, probably due to driver problems for the USB to serial adapter. Drivers for those things are a constant source of problems, so I thought I would replace it with something implemented completely in hardware, so it can't become broken due to software changes. To make it a bit different to last time, I used lasers instead of LEDs, because lasers are cool.

It's not possible to directly measure CPU usage externally, but it can be inferred from power consumption, which is proportional to current consumption, which can be easily measured thanks to the modern ATX form factor requiring the CPU to have its own power cable. To make it as non-invasive as possible, I used a Hall-effect sensor to measure current, which it does indirectly via the magnetic field around a cable generated by the current it carries. The particular sensor I used is a DRV5056-A1, which has decent sensitivity and is unipolar (it only needs to measure current in one direction).

The magnetic field is weak, so it needs to be concentrated onto the sensor by surrounding the cable with a magnetic core. I don't know exactly what sort of core the one I used is - it's just the highest permeability core of suitable size I could find in my parts drawer, with a slot cut in it to fit the sensor into. Given the metallic appearance of the bit that was cut, it might be powdered iron or other metals, but not ferrite.

A cable with heatshrink over one end, concealing a small sensor. A green toroidal core. A piece of wood with a groove cut into it the same shape as the core, and another groove that the sensor would fit into. A u-shaped piece of metal large enough to slide over the piece of wood and the core together.
The sensor is on the left, soldered to some wires and wrapped in heatshrink. The magnetic core is the green ring. The other parts are for holding everything together.

To hold the sensor in the right position relative to the core, I carved a little bit of wood. I used oak for this, as it's strong enough to not split when cut into thin shapes. This is then clamped to the core by a piece of aluminium that I cut out of an old external hard drive enclosure.

A CPU power cable, with the 12V wires passing through the green toroidal core. The sensor is inserted into the gap in the core, with the wooden and aluminium mounting hardware holding it in place.
This is how it all fits together on the cable. Most PSU cables have uniformly black wires nowadays, making it harder to work out which wires are the relevant ones.
A close-up of the corner of the motherboard where the CPU power cable attaches. The cable has the current sensor installed onto it.
Installed. I had to pull the sleeving on the power cable back a bit to expose the wires. Fortunately these wires are colour coded - just place the core around the yellow ones.

The sensor outputs a voltage proportional to the magnetic field strength, which is itself proportional to the current. This is then read by a microcontroller, which turns it into a pattern to blink some lasers.

Schematic drawn in KiCad. It consists of an 8-pin microcontroller, four laser diodes, a hall-effect sensor, and a few filtering components.
With all the complexity hidden inside the microcontroller, there are hardly any physical components needed.
PCB layout, 30x30mm
Tiny PCB.

The microcontroller, a PIC12F1571, reads the output from the sensor periodically, and adds the value to a running total, which is effectively the total amount of energy used by the CPU. This is then converted into a balanced Gray code, which is output to the lasers. The Gray code has no real meaning - it's just to look nice. Every time the recorded energy use increases enough, the output pattern changes. Thus the rate that the lasers flash represents the amount of power the CPU is using. It's self-calibrating, automatically scaling the output according to the peak current that it has measured since powering up. This allows it to work with CPUs of different power consumption without having to change anything.

This is written in C suitable for Microchip's XC8 compiler.
The PCB with all the components soldered to it. It's screwed to four stand-offs, which are in turn glued onto a rectangular magnet.
The completed PCB, attached to a ferrite magnet so it can be easily stuck to a steel PC case without needing any tools.

For the lasers, I got four cheap laser diode modules. These conveniently have built-in linear constant-current drivers, and the metal casing provides enough heatsinking that they can run continuously. They produce a cross-shaped pattern rather than the dot you might expect from a laser. This spreads the light out over a larger area, making it more visible.

Four laser modules, consisting of metal tubes with lenses screwed over one end, and wires emerging from the other end.
I wrapped each module in heatshrink together with a magnet, for attachment to a steel case, the same as the PCB.

Anf finally, this is what it looks like working in the recipient's PC.

.
A still image doesn't give the right impression.
Disco mode.