Computerise Your Halloween for Under $30

by JustinLovesTheTech in Circuits > Arduino

12208 Views, 161 Favorites, 0 Comments

Computerise Your Halloween for Under $30

VID 20161018 171053055
IMG_20161018_165721131_HDR.jpg
IMG_20161018_172310769.jpg
IMG_20161018_172344942.jpg
IMG_20161018_172424643.jpg
IMG_20161018_172524483.jpg
IMG_20161018_173324241.jpg

I have been doing computer controlled lighting displays for years now, for Christmas and Halloween mainly, but I do it with almost $1000 of hardware and software, and I was thinking what can be done for $30? So I pulled out my arduino and relay board and got to work! This is a very simple instructables and can be completed in 15 minutes.

Parts List;

Arduino Uno (knock off is cheaper) $07.00

Relay board $14.99

LDR AKA Light Dependable Resistor

4.7K Ohm resistor

Laser Diode $10.95

Extension cable

12V DC wall adapter

2 conductor ~24awg wire

Tools;

Small phillips or flathead screwdriver

Wire cutters

Multimeter

Meter probes (I like to have ones with alligator clips)

Other Items

Computer to program the Arduino

USB cable to connect Arduino

Lights to control

And that's it! You might have all of these things laying around! So let's get started!

High voltage is dangerous and can cause injury or death to property, livestock, humans, and more. If you continue you take on all of the responsibilities of safety and can not find me liable to any injury or property damage that might happen if you attempt this project in part or whole.

How Do It Do What?

Let's start off explaining what I wanted to accomplish. I wanted to make is so that when someone walked past a certain point mains voltage lights would trigger, wait 3 seconds, then turn off until the next person shows up.

Over the years I have attempted to make several methods to detect when someone has passed a certain point, my primary method in the past is various designs of pressure plates, but this year I attempted to use lasers, AND IT WORKED! It worked very well at that, and they are easier and cheaper to set up. The way that the laser system works is that you will have a laser diode pointing at a LDR aka Light Dependent Resistor or photoresistor and that will cause it to have a low resistance and effectively act as a closed circuit, but when someone walks by they will interrupt the beam going from the laser to the LDR effectively making it an open circuit. We can use the Arduino to detect whether the laser is hitting the LDR or not and then activate the lights accordingly. But you might be thinking "You can't run 120V lights off an Arduino!" and you would be correct! This is where the relay board comes in handy, the Arduino sends a signal to the relay board and then activates one or more relays, thus turning on the lights, as relays can use a very small voltage and amperage to control a very large voltage and amperage.

CIRCUIT!

Untitled Sketch_bb.png
IMG_20161018_165624592.jpg
IMG_20161018_165645466.jpg
IMG_20161018_165735364_HDR.jpg
IMG_20161018_165746354.jpg

Ok this is pretty simple in reality, and I wanted to prove that it can be done without soldering, so it is a tad bit messy.

So the basics are similar to what I did in my computer controlled fireworks show Instructables, basically you need to take the 12V wall adapter and cut off the end, then strip the wires and connect them to the + and - screw terminals on the relay board, thus supplying power to it. Powering the relay board will bake it output 5V across the 5V and GND pins, we will use this to power the Arduino. What you need to do is take 2 wires acd connect +5V to the red rail pin on the breadboard and connect the GND pin to the black rail on the breadboard, then use 2 more wires to connect the rails on the breadboard to +5V and GND on the Arduino, as these pins are not only capable of outputting power, but can also be used to supply the Arduino with power, but this dose bypass all of the Arduinos protection circuitry so be careful! Now we need to connect the relays to the Arduino, on the relay board they all have individual pins marked 1 to 16, if you want to control all of them separately you will need to use a bigger Arduino like the Arduino Mega, but basically you just need to take one wire from the pin of the relay that you want to use and connect it to a pin on the Arduino, in my case I used pin 11, and if you want to use my exact code I recommend that you do the same.

