The best tools to make your project dreams come true

Login or Signup
USD


Halloween Explorer HAT Eyes

By Pimoroni

Courtesy of Pimoroni

Guide by Tanya Fish

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.

Breadboard_1

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.

Connecting_2

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.

Wire_3

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.

Wire2_4

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.

 

Copy Code
#!/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!)

Eyes_5

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!?

Key Parts and Components

Add all Digi-Key Parts to Cart
  • 1778-1016-ND