Halloween Explorer HAT Eyes

Eyeballs

This is a tutorial to use with an Explorer HAT Pro and some foamy sweets to make a silly Halloween interactive. Once Halloween is over, or the amusement value fades, you can try triggering lights or motors with other squishy sweets.

This was first made by Emma here at Pimoroni Towers, but she's given me the rest of the squishy sweets and her code so you get this tutorial. Woo!

First, you need...

  • 2 x MM (male to male) jumper jerky
  • 1 x 470 Ohm resistor
  • 1 x piezo buzzer
  • 2 x crocodile clip wires
  • 2 x jelly sweets

Put the resistor and buzzer into the breadboard of your Explorer HAT Pro, as shown in the picture below.

Circuit setup

Using jumper jerky, plug one side into GND (ground) and the other into PWM (pulse width modulation) - this makes the circuit for turning the buzzer on and off. PWM means we can do a variety of different frequencies to make the buzzer sound different.

If you've ever wondered what a breadboard actually does, it's a lazy way of connecting circuits. It's just a series of clips hidden under the plastic.

Inside a breadboard

Now to make the eyeball switches. Clip one end of the wire to pad 5 on the Explorer Hat, and the other end needs to be wedged firmly into the sweet.

Making switches

Do the same with the other wire, this time clipping it to pad 8. You can use other pads, but you'll need to change the code.

The whole shebang

Now all the hardware is set up, you need to get some code together to make it work.

Handily, we've written some below, with comments so you can hopefully understand what each bit does. You don't need the comments if you're typing it out.

#!/usr/bin/env python

import time

import explorerhat
import RPi.GPIO as GPIO

# Sets up GPIO pin 18 as the PWM out with a frequency of 60Hz
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
buzzer = GPIO.PWM(18,60)

# Uses a try to keep looking out for eye squishes on the 5 and 8 bare touch pads.
# Change the numbers if you use different ones.
# You could add more eyes or squishies in if you copy the block for a touch pad and
# add it into the while True loop with a different frequency in the brackets.
# Best not to go over 500 unless you're a bat or a dog or something
# If you change the sleep time to a bigger number it will stay on for longer.

try:

    while True:
        if explorerhat.touch.five.is_pressed():
            buzzer.ChangeFrequency(80)
            buzzer.start(1)
            time.sleep(0.5)
            buzzer.stop(1)
        elif explorerhat.touch.eight.is_pressed():
            buzzer.ChangeFrequency(320)
            buzzer.start(1)
            time.sleep(0.5)
            buzzer.stop(1)

# This bit means you can stop the program by pressing ctrl and c.
except KeyboardInterrupt:
    pass

# And this bit cleans up before you leave the place in a right state
# because no one needs telling off.
finally:
    GPIO.cleanup()

Time to run the code and poke some eyes (we are not responsible for you poking the wrong eyes!)

Poking eyes

Once you have the hang of it, try changing the frequencies, or add more squishy eye switches. Maybe you could make it into a Halloween make of your own!?

Shopping basket

Need something for this project? You can use the links below to add products to your Pimoroni Shop basket for easy checkout.

Explorer HAT Pro
£18.00
Explorer HAT Pro Parts Kit
£10.00
Crocodile Leads (set of 10)
£3.00
Raspberry Pi 3 Starter Kit
£89.99
Raspberry Pi 3 Only
£32.00
Official Raspberry Pi Universal Power Supply
£8.00
Want to checkout or change something? Click here to view your cart.

Tutorial
Beginner
Kids, Raspberry Pi

Tanya Fish

tanya@pimoroni.com
@tanurai
http://tanyafishmakes.wordpress.com
Formerly, Tanya worked in various Sheffield schools, teaching maths and physics and shouting loudly at paperwork. Now a crew member at Pimoroni - working on learning materials for schools, workshops, and lasering anything she can get her hands on. Gets very giddy at most things STEAM.