Friday, September 26, 2025

Pico audio 7: Build a Zwitscherbox

For an index to all my stories, click this text

My girlfriend got a birthday present from a friend. Nothing to write about you would think. But it was a Zwitscherbox. Never heard of it ??? Neither did I. Read on.



A Zwitscherbox is a simple concept. It is a box with some kind of a microcontroller inside (no I did not take it apart), a speaker and a PIR. Every time you pass by, the PIR detects movement, and the box plays the sound of birds singing.

Simple, but effective and fun. And most of the time it brings a smile to your face. So a real fun present.

I looked it up on the internet and was amazed at the price. It was a rather expensive gift at 50 to 60 Euro (USD).

That got me thinking. How difficult would it be to build one myself. Well actually it is dead simple.

Playing audio with a microcontroller.

There are several ways to play audio with a microcontroller. You can add an MP3 player like I did it this story: http://lucstechblog.blogspot.com/2019/10/web-controlled-mp3-player.html

Another method is to use the Raspberry Pi Pico as an audio player. I have written a few stories on using a Raspberry Pi Pico as an audio player. You just need a few cheap components. It can be build in 15 minutes or so. And like stated before, the audio quality is very good. I chose this option for this project.

Raspberry Pi Pico audio player.

To build an audio player with the Raspberry Pi pico you will need a few simple components. You will need a few resistors, some capacitors and (for larger audio files) an SD card with an adapter. If you can solder, you can use the SD adapter that is included with most micro-sd cards. If you can not solder you can use an SD-card adapter for microcontrollers.

I wrote several stories on this subject and it would be wise to read these first before continuing this story.

The audio file has to be in WAV format and you can use Audacity to convert an MP3 file to a 8K wave file. The following link takes you to my story on how to achieve this:
https://lucstechblog.blogspot.com/2024/10/audacity-pico-audio-part-1.html

The Raspberry Pi Pico audio player hardware can be found here:
https://lucstechblog.blogspot.com/2024/10/audio-on-pico-part-2-hardware.html

The Raspberry Pi Pico software (Micropython) can be found here:
https://lucstechblog.blogspot.com/2024/10/pico-audio-part-3.html

Attaching an SD card:
https://lucstechblog.blogspot.com/2025/01/pico-sdcard-part-1-hardware.html

Software for Pico and SD card:
https://lucstechblog.blogspot.com/2025/01/pico-sd-card-part-2-software.html

For this project we need to add a PIR.
You can read the basics on how a PIR works here: https://lucstechblog.blogspot.com/2017/01/pir-basics-movement-detection.html

Alternatively you could use a radar module like this one:
http://lucstechblog.blogspot.com/2018/08/motion-detection-with-rcwl-0516-radar.html

They both work the same way so rummage through your stock and use what you have got.

The breadboard setup.

Basically it is the setup from the Pico audio player. You can use that for testing. When everything works as planned just remove the buttons and the Oled screen. If you want to use that setup just look at this story: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx




I just added one thing to this setup and that is a PIR.
The VCC of the PIR MUST be connected to the VBUS connection of the Pico as it needs 5 Volt.
The PIR is further connected to GP21 and to GND.
If you are not building this on top of the Pico Audio Player you can attach the PIR to any GPIO you like. Just make sure you adjust the program to use the selected pin.

And that's all for the hardware side.

The audio file.

For replicating the Zwitscherbox I needed an audiofile of a bird singing. There are many sites on the internet that offer royalty free sounds. I found a nice audio file that plays a blackbird singing. It runs for about 2 minutes. Ideal for this project. You can download it here:

https://quicksounds.com/sound/4769/blackbird-in-town-3

Next step is to import the file into (free software) Audacity and convert it to an 8K wav file. In a previous story in this series I described how to do that. You can find that story here: 
https://lucstechblog.blogspot.com/2024/10/audacity-pico-audio-part-1.html

When the audio file was converted I stored it on the SD card that is attached to the Pico in the directory music with the name "Blackbird.wav"

Zwitscherbox software

Basically this is the same program that was used for the Talking Dice. The program is written in MicroPython.

import os as uos
import time
from machine import SPI, Pin
import sdcard
from wavePlayer import wavePlayer

spi = SPI(1,sck=Pin(14), mosi=Pin(15), miso=Pin(12))
cs = Pin(13)
sd = sdcard.SDCard(spi, cs)

pir=machine.Pin(21, machine.Pin.IN)

uos.mount(sd, '/sd')

player = wavePlayer()

print(uos.listdir('/sd/Music'))
time.sleep(10)

try:
    while True:
      print(pir.value())   
      if (pir.value() == 1):
        player.play('/sd/Music/Blackbird.wav')
        time.sleep(5)
      time.sleep(0.3)
except KeyboardInterrupt:
    player.stop()
    print("wave player terminated")


For testing purposes I build a keyboard interrupt into the program. Pressing CTRL-C on the keyboard, while the Pico is connected to Thonny, stops the program and shuts the audio player down.

Like said before and as can be seen in the schematics: the PIR is connected to GPIO 21 on the Raspberry Pi Pico.

Almost everything is identical to the previous audio programs except for this part:

      if (pir.value() == 1):
        player.play('/sd/Music/Blackbird.wav')
        time.sleep(5)
      time.sleep(0.3)

First the program tests if the PIR signal is high. If that is the case then someone is passing by. The player then plays the blackbird sound witch is stored on the attached SD card in the directory Music. The program then waits 5 seconds so the PIR can settle down and then runs again.

Concluding.

The Raspberry Pi Pico with MicroPython is a golden combination that is easy to program and enormous versatile.
The Zwitscherbox clone is an easy build and great fun. It makes a fantastic present for a fraction of the price of the original.

Next step is to design and build a nice casing.........

Till next time
Have fun


Luc Volders