Introduction: Motion Activated AC Switch
I hate Christmas tree lights.
Well not really, I just don't enjoy having to climb under the tree every time I want to plug in or unplug the lights. In the interest of saving my sanity, I decided to build a motion activated switch that can power the lights for me. It has an integrated adjustable timer so they will stay on for as long or as short as I want. Here's a video showing the final test on the fish tank light.
Step 1: Safety and the Parts and Tools List
First, a word about safety. We will be working directly with AC mains voltage, so BE EXTREMELY CAREFUL!! Make sure that any time you are testing the circuit, you have your work space clear and anyone around you is aware of the danger. Also, don't burn yourself with the soldering iron. It is hot. Don't be that person.
I salvage what I need/want from whatever device I can get my hands on. Most parts are still useful as long as you take care in how you remove them from the original board. That being said, none of the parts are expensive, so it shouldn't be hard to come across them if need be. Also, many times the exact part is not absolutely required, just something that is compatible, e.g. a 2N2222 NPN BJT instead of the 2N3904 listed.
- 1 power transformer. Any transformer that has a step down factor of 10 will work here. We want an output of about 12-15VAC, but if your outlet supplies 220VAC, it will still work.
- 1 board mounted outlet. You can find these on the back of DVD players, home theater systems, and VCRs.
- 1 rubber grommet. This one came with the AC power cable attached to the transformer and is used to secure the cable to the housing. Very handy if you can get one.
- AC power cable. We don't need a grounded cable here, so 2 wires will do fine.
- board pins as needed/desired for connecting AC lines. You can also solder directly to the copper pads but it may not be as secure.
- 1 board mounted fuse holder. I used a 5X20mm fuse.
- 1 fuse rated for slightly less than the relay max current rating. Mine is a 250VAC 4A, slow blow.
- 1 555 timer IC with 8-pin socket. Any brand will work.
- 1 7809 +9VDC voltage regulator. You can use whatever regulator you have so long as it matches the DC input rating on your relay switch. You also don't want a 7909 regulator as it will provide -9VDC, which you don't want.
- 1 Parallax PIR sensor. Found mine at radioshack for about $10.
- 1 2N3904 bipolar junction transistor, or BJT. Any NPN BJT should work here.
- 4 1N4001 rectifying diodes. You can also get a bridge rectifier if you want, since that is what we are going to build.
- 3 capacitors: 1 0.01uF (103) ceramic disc; 1 470uF electrolytic; 1 large electrolytic. I used a 1000uF. The large electrolytic will be used to run the timer, so the bigger it is, the longer your max time can be.
- 4 resistors: 2 1k; 1 4.7k; 1 10k
- 1 potentiometer. Mine is a 4 megaOhm pot. This pot will allow for adjusting the timer. With the 1000uF cap, mine will run for about 2.5 hours.
- 1 9VDC relay. The coil voltage should match the regulator voltage. The switch portion of the relay needs to have a decently high current rating since we will be running AC current directly through here to the device we want to power. Mine is rated for 250VAC 5A.
- 1 LED and 1k resistor (optional, LED not pictured). Used mostly for testing, I didn't keep it for the final build.
- screws, wires, heat shrink, glue as needed
- plastic project enclosure
- printed PCB
- Digilent Analog Discovery. Highly recommended as it will allow you to verify circuit function using the built in oscilloscope.
- soldering iron and solder. I use a 40W for just about everything.
- wire cutter/stripper, pliers, hobby knife, screwdriver
- breadboard for testing
- digital multimeter
- saw and/or rotary tool (not pictured)
Step 2: Design
The basic idea is that we first step down 120VAC (or 220VAC) down by a factor of ten. We then rectify and smooth that to get rid of the negative part of the wave, which allows us to then regulate it to a usable, stable 9VDC voltage. The PIR can't use 9VDC though, so we will be dividing it down to 4.5VDC just for that part.
Step 3: Testing
Get yourself a breadboard, and some wires or jumpers, for testing if you don't already have one. I use it every time I build. You don't want to be soldering and cutting and find out you did it all wrong. Don't say I didn't warn you.
Each subsystem is broken off into smaller bits to make building and testing easier. Make sure each subsystem works before attaching it all together as one big circuit. It makes debugging way easier and less frustrating.
Step 4: AC/DC Conversion
Again, we are stepping down AC mains voltage by a factor of 10. The 4 diodes are configured as a bridge rectifier. Make sure to get the connections correct here. It can be very confusing when putting it on a board. Or get a bridge rectifier as a discrete part. The 470uF cap keeps the voltage high enough to be used by the regulator. You need the input to the regulator to stay higher than it's rated output or you won't get a stable output. With this setup, I could use a 7812 regulator for +12VDC, but just barely and no more than that.
As mentioned before, be very careful when testing this sub-circuit. Since the output here is 9VDC, you can use a 9V battery to test subsequent systems without exposing yourself to live AC.
Step 5: Timer Circuit
I found the original schematic for this circuit in Forrest M. Mims' book Basic Electronics: Transistors and Integrated Circuits, page 91. A wonderful book by a fantastic author. I've used this circuit several times before and will again. I modified it by changing the pot/cap pair to meet my needs and removing the buzzer. The original circuit also has a push button momentary switch between the trigger (pin 2) and ground to activate it. I've changed it to use the output from the PIR sensor, but the the 555 requires a logical low signal to trigger and the PIR outputs a logical high. That problem is solved by using the NPN BJT. More on that later. Just know that if you want to use this circuit elsewhere, the trigger must be a low signal. The 4.7k resistor acts as a pull-up resistor to keep the signal high when no signal is coming from the PIR sensor.
You'll probably notice that adjusting the timer value is not very precise. Using larger value components makes it so that the tiniest change on the pot makes a big difference in time. It's the nature of analog circuits, and I think it's part of the appeal for me. If you want exact precision, I recommend a chipKIT microprocessor board from Digilent Inc.
Step 6: The PIR Sensor
Really simple connections with this part, though the BJT is easy to switch around backwards. The PIR is designed to be used primarily with microprocessors, like the Digilent chipKIT Uno32, so it can only handle 3-6VDC input, so the two 1k resistors form the voltage divider we need to drop the 9VDC supply down to 4.5VDC.
Step 7: The Relay and AC Passthrough
Easy connections here too, though we are using AC voltage again when testing. The AC outlet, with a 4A fuse connected, will run a fair bit of power through it. I only plan on using this project where I don't need very much power, e.g. LED Christmas lights instead of incandescent. Keep your power needs and circuit limitations in mind as you design and use your own version.
Step 8: Building and Finishing
Be aware of space limitations inside your enclosure as you are placing and soldering the parts to the PCB. The AC outlet should have screw holes on the side to securely mount it to the case, so plan for that as well. You also don't want anything to short out inside after it's closed, so keep an eye out for exposed contacts and such.
You may very well make a mistake, no matter how hard you try. I got the outer leads on the BJT switched around and it wouldn't do anything for me. I went through the whole thing, testing voltages until I found the problem, de-soldered the wrong connections and then re-soldered correctly. I also forgot to feed the PIR wires through the case before soldering to the board.
I designed the whole thing to sit underneath my Christmas tree skirt, so the PIR sensor will need to be placed up into the tree. I have a length of cable attaching it to the box, which saves space inside, but may require a design change should I want to put the PIR inside in another application.
Please don't hesitate to ask questions, either below in the comments or PM. Have fun building!
ASCAS made it!
We have a be nice policy.
Please be positive and constructive.