It’s Halloween today, so it’s time for a new project.
Some time ago, my son very casually said: “Hey dad, I would like a talking witch for Halloween”.
Challenge accepted!
Components
I ordered the necessary components:
- A Raspberry Pi Zero WH (bottom right) for the programming
- A HiFiBerry MiniAMP (bottom middle) to play sound
- A PIR sensor for the motion detection part
- A speaker

Assembly
It’s very easy to connect the Pi Zero and the MiniAMP. The MiniAMP is a HAT (Hardware Attached on Top), so you can just slide it on the GPIO pins of the Pi Zero.
But the PIR sensor poses a problem then. All the GPIO pins are used by the HAT, and there are no free pins anymore for the PIR sensor.
The MiniAMP actually only uses a couple of pins (as described in their support pages). It is possible to solder the PIR sensor to the unused pins of the MiniAMP board, but that’s a rather permanent solution.
Instead, I reused a small GPIO pin reference board. I soldered the PIR sensor to that board, and added the board between the Pi Zero and the HAT.
After that, I built a Lego case to hold all the electronics, and to protect it in case of rain. This case can also be attached to the witch itself.
Programming
The program plays a random sound whenever motion is detected.
import RPi.GPIO as GPIO
import time
import pygame
import random
#initialize motion sensor
GPIO.setmode(GPIO.BCM)
PIN = 12
GPIO.setup(PIN, GPIO.IN)
#initialize sound
pygame.mixer.pre_init(frequency=44100, size=-16, channels=2, buffer=4096)
pygame.mixer.init()
pygame.mixer.music.set_volume(0.5)
#sound list
_sounds = ['Witch01.mp3','Witch02.mp3','Witch03.mp3','Witch04.mp3','Witch05.mp3','Witch06.mp3']
#wait till sensor is activated
print ("Start sensor...")
time.sleep(2)
print ("Sensor activated...")
while True:
if GPIO.input(PIN):
print ("Movement detected! " + (time.strftime("%H:%M:%S")))
next_sound = random.choice(_sounds)
pygame.mixer.music.load("/home/pi/Documents/Programs/WickedWitch/Sounds/"+next_sound)
pygame.mixer.music.play()
while pygame.mixer.music.get_busy() == True:
pass
time.sleep(30)
time.sleep(0.1)
The Wicked Witch
And here she is…

Related posts
If you’re looking for more Halloween-related posts, then you check the pumpkins of last year and the year before. Or you can check my scary cupcakes.
And for more Raspberry Pi fun, you can check for example the timer button, the hedgehog photo booth or the automatic roller shutter.
6 thoughts on “The Wicked Witch”