This is one of those things that is much more complicated than it looks.

You turn it upside down for a short time, and an internal red light toggles. Should be simple, right? Haha, not really – a practical implementation involves a fair bit of engineering. Tiny engineering!

First, the box is 2cm x 3cm x 4cm. The internals are absolutely dominated by a barrel jack connector (not shown). That leaves only a tiny space for a rechargeable battery, charge controller, sensor, control circuit, and a light.

The charge controller is a standard TP4056. The sensor is a tilt-switch, sort of like a capacitor shell filled with ball bearings. This is where things get messy – anyone who has worked with microcontrollers knows about switch debouncing, and tilt switches bounce a lot!

So to make the tilt switch work the way a user expects, we need a low microcontroller with a very small footprint. I selected an Attiny10 – it’s about half the size of a grain of rice. This sits in the deepest of sleep modes, with the INT0 pin pulled high. When the tilt switch pulls that pin low, this triggers an interrupt that initiates a fairly long debouncing routine. This is written in hand-optimized assembly, because that’s what I know best (so I can knock it out in a couple of hours).

Power consumption in standby is measured in nanoamperes. When active, it consumes a few milliamps for the LED (it doesn’t need to be that bright).

For the battery, it had to be small yet high-quality. So, I selected parts I found lying by the side of the road (a common theme). In this case, it meant a shattered Xiaomi smartwatch donated a small but good quality lithium pouch cell.

On standby, the power usage of the device is absolutely dominated by the self-discharge of the battery. In this mode, I estimate it can last around a year. While active, it can last some tens of hours before needing a new charge.

The design was intended for children who want a small comforting nightlight. That’s why you can turn it on by simply turning it upside-down for a few seconds, instead of fumbling in the dark for a switch or button.

One thing I do not like about the design, is it will probably fail after five or so years due to the lithium cell. Children can become very attached to the things that bring them comfort, sometimes treasuring them well into adult life. It would be good to design electronic systems that can accommodate our irrational human attachments. However the limited lifetime of rechargeable batteries make it difficult to design something that lasts this long without making expensive tradeoffs.

For example, I could have used replaceable non-rechargeable batteries. These should last for at least 5 years on standby (low self discharge!), but only maybe 30-60 hours of light. So this means a fair amount of battery replacement. One alternative would be low-light solar charging and a pseudocapacitor, but this is extremely sophisticated and difficult to fit in this form factor. Probably the best choice would be replaceable 3V batteries, and adding an auto-off function after 1 hour of light. This would allow for at least a month of use on a coin cell, and as the device does not rely on writing EEPROM or flash, it should endure for many decades. However, a user-accessible battery holder also takes up a fair amount of space, and would require a custom case.

Anyway, a surprising amount of engineering goes into making simple things that endure.