Products for USB Sensing and Control

Products for USB Sensing and Control

Hack Your Halloween with Phidgets


by Lucas

Source Code

Introduction

This project will show you how you can "hack" your Halloween decorations and get them to behave exactly how you want!

The Halloween decoration we are working with has the following default functionality:

  • Activated by throwing switch (shown in video)
  • Activated by a loud sound
  • Our goal for this project is to make it motion activated instead!

What You'll Need

You will also need a soldering iron, some wire strippers, and some basic programming knowledge. We wrote the program that controls the decoration in C.

Is Your Decoration "Hackable"?

The first step is figuring out if you can modify your Halloween decoration. Usually, decorations will have a demo mode that will activate the electronic component of the decoration with a simple button or switch. If this is the case, you are in luck. You can simply replace the button with a relay in order to control the system

You can see the button that is used for demo mode in this picture.

Project Overview

This project will have the following layout:

  • PhidgetSBC4 will run our program code (written in C). It will be connected to the DST1200 sonar sensor and the REL2002 signal relay through the built in VINT Hub.
  • The sonar sensor will be be used to detect objects.
  • The relay will be connected to the demo wire of the decoration, and will be used to activate the decoration based on the readings from the sonar sensor.


Modifying Your Decoration

Cut Button Connection

In order to add our relay, we will need to remove the button. Simply cut the wires close to the button, and then strip off some of the insulation.

Add Relay

Take the wires from the button and connect them to the relay. Connect one wire to the Common terminal and one to the Normally Open terminal.

Mount Sonar Sensor

Where you place the sonar sensor will depend on your application. This project will be installed in a outdoor haunted house where visibility will be low, so having the sonar sensor sit directly on top won't be a problem. Alternatively, you could mount the sonar above a doorway, or pointing up from the ground if you wanted to hide it.

We used some glue to mount the sonar sensor. Double-sided tape would also work great!

Decide If You Need An Enclosure

This project will be outside, so having the electronics protected is essential. The SBC will sit inside a waterproof enclosure with the relay. We extended the relay connection to the decoration by soldering on some wire, and we used a 350cm long Phidget Cable to connect the SBC to the sonar sensor.

Software

All the code for this project is already written and is included in the file halloween.c, so if you want to implement it, all you will have to do is modify a few things (serial numbers, timing, etc.) and compile it. You can compile it via the terminal on the SBC with the following command.

  
gcc halloween.c -o runfile -lphidget22

Here is a quick overview of the code:

  • Create DistanceSensor and DigitalOutput objects.
  • Address Phidgets. See this video for more information.
  • Subscribe to attach & detach events for the sonar and relay.
  • In sonar attach event, set the data interval to 100ms (the minimum data interval)
  • Subscribe to distance change events for the sonar.
  • In distance change events, see if the object is closer than 1 metre, if it is, set the objectDetected variable to 1.
  • In while loop, check if object has been detected. If so, turn relay on and then off (this will activate the decoration). Wait for four seconds, and then deactivate the decoration.

Installation Pictures

Coming Soon!