Now to connect the LDR. This is a bit harder as I am attempting to use an analog signal to control a digital pin, but it is not possible, basically we will need to make a simple voltage divider with the LDR and the 4.7K Ohm resistor (this value may vary depending on the ambient light but I find that 4.7K Ohm works in most conditions.). The LDR will have one leg connected to the 3.3V pin on the Arduino, and the other leg will connect to a pin on the Arduino, in my case I used pin 3, now you will need one leg of the resistor to go to the same pin, and the other leg of the resistor to go to ground, this will make our voltage divider that will make out analog input (light on the LDR) work on the digital pin of the arduino, this will massively simplify the code required to make this work. Just make sure to remember that the LDR needs to be where the trigger is so give it some long wires.

You will also need to connect the laser diode, to do this you attach wires to +5V and GND, these wires will need to run to where the trigger will be placed so don't make them too short.

Relay Connects

IMG_20161016_182853510.jpg
IMG_20161018_165701378.jpg

So this is the simplest step, but BE CAREFUL as these will be live wires, I HIGHLY recommend covering exposed wire with electrical tape or heat shrink tubing.

All you need to do is use you wire cutters to separate and the strip one of the wires on the extension cord (if you are using a cord with 3 wires make sure that you are not separating the GND (green) wire as this won't work and will actually create a safety hazard)

Now take each end of the stripped wires and connect them to the center and upper connections on the relay board (center and lower on relays 8-16) and then you can plug in the extension cord and whatever is connected to it will be controlled by the relay. REMEMBER there is exposed circuitry on the bottom of the board that will have LIVE 120V electricity flowing through it as soon as the cord is plugged in, so BE CAREFUL!

If you are using more than one relay you have 2 options, 1 use this method on all of the relays and plug all of the cords into a power strip, or 2 have one male end cord that you plug into an outlet and separate female ends for each relay, have one wire of the male connector connect to the middle terminal of all of the relays, and have the other wire on the mail connector connect to one wire of all of the female connectors, then have each of the female connector other wires plug into one of the relay terminals. This is the method that I used in my Computer Controlled Fireworks Display, check out my other Instructables to learn more about this method.

Code!

Ok this bit is already done, I have attached the code that is needed, you can just download that and put it on your arduino, but that will only work with one input and one output so I will explain the code so that you can modify it to whatever you want.

void setup()
{

pinMode(3, INPUT); //The LDR is connected to pin 3

pinMode(11, OUTPUT); //The relay is connected to pin 11

digitalWrite(11, HIGH); //Turn relay off

}

void loop()

{

if (digitalRead(3) == LOW) //If the laser is not shining on the LDR

{

digitalWrite(11, LOW); //Turn on relay

delay(3000); //Wait 3 seconds

digitalWrite(11, HIGH); //Turn off relay

}

}

And that is it! Basically there is an infinite loop looking to see if the laser beam is broken, and if it is it turns on the relay for 3000/1000ths of a second (3 seconds) and the turns it off again. If you want more triggers, just update the inputs at the top and add more if statements, you can just copy the existing if statement and change the pin number. If you want a different timing just adjust the delay, say you want a 5 second delay, just change the delay from 3000 to 5000

Final Work!

Untitled-laser.png
VID 20161018 171053055

Ok now all that you need to do is place the LDR and Laser diode. You can basically put them anywhere as long as the laser is shining on the LDR, they can be 100' from each other, alto I wouldn't recommend it. Using a sidewalk as an example I would recommend drilling a small hole, the size of the laser diode in a stake, hammering it into the ground next to the sidewalk and then placing the laser diode in the hole, it should fit just by friction alone, but if needed you can use some glue to hold it in. Then on the other side of the sidewalk drive another stake into the ground and tape the wires for the LDR to it, I would recommend you using solid core wire and leaving an extra inch or two dangling so that you can position the LDR in the perfect spot.

Now just plug in the 12V power brick and the extension cord and connect some lights or maybe a siren to the extension cord and you are ready to go!

Tanks for reading, please vote for me in the contests that I am entered in! Thanks everyone

Be warned, if you make it on a small scale it is kind of like the useless machine as when you turn it on it turns itself off, you might play with it for a while. :P