Overview

Jump scares are fun, but how about a jump scare that is fully automated? Even better! This one uses the HalloWing with a PIR motion sensor, servo motor, and speaker to detect victims and drop a creepy rubber bug right in front of them as it hisses terrifyingly!

You can plug these parts right into your HalloWing, code it in CircuitPython, and get to scaring people in no time.

Parts

1 x Adafruit HalloWing M0 Express
Skull-shaped ATSAMD21 board w 1.44" 128x128 TFT display
1 x PIR (motion) sensor
Passive Infrared detector
1 x Micro Servo
Tiny 180 degree rotation servo
1 x 5V 2.5A Switching power supply
with 20AWG MicroUSB Cable

Materials

In addition to the above parts, you'll need the following:

  • Thin thread or mono-filament fishing line
  • Creepy rubber bug
  • Double stick foam tape
  • Cardstock
  • Cardboard or corrugated plastic for mounting
  • Gaffer's tape

Build the Jump Scare Trap Circuit

Building the circuit for your Jump Scare Trap is quick and easy -- you'll just need to plug a few things into some cables and ports on the HalloWing!

These are the connections to make:

  • Speaker plugs into HalloWing SPEAKER A0 port
  • Servo plugs into JST PH 3-pin to Male Socket cable:
    • Brown servo GND to cable Black
    • Orange servo Power to cable Red
    • Yellow Data line to cable White
  • This servo cable plugs into HalloWing NEOPIX 4 port
  • PIR sensor plug into the JST PH 3-pin to Female Socket cable:
    • PIR GND to Black
    • PIR Data to White
    • PIR +5V to Red
  • Then, plug this cable into the SENSE port on the HalloWing

Mounting

You'll need to mount the circuit on a piece of corrugated plastic or cardboard so it's easier to deploy on your port or door frame.

First, cut a small piece of board roughly 10" x 4", then use a hobby knife to cut a ~2-1/2" square from the board as shown to fit the PIR sensor's lens base (the white square under the dome). This is where the sensor will peek out at your oncoming victims!

Please be careful of any tool or scissors you might use to cut the holes for this project.

Push the PIR sensor into place in the cutout.

Sensor Lens Blocker

By default, the lens has a very wide field of view. This will cause the sensor to trip the alarm when people are approaching from the side. We want to maximize the frights by having them positioned under the trap when it drops its creepy payload in front of them!

Shape the sensor by folding a small piece of black cardstock like a hood and fitting it over the lens, pushing it into the hole you made in the board.

proximity_IMG_1358_2k.jpg

proximity_IMG_1359_2k.jpg

proximity_IMG_1360_2k.jpg

HalloWing & Speaker Mount

Use double stick foam tape to mount the HalloWing to the board as shown here, followed by the speaker.

Servo Mount

Use tape again to mount the micro servo on the board. It is from this spot that is the creepy bug will be staged and then dropped from a length of thread or fishing line!

Next, we'll program the Jump Scare Trap using CircuitPython.

Code with CircuitPython

CircuitPython Setup

