The Crackerjoke-a-tron

In the UK, plus a few other countries here and there, no Christmas table is complete without the traditional Christmas cracker next to every plate.

The Christmas cracker is a cardboard tube, tied shut at both ends. When two people pull it apart, an inner ‘snapper’ gives off a bang while the cracker’s contents fall into your mashed potatoes and gravy. There’s usually a paper hat that tears the moment you try to fit it on your head (or falls away with the after-dinner meat sweats), a gift that tends to be something like a magic trick, a miniature sewing kit or a golf tee, along with a joke, like this one:

What’s orange and sounds like a parrot?

A carrot.

Cracker jokes are notorious for being awful.

Because of this, I have created the Crackerjoke-a-tron. It’s the ultimate joke response unit that allows you to pronounce judgement upon the jokes at this year’s Christmas table.

To make your own Crackerjoke-a-tron, you’ll need:

  • a Raspberry Pi (any model will work)
  • 2 x tactile push buttons
  • a speaker with a standard 3.5 mm jack

If you don’t fancy soldering, you’ll also need:

  • a breadboard
  • 2 x male-to-male jumper leads
  • 5 x female-to-male jumper leads

To add lights, you’ll need:

  • a red LED
  • a green LED
  • 2 x 330 ohm resistors

You can download the .wav files you will need directly to your Pi.

Create a new folder on your Pi called ‘crackerjoke’ by entering the following into a terminal window:

mkdir crackerjoke

You can then enter this folder using this command:

cd crackerjoke

To download the .wav files to your Pi, use this:

wget -O goodjoke.wav

And then this:

wget -O badjoke.wav

To make sure the files play, try typing the following (make sure to plug in your speaker or some headphones):

aplay goodjoke.wav

If this works, you’re ready to get your code written and your buttons and lights set up.

First, we’ll put the components in place. Here’s a picture of what to expect:


The GPIO pins we are using are as follows:

  • Good joke button = pin 21
  • Bad joke button = pin 24
  • Red LED = pin 8
  • Green LED = pin 7

If you have a breadboard, ground everything as standard. If you don’t, make sure you ground all your LEDs and GPIO pins.

Now it’s time for the code. Open Python 3, create a new file within the crackerjoke folder called ‘’ and type the following:

import pygame.mixer
from pygame.mixer import Sound
from gpiozero import Button, LED
from signal import pause


good = Sound("/home/pi/crackerjoke/goodjoke.wav")
bad = Sound("/home/pi/crackerjoke/badjoke.wav")

good_button = Button(21)
bad_button = Button(24)

red = LED(8, initial_value=True)
green = LED(7, initial_value=True)

good_button.when_pressed =
bad_button.when_pressed =


Save your code, press F5, and you should be good to go.

If you’d like the code to run on reboot, allowing you to detach yourself from the monitor, keyboard, and mouse, open a terminal window and type:

nano ~/.config/lxsession/LXDE-pi/autostart

At the bottom of the file, add:

@python /home/pi/crackerjoke/

Save and reboot.

If you make the Crackerjoke-a-tron, don’t forget to share a picture or a video with us via social media, using the hashtag #BerryXmas.


Liz Upton avatar

Q: What did Adam say the day before Christmas?

A: “It’s Christmas Eve.”

henry avatar


The Grinch avatar

There’ll be no need to bother downloading unless you get your crackers from M&S, Waitrose, Harrods or Fortnums. ALL cracker jokes are cornier than anything from

Q. Where do fish sleep?
A. In a water bed

Liz Upton avatar

Ha – love the new name!

Alex Bate avatar

Why did the Grinch go to the liquor store?

To get some Christmas spirit.


Dan Fisher avatar

What does Santa suffer from if he gets stuck in a chimney?Claustrophobia.

Steph avatar

What do you call a guy with no calves?

Katharine avatar

What do you call a Pokemon who can’t see?
I can’t Pikachu

Alex Bate avatar

How do you get Pikachu on a bus?
Poke him on.

Matt avatar

