Skip to content
mattix

birdbox

Arduino, ATtiny85 · built June–July 2026 · mattijsf/birdbox

My family had one of those little birds in their toilet, just for the ambient sound. Every time you walked in, a single bird would start singing. Kind of nice. But I kept thinking, what if it got shot every once in a while? You walk in, the bird is happily singing away, and then a big bang. Total silence. I know, it’s a bit dark. But that’s also the fun part, I guess. So that’s how this project started.

My plan was to change the original hardware, so I bought a second bird and opened it up. The sound chip turned out to be a chip-on-board, a bare die under a blob of epoxy on the back of the board, so there was no way to reprogram it. I went with an ATtiny85 instead, together with a light sensor (LDR) and a DFPlayer Mini with an SD card of bird sounds. It had to keep running for months on the batteries without anyone replacing them, and that turned out to work quite well.

First breadboard prototype. It still played short test clips here, so I could hear each wave it picked up.

Everything is built around the batteries. A bare ATtiny85 draws next to nothing in deep sleep, so that’s what I used. It wakes up about once a second, reads the light and goes back to sleep. Once a second is often enough not to miss anyone, and rare enough for the batteries to last months.

The bird only has the light sensor to notice someone walking in, and it needs to work at night in the dark, in daylight and with the lamp on. So it doesn’t look at the light level itself, but at how much it differs from a baseline that follows the ambient light. A sudden change, like a shadow or a reflection, counts as someone walking in.

When it triggers, it plays a random track on the DFPlayer. The DFPlayer keeps drawing current even when it’s not playing, so a MOSFET switches its power on for the track and off again afterwards. Then the bird ignores the light until at least a minute after the track started, so walking in and switching on the light only gives one sound. When you switch it on it plays one track straight away. That’s my test for the batteries, the SD card and the speaker.

The breadboard version in the video worked on the table. Getting it to work in the toilet, on batteries and in every kind of light, took a lot longer.

First the light sensor. The reading goes from about 0 in the dark to about 975 in daylight, and an LDR isn’t linear. One fixed threshold can’t cover that. In dim light someone walking in only changes the reading by 8 or so, and in daylight the sensor noise alone is already a few steps. A cloud or the hallway light changes the light within seconds, so the baseline has to keep up, but not so fast that it misses someone walking in. And walking in and switching on the light is a jump that stays, so after a trigger the baseline starts again from a fresh reading.

Guessing numbers didn’t get me there, so I wrote a small debugger sketch. It sends the light readings over serial, and I press a button whenever someone actually moves. I recorded five situations in the toilet, and a Python script replays them at one reading per second, like the bird. It compares the detections with the button presses and shows what gets caught and what fires for nothing. I tried a plain threshold and CUSUM that way. The prototype used CUSUM, the final firmware is back to a threshold: a small fixed step for the dark, plus a part that grows with the light so daylight noise stays below it. A hand wave in bright daylight it still misses, the change is too small.

Breadboard prototype on the toilet shelf next to the white bird, with a speaker and a power bank

Testing in its natural habitat.

I also tried a bigger 4 Ω 3 W speaker. On USB that worked. On the AAA batteries the DFPlayer reset as soon as a sound got loud. A 10 Ω resistor in series and a 330 µF capacitor didn’t help, AAA cells just can’t deliver those current peaks. The 330 µF capacitor I had is rated for 64 V, so it was 3 to 4 cm tall. Too big for the bird anyway. So it’s back to the 8 Ω 0.25 W speaker, without the resistor because that made it too quiet, and a small 100 µF capacitor. The DFPlayer’s amplifier can do 3 W and the speaker is rated for 0.25 W, so I keep the volume at 17 out of 30.

The speaker also pops when the power is cut. The shutdown order sets the volume to 0, puts the DFPlayer to sleep, waits a bit and releases the TX pin, so the player can’t get power through it. The pop is still there. A 1 kΩ resistor across the capacitor to drain it didn’t change it either. The voltage dropped to 0.4 V right away and took about 15 seconds to reach 0, and the pop sounded the same. So it’s not the capacitor, it’s the way the MOSFET switches. The IRLR8743PBF is an N-channel on the DFPlayer’s ground, so VCC stays connected and the amplifier’s DC bias drops through the speaker. A P-channel MOSFET on VCC should fix it, but this was the one I had.

Once it all worked I went over the firmware to clean it up and save power. The ATtiny85 runs at 1 MHz and has no hardware UART, so the serial line to the DFPlayer ran in software, with the SoftwareSerial library. That library also listens for incoming data, but the DFPlayer’s TX line isn’t even connected. So I replaced it with a few lines of C that only send. A few changes later the bird didn’t make a sound at all.

I went back to the last build that worked and added the changes back one by one, until the serial code turned out to be the only problem. And that’s where the cycles come in.

Serial has no clock line. The DFPlayer only sees the line go low for the start bit, and from there it counts on its own clock and reads every next bit halfway through, at the moment it expects it. Each byte goes over the line as ten bits: a start bit, the eight bits of the byte and a stop bit. At 9600 baud a bit lasts 104 µs, and at 1 MHz that’s only 104 clock cycles for the ATtiny85. So one cycle is already 1%.

My C code set the pin and then waited for the rest of the bit. The loop around it takes time too, so I subtracted 8 cycles from the wait as an estimate. But how many cycles that loop really takes depends on what the compiler makes of it. Say every bit ends up 5 cycles off. That’s about 5%, and by the tenth bit you’re 50 cycles off, half a bit. Then the DFPlayer reads its sample at the wrong moment and gets a wrong bit. A DFPlayer command is ten bytes with a checksum, so one wrong bit and the whole command gets thrown away. No error, nothing. The bird just stays quiet.

In C you don’t decide how many cycles a loop takes, the compiler does. In assembly you do. So I rewrote the loop in assembly and counted every instruction. Each bit now takes 103 cycles, every time. That’s 1% off the ideal 104, which is fine.

The last one was small. The SD card was sometimes slow to start a track and the firmware gave up too early. Waiting a bit longer fixed that.

The opened bird with the original circuit board, a speaker and the new electronics wired in

Inside the bird.

When it was done I swapped my bird for theirs. Their first reaction was that someone must have turned on a feature, or that the box got some kind of update, because they heard sounds they hadn’t heard before. They didn’t expect me to have built a new one. Once they got the joke they really appreciated it and thought it was very funny. I had a lot of fun building it, so a good result in the end.

To build one yourself, put the sounds in folder 01 on the SD card, named 001.mp3 to 010.mp3. Open vogelbox/vogelbox.ino in the Arduino IDE with an ATtiny85 core, set the clock to 1 MHz internal and flash it with an ISP programmer. The README has the pinout, and the header of the sketch explains each constant.

Part For
Toilet bird The case. The original board is still inside
ATtiny85 Runs the firmware, at 1 MHz on the internal clock
LDR and a resistor Light sensor, as a voltage divider on A3
DFPlayer Mini Plays the MP3s and drives the speaker
microSD card Ten bird sounds in folder 01
IRLR8743PBF N-channel MOSFET Switches the DFPlayer’s ground, so it only draws power while playing
100 µF electrolytic capacitor Across VCC and GND of the DFPlayer, behind the MOSFET, so it doesn’t drain the batteries in sleep
8 Ω 0.25 W speaker On the DFPlayer’s speaker output, no series resistor
3 × AAA batteries 4.5 V
ISP programmer Flashing the ATtiny85
Push button Only for the debugger sketch, on pin 2, to mark real movement

No trackers or cookies. Older designs of this site.