For this project you need to ensure your version of CircuitPython is at least 3.0. Adafruit recommends the latest version available by clicking the green button below. Download the file to your Downloads folder, Desktop, etc. (a place you'll remember for the next step).

To load the downloaded file, plug in the HalloWing over USB to your computer and then double-click the reset button on the HalloWing. This will put it into bootloader mode, allowing you to change the firmware. You'll see a USB drive appear on your computer called HALLOWBOOT.

Drag the .uf2 file you downloaded onto the HALLOWBOOT drive. Once it copies over, it will automatically restart, show up as a drive named CIRCUITPY and you will be ready to load a CircuitPython program.

Adafruit really likes using the Mu editor to edit the CircuitPython code. See this guide on loading and using Mu.

Libraries

You'll also need to add a code library for this project. Follow this guide on adding libraries. The only one you'll need is the adafruit_motor folder from the Circuit Python bundle in the lib folder, so just drag it from your downloaded, unzipped lib folder onto the HalloWing's lib folder.

Code Outline

Here's the basic flow of our trap:

  • Startup
  • Rotate the servo arm to the set position
  • Watch for the PIR sensor to be triggered
  • Play hissing sound over the speaker
  • Rotate the servo to drop the creepy bug
  • Wait for the screaming to subside
  • Rotate the servo back to the set position
  • Wait for the user to press the reset cap touch tooth button
  • Begin waiting for the PIR sensor to be tripped again

User Feedback

In order to help you (or your lab assistant Igor) in setting the trap, we'll use the LCD TFT screen on the HalloWing to provide status messages and prompts.

Here are the screens we'll use:

proximity_please_standby.bmp

proximity_trap_set.bmp

proximity_trap_sprung.bmp

proximity_reset_trap.bmp

The simplest way to us the HalloWing screen currently is as an image player to show pre-generated bitmap graphics. Download this .zip file and then uncompress it. Plug in you HalloWing and then drag the four .bmp files onto the root level of your HalloWing's CIRCUITPY USB drive.

Audio Playback

We'll use two methods of audio playback with the audio.play() -- for beeping we'll use the tone playback of a sine wave sample, and for hissing we'll use the audioio.WaveFile() playback method.

Download this wave file and drag it onto your HalloWing's CIRCUITPY drive at the root level.

Code

Here is the code we'll use. Copy it and then paste in Mu. Save it to your HalloWing as code.py

# HalloWing Jump Scare Trap
# use PIR sensor, speaker, and servo
import time
import array
import math
import board
import displayio
import pulseio
from adafruit_motor import servo
import digitalio
import touchio
import audioio
# Setup LED and PIR pins
LED_PIN = board.D13  # Pin number for the board's built in LED.
PIR_PIN = board.SENSE   # Pin port connected to PIR sensor output wire.
# Setup digital input for PIR sensor:
pir = digitalio.DigitalInOut(PIR_PIN)
pir.direction = digitalio.Direction.INPUT
# Setup digital output for LED:
led = digitalio.DigitalInOut(LED_PIN)
led.direction = digitalio.Direction.OUTPUT
# Setup servo
# servo = pulseio.PWMOut(board.D4, frequency=50)
pwm = pulseio.PWMOut(board.D4)
servo = servo.Servo(pwm)

# Setup cap touch button
ready_button = touchio.TouchIn(board.TOUCH1)

def servo_ready():
    servo.angle = 0
def servo_release():
    servo.angle = 90

# Set servo to ready position
servo_ready()
# Function for playing wav file, releasing servo
def play_wave():
    wave_file = open("hiss01.wav", "rb")  # open a wav file
    wave = audioio.WaveFile(wave_file)
    audio.play(wave)  # play the wave file
    led.value = True
    servo_release()
    print('Motion detected!')
    while audio.playing:  # turn on LED, turn servo
        pass
    wave_file.close()  # close the wav file
# Setup audio out pin
audio = audioio.AudioOut(board.A0)

# tone player setup for status beeps
tone_volume = 0.1  # Increase this to increase the volume of the tone.
frequency_hz = 880  # Set this to the Hz of the tone you want to generate.
length = 8000 // frequency_hz
sine_wave = array.array("H", [0] * length)
for i in range(length):
    sine_wave[i] = int((1 + math.sin(math.pi * 2 * i / length)) * tone_volume * (2 ** 15 - 1))
sine_wave_sample = audioio.RawSample(sine_wave)

# Function for beeping, usage: 'beep(3)' will beep 3x
def beep(count):
    for _ in range(count):
        audio.play(sine_wave_sample, loop=True)
        time.sleep(0.1)
        audio.stop()
        time.sleep(0.05)

# Function for counting down, usage: 'countdown(5)'
def countdown(count):
    for k in range(count):
        print(count - k)
        led.value = True
        time.sleep(0.1)
        led.value = False
        time.sleep(1)

# function for blinking, usage: 'blink(5, 0.2)'
def blink(count, speed):
    for _ in range(count):
        led.value = True
        time.sleep(speed)
        led.value = False
        time.sleep(speed)

# display setup
backlight = pulseio.PWMOut(board.TFT_BACKLIGHT)
splash = displayio.Group()
board.DISPLAY.show(splash)
max_brightness = 2 ** 15
backlight.duty_cycle = 0
# Image list
images = ["trap_sprung.bmp", "reset_trap.bmp", "please_standby.bmp",
          "trap_set.bmp"]
# Function for displaying images on HalloWing TFT screen
def show_image(filename):
    image_file = open(filename, "rb")
    odb = displayio.OnDiskBitmap(image_file)
    face = displayio.Sprite(odb, pixel_shader=displayio.ColorConverter(), position=(0, 0))
    backlight.duty_cycle = 0
    splash.append(face)
    # Wait for the image to load.
    board.DISPLAY.wait_for_frame()
    backlight.duty_cycle = max_brightness

beep(1)  # startup beep
show_image(images[2])  # waiting display
print('Stabilizing')
countdown(3)
print('Ready')
blink(3, 0.2)
beep(3)  # ready beeps
triggered = False
ready = True

show_image(images[3])  # ready display

while True:
    # Check PIR sensor
    pir_value = pir.value
    # Check touch button
    ready = ready_button.value

    if pir_value and triggered is not True:
        # PIR is detecting movement!
        play_wave()
        splash.pop()
        show_image(images[0])
        print('Triggered')
        countdown(8)
        blink(3, 0.2)
        beep(1)
        print('Please reset')
        led.value = False
        triggered = True
        servo_ready()
        splash.pop()
        show_image(images[1])

    if ready:  # touch sensor has been pressed
        beep(1)
        splash.pop()
        show_image(images[2])
        countdown(8)
        print('Ready.')
        blink(3, 0.2)
        beep(3)
        splash.pop()
        show_image(images[3])
        triggered = False

Next we'll test out the code and deploy the trap!

Deploy the Jump Scare Trap

Your creepy prop insect or spider is going to be bungee jumping! Loop a length of fishing line or thread around your rubber bug, leaving a bit of slack that can slip over the servo arm. Secure the other end to the board or the servo body so it will be suspended when the bug drops.

You can add a bit of hot glue as seen above to keep the bug positioned properly in the loop.

Please Standby

When you power on the Jump Scare Trap the screen will ask you to "Please Standby" while it resets the servo and allows the PIR sensor to settle. This is when you can hook your bug's release loop around the servo arm.

Trap Set

After it settles, you'll see the "Trap Set" screen.

Trap Sprung!

Now, wave your hand in front of the PIR sensor -- the trap will spring, the hissing sound will play, and the servo arm will rotate to drop the bug payload!

Reset Trap

Now you'll be asked to reset the trap. Loop the bug back over the servo arm and press the left tooth cap touch pad. The screen will then ask you to standby, and then the trap will be once again set and ready to scare the next visitor!

Deploy!

You are ready to deploy the trap! You can use gaffer's tape to attach the board to a porch beam or door frame, with the PIR sensor pointed at the path your visitors will take.

I also ran a USB power cable along the top of the beam to keep the trap running all night long.

This guide was first published on Sep 29, 2018. It was last updated on Sep 29, 2018.