What did one snowman say to the other?
“Can you smell carrot?”

The Grinch avatar

Q: What do you call a bat with a carrot in each ear?
A: Anything you want as he can’t hear you!

David Booth avatar

“a Raspberry Pi (any model will work)”, probably not a zero unless you have an audio socket kit, or am I wrong?

mahjongg avatar

A zero has audio through HDMI.

Bill Edwards avatar

Which one of Santa’s reindeer do you hardly ever hear about?

Olive, the other reindeer…..

Alex Bate avatar

Haha, that took me a moment.

Alex Bate avatar

From my mum:

Can dogs operate an MRI?
No, but Catscan.

Russell Davis avatar

How many elephants can you fit in a mini?

4, 2 in the front and 2 in the back

Alex Bate avatar

How do you get two whales in a car?


Simon Long avatar

M4, surely! The M6 gets you to Carlisle…

Liz Upton avatar

Where do you weigh a whale?
At a whale-weigh station.

Russell Davis avatar

Why did the elephant paint his toe nails red?

so he could hide in a cherry tree

Russell Davis avatar

what’s is hairy, got 66 legs, 8 eyes & large dripping fangs?

I don’t know either but there’s one on your shoulder

Russell Davis avatar

What did the grape say when they elephant trod on it?

nothing it just let out a little whine

MalMan35 avatar

What do you call an old snowman?

Why did the belt go to jail?
It held up a pair of pants.

BTW Great project Alex!

Alex Bate avatar

Thank you :D

Ken Warren avatar

Why do ducks have flat feet?
So they can stamp out fires.

Ken Warren avatar

How do elephants get flat feet?
From jumping out of cherry trees onto burning ducks!

Norman Dunbar avatar

Where do you go to find out how heavy a pie is?
Somewhere over the rainbow.
(Weigh a pie)


I’ll get my coat!


Yerba1 avatar

Where does a Pirate hide his Buccaneers?

Under his Buccanhat

Max Power avatar

But can you come up with something to keep the confetti from getting in my dinner?

henry avatar

I could not get the program to start on reboot as the instructions said. Has anyone else been able to do that?
Other than that, it works great! I’m going to use it at our next team meeting.

henry avatar

Update to my comment earlier about not getting the to run in autostart. It seems like it does start because both lights turn on. However, when I press the buttons, no sound go off. The program does work when I run it manually. Any ideas? Thanks. – Henry

henry avatar

Here is an alternate way of having the Pi start the program, then after ten (10) jokes, it shuts down the OS:

# links:

# External module imports
import RPi.GPIO as GPIO
import time
import os
import sys

import pygame.mixer
from pygame.mixer import Sound

# Pin Definitons:
pwmPin = 27
ledPin = 22
butPin = 17
butRed = 24




# Pin Setup:
GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme
GPIO.setup(ledPin, GPIO.OUT) # LED pin set as output
GPIO.setup(pwmPin, GPIO.OUT) # PWM pin set as output

GPIO.setup(butPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Button pin set as input w/ pull-up
GPIO.setup(butRed, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Button pin set as input w/ pull-up

# Initial state for LEDs:
GPIO.output(ledPin, GPIO.HIGH)
GPIO.output(pwmPin, GPIO.HIGH)

while i < 10:
if GPIO.input(butRed) == False: # button is pressed
i = i + 1
os.system("sudo aplay /home/pi/PiBoard/badjoke.wav")

if GPIO.input(butPin) == False: # button is pressed
i = i + 1
os.system("sudo aplay /home/pi/PiBoard/goodjoke.wav")

GPIO.output(pwmPin, GPIO.LOW)
GPIO.output(ledPin, GPIO.LOW)
GPIO.cleanup() # cleanup all GPIO
os.system("sudo shutdown -P")

kevin avatar

this doesnt play sound on the rasberry pi 3 model b i did everything that it says there is a folder and everything and still doesnt work and i need to know what might be the problem because i am doing this for a school project if you know email me asap

Comments are closed