Overview
Using an Arduino, we were able to set up an IR beam to act as a motion detection trigger. When the beam between the two is unbroken, the Arduino controls an AC socket, powering a friendly Jack-o-lantern and porch light. Once the IR beam become broken, the Arduino:- kills power to the AC socket, extinguishing the lights,
- starts the smoke machine, and
- sends a message to my MacBook, causing the MacBook to start playing back spooky sound effects.
After a delay of 3 seconds, the Arduino:
- turns on LED circuits 1 and 2, lighting up the eyes of an evil looking Jack-o-lantern.
After a delay of 27 seconds (total elapsed time is 30 seconds), the effect is considered over. Correspondingly, the Arduino:
- turns off LED circuits 1 and 2,
- stops the smoke machine, and
- turns power back on to the AC socket, lighting the friendly Jack-o-Lantern and porch light back up.
Bill of Materials
Here is what it took for me to get this off of the ground (note that because of the quick turn nature of the project, I leaned heavily towards equipment I already had on hand or could easily get):Item | Cost |
Arduino Uno R3 | $24.95 |
Adafruit Half-sized PCB Protoboard | $4.95 |
Powerswitch Tail2 | $25.95 |
Screw-down terminal blocks | $9.54 |
Project Box | $2.98 |
250 ft 18 AWG Brown lamp cord | $44.40 |
High Intensity Blue LED x 2 | $5.58 ($2.79 ea) |
IR LED Emitter and Detector | $3.99 |
Digitally controlled smoke machine (previous project) | $60 (approx) |
Halloween Decorations | varies |
Miscellaneous LEDs, Resistors, Wires | $10 |
TOTAL | $195 (give or take) |
Connecting it all Up
Here is the circuit diagram diagraming everything:
On the left is the Arduino Uno. All of the pins from the Arduino route to the protoboard, where all of the resistors and LEDs on the left side of the diagram are located. The protoboard then routes to the screw down terminal block, where it interfaces with (starting from the top) the IR detector circuits, smoke machine, AC circuit (via PowerSwitch Tail 2), and LEDs. Not depicted is the USB cable used to for power and serial communications.
And here's how it looks all wired up in the project box:
Project Box - Arduino Uno (left) wired to protoboard (right) in turn wired to terminal block (screwed into right side of the box) |
Arduino Code
If you've never used an Arduino before, do not fret. They are amazingly easy to use. Please visit this page for all the information you'll need to get started.
As with all good projects, I started by googling for similar projects; specifically with regards to IR sensors (as the rest of the project seemed fairly straight forward to me). Ultimately, I settled on this project over at Instructables as a basis for mine. Please be sure to visit that page for tips on how to assemble the IR sensor/detector portion of the circuit.
Starting with the Instructables code, I then defined additional pins for the devices I wanted to control and then an animation subroutine to be run when the IR beam is broken. The complete code can be found here: https://github.com/ScratchesTheItch/Halloween-MotionDetect-Effects.
Computer scripts
Once the Arduino is programmed and calibrated, the circuit will handle motion detection via the IR beam and the resulting lighting/smoke effects on its own. However, if you want associated sound effects, a computer will be required. In my case, that computer is a late model (2007) MacBook with iMovie HD installed. The scripts I used to enable sound effects are relatively simple and can be found here: https://github.com/ScratchesTheItch/Halloween-MotionDetect-Effects/tree/master/scripts.
There are two scripts total. A perl script (halloween.pl) opens up serial communications with the Arduino, listening for a trigger event. Once the trigger is received, a bash script (halloween_sounds.sh) is started to produce the sound effects. Note that both scripts are very set-up dependent(Mac OSX with iMovie HD installed). In order to enable your own sound effects, you will likely have to edit the scripts at least a little bit.
Final assembly
Once the project box is wired up, the Arduino programmed and scripts installed, all that remains is to deploy everything. To do so:
- Connect the computer to the Arduino via a long USB cable. Attach and position speakers (to amplify the sound effects), if so desired.
- Locate the project box in some inconspicuous but central location.
- Place each of the effects (smoke, LED, AC outlet) in their desired location. Connect each effect to the project box via appropriately sized runs of wire, being mindful to keep the positive and negative ends of the circuits straight.
- Calibrate the IR beam again, if needed.
- Enjoy
Issues with deployment
As you might expect, not everything went to plan. The biggest issues had to do with the IR beam. Originally, we had planned on do a beam crossing the entrance to the porch. Unfortunately, that seemed to be a bit too far for reliable operation of the beam (especially before night fall). Rather than deal with an unreliable trigger, we quickly reconfigured to put the trigger around the frame of the door, triggering when the doorbell is rung. That worked much more reliably, although it did require at least one recalibration.The other major issue we had was with recalibration. As night fell, the IR transmitter quickly became easier for the sensor to see, resulting in our threshold being far too low to trigger at night. Thankfully we were able to very quickly recalibrate (a manual process), returning the trigger to reliable service in short order.
No comments:
Post a Comment