Introduction: Motion Activated AC Switch

Picture of 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

Picture of 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.

The Parts:

- 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

The Tools:

- 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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!


JesseG85 (author)2017-10-13

Would you have any idea on how to get the effects I'm looking for it or could you point me in the right direction I saw a hall effect circuit that does basically what I need it to do but I guess you have to have a magnet in your hand while waving is there some way I could maybe have two coils and cause them to Arc maybe something like that?

JesseG85 (author)2017-09-28

hi ive been trying to figure out how to build a close range motion on/ motion off switch for a power supply so that i wave my hand over the sensor to turn it on and it will stay on til i wave my hand over it again to turn it off. is that what this circuit is meant to or could do? here is an example:

brmarcum (author)JesseG852017-09-28

No, this circuit will not turn off when you wave your hand in front of it. This circuit will turn on with motion and then stay on for a set amount of time. All motion will be ignored once it has turned on, but once it turns off you can move in front of it to turn it on again.

JesseG85 (author)brmarcum2017-10-04

I found what I was looking for i think

yogesh thakare (author)2016-03-29

what if i use an old mobile charger adapter to step down from 220v to 5v and remaining ciruit same ,will i have to change anything else or replace any component?

thank you

rameezkoya007 (author)2014-08-07

I have a doubt.
Help me please.
can I connect two PIR sensor in the circuit ?.
I yes ,how?
If it's possible I could place those sensors on the the either sides of my garden pavement.

brmarcum (author)rameezkoya0072014-08-25

Yes absolutely. The best way I can think of to do it is to pass the two inputs from the two PIR sensors through an OR gate on an IC (like this one). That way, when either sensor triggers, the timer starts and the lights go on.

rameezkoya007 (author)brmarcum2016-03-08

A PIR sensor senses a human or animal right ?

Then how could i modify this circuit to sense my car or bike as well ?

coolkids (author)2015-04-03

hey what do i do if i get 0v btw pin 3 and gnd

thanks in advance

brmarcum (author)coolkids2015-04-03

There may be a couple of reasons for it.

1) Bad 555. Swap it with a new one. Probably not this since 555s are pretty tough little ICs.

2) Circuit was built wrong. This is much more likely. No offense intended, I get stuff crossed all the time. Double check everything, and if it still doesn't work, rip it apart and start over. This is why we test everything on a breadboard first.

3) Bad component. A good DMM will allow you to check just about any passive component except for inductors, and then you can check the inductor's internal resistance (generally if the resistance is within spec, it's still good, though may not be). Check capacitors C2 and C3. The 555 may not be able to function properly because one or both may be bad.

That's what comes to mind. Keep me posted.

darius.mackun (author)2015-02-15

Sorry for maybe sounding a little bit stupid I'm kinda new to this, although I get a big voltage drop across the relay, I get like 2 Volts, what might be the problem ?

brmarcum (author)darius.mackun2015-02-15

Don't apologize for learning.

Where are you getting 2V? Look back at the schematic and use that as a reference for me to visualize.

darius.mackun (author)brmarcum2015-02-15

Thank you kind sir for your reply. Across the coil of the relay I get 2 V , in the step 7 schematic, out from where it's written "to 555 pin3 (output)" to "GND". If I test those two ends with my multimeter it shows 2V. Plus I'm using 12V relay, cause the shop didn't have 9V relays, and I'm using 220V AC conversion to 12V DC, I think that it should be alright anyways because my PIR has max voltage of 15V and 555 as I read in the datasheet can handle until 15V too

brmarcum (author)darius.mackun2015-02-15

A few thoughts come to mind:

1) check the voltage coming from the 555 pin 3 to GND without the relay connected. It should be almost the same as your input voltage to the 555. If it's not, the problem is most likely not the relay.

2) Are you sure you have the relay coil terminals connected between the 555 and GND and not the relay switch terminals?

3) What is the step-down factor of your transformer? You input 220VAC, what AC voltage do you get out of the other side of the windings, before you attach the bridge rectifier? You want output to be about 1/10 of input.

4) What voltage regulator are you using to power the 555?

5) Which PIR sensor are you using? I'm highly intrigued that your PIR has a max voltage of 15V. Are you sure? Most are meant to be used with microcontrollers (ChipKIT or Arduino), so a source voltage of 3-6VDC is very common.

darius.mackun (author)brmarcum2015-02-16

1) just did it and having issue of 0V from pin3 to GND = 0V
2)Yep, I'm pretty sure

darius.mackun (author)brmarcum2015-02-15

At the moment can answer 3 , 4 , 5 , I dissassembled the whole scheme, going to try to assemble again

3) I'm using "APV-12-12" to convert it for me, it converts 220V AC to DC 12V.

4) I'm using 7809 voltage regulator
5) I'm using HC-SR501

Btw since it is my first time doing this on breadboard, so I might've made some mistakes, I should probably just try to solder it all together and see what happens.

brmarcum (author)darius.mackun2015-02-15

Bad idea. Never solder a circuit without knowing for sure that it works. It just creates headaches. That's why we have breadboards.

Sasando_Rote (author)2015-01-18


DewlanceHosting (author)2015-01-08

I am new to this, Can someone make a design of this project like this one >

brmarcum (author)DewlanceHosting2015-01-09

What are you asking? The design is in the image, so I'm confused.

rameezkoya007 (author)2014-08-07

how could I adjust the working time of the circuit to 15-20 minutes?

brmarcum (author)rameezkoya0072014-08-25

You can get anywhere from <1 minute to over 2 hours with the schematic as is. Look at the schematic to Step 5. The potentiometer (P1) and the 1000uF cap (C3) determine the timing. Changing either one for a component with a smaller value will shorten the time. The large 4M pot makes getting a precise time difficult since a small change on the pot will result in a large change in the timer output, but you can get 15-20 minutes as is. You just have to test different values to get it where you want it.

bcraun (author)2014-06-18

Just curious; what is the max on time when using the 4M ohm adjustable resistor? Is the point to keep the PIR in re-trigger mode constantly with movement in the room, or to maintain the on state using the timer?


brmarcum (author)bcraun2014-06-18

In theory the timer could run forever. The threshold pin on the 555 requires a certain voltage level to allow the output pin to go high. A larger cap/pot combo will give a longer time. This particular build ran for about 2.5 hours. I have another project I built that would run for about 4 hours.
Unfortunately the timer isn't able to reset to zero every time it triggers. Once it triggers, it's on and will run until the cap runs out.

bcraun (author)brmarcum2014-06-18

Gotcha. So, aside from the RC combination, the theory is that once the PIR triggers the circuit, it's active for around 2.5 hours. At that point, any movement in the room would re-trigger for another 2.5 hours...and so on? So the assumption is that someone will move at least every 2.5 hours to keep the lights on?

brmarcum (author)bcraun2014-06-18

Yes. Once it triggers, it ignores all subsequent signals from the PIR until the cap runs out, and then resets back to zero. It's not ideal, but it will work

DBoulanger (author)2014-06-17

After re-reading your intro, which described your main objective, with pretty much the same parts and a few more, you could potentially consider creating some sort of toggling circuit, with the 555 and a LDR, which could be controlled via a small laser light, like the ones we have on some keychains.

If you want, you can also go for an IR led approach, like the ones in TV sets, DVD players, etc..., allowing you to toggle the circuit with your current TV remote control, or mostly any remote control for that matter.

In either case, strategic positionning of the LDR or IR led is mandatory to prevent false triggering by external lighting, naturally.

Finally, you could also consider a RF switch. The beauty of that little beast is that it can be completely hidden and you can even toggle the switch without having to aim at the receiver. Plus, it isn't affected by the light, which could be considered as an advantage.

Anyhow, you have plenty of choices, so just let your imagination guide you !

Have fun !

brmarcum (author)DBoulanger2014-06-18

I'm really intrigued by those ideas. LEDs can actually be used as phototransistors as well. Forrest Mimms did a lot of pioneering work in that area many years ago.

matsk (author)2014-06-17

I love this easy electronic project with a practical usage!
And my 20 cent improvments would be to change the PIR to a PIR with adjustable sensitivity and delay like or equal.

That would make the 555 obsolete.

brmarcum (author)matsk2014-06-17

Thank you for your advice. I have no experience with that particular sensor, but I have been warned to be wary of really low price PIRs. If it is working for you, that's great. I may try it with something else.

matsk (author)brmarcum2014-06-18

The PIR's i have bougth on ebay have two different pin layout. I have bougth PIR's from five different seller on ebay and I haven't found "bad quality". The schematic is mostly the same a D203 sensor and a LM324 OP amp or equal.

DBoulanger (author)2014-06-17

Nicely done. You obviously have good soldering skills. Personally, I kind of dislike those 30-40-50W soldering irons. I treated myself and got an Hakko FX888D soldering station. It's a real gem for the electronic enthousiast that I am.

Concerning the PIR sensor, it must be understood that this little beast is actually activated by a variation of heat, not really motion as some of us are lead to believe with the advertisements.

The PIR is a "Passive Infrared sensor" device that reacts to small variations of heat close to it (within 10 feet or so). I discovered it when I installed my so called "motion detector" at the top portion of my garage door, with the sensor pointing down towards the floor.

When my dogs are going outside or coming back, the sensor activates, letting me know with flashing leds that something/someone crossed the doorstep.

However, when the door is left opened, the sensor also reacts to air drafts. If there is some air flow, of warmer or cooler air than the air actually being "monitored", the sensor may activate despite there is no human / animal movement / motion.

Globally, that PIR sensor takes an infrared snapshot of the area it's pointing to and if there is any sufficient heat change detected, would it be because of a human, an animal or simply air flow, the device will trigger.

Nothing really scientific, but might be interesting to know, either to adjust accordingly and prevent false triggering, or simply incorporate this "feature" in one of your future project.


brmarcum (author)DBoulanger2014-06-17

Thank you for the compliment and for explaining how PIR sensors work. You are absolutely correct and this project could be a bit tricky in a home with pets. Most PIRs come with sensitivity adjustments, but they are not all created equal.

ASCAS made it! (author)2014-06-15

Love it! That PIR motion sensing is quite useful. I added your PIR motion sensing idea to my DIY Home Automation Box. Since there's no more room for the PIR, I hacked my dollar store Motion-Door chime and added a $3 RF module. I must say, it makes life more convenient ! Thanks for the wonderful idea! Cheers! :D

brmarcum (author)ASCAS2014-06-16

Very glad to hear that you were able to improve your own project. Do you have a link to it?

witkowski8 (author)2014-06-16

Pro instructions, great

tsaltzman (author)2014-06-15

I really like your idea and what you did but if you had a switch outlet in the room where your xmas tree is you could just replace the wall switch with a motion one and put a time between the wall outlet and xmas tree...but making things is so much better. ;)

brmarcum (author)tsaltzman2014-06-16

Well my wife wants the tree on the other side of the room from that switch. So I get to have fun building.

transistor2 (author)2014-06-15

do you know how to switch from DC current to ac ?

brmarcum (author)transistor22014-06-15

DC to AC inversion is not something I've used with any project so far, though I do have a current project that will require it, so I'm doing my research into that as well. There are a few methods I've found so far: using a 555 timer IC and some transistors, using only transistors, or using a relay. All three look promising, it just depends on the requirements for the circuit you want to build and the space/weight considerations you have available and/or want to take up.

gada888 (author)2014-06-15

Thanks for your info.l love the 'parts kit'and 'discovery',but i am not in the discount bundle is not available to me.who can help me to get them as student or academic special i pay him extra through paypal.

gada888 (author)2014-06-15

Thanks for your feedback.i am thinking of taking one.Do you use simulators to assist you design? Electronics calculation is also my headache.What book you find is most useful in this field.I am a newbie need advice.

brmarcum (author)gada8882014-06-15

I have found simulators to be very useful in very specific applications, though not in the large majority of the time. I usually just build and go with it, but that comes with some experience.

As far as electronics calculations go, the best way to get it is to just do it. That being said, I recommend This is one of the better (but not only) online resources for learning analog electronics. It's laid out like a university level EE course, starting at the basics and going through much more advanced concepts.

I also recommend Click on "Browse Individual Projects" on the left, then on "Analog" in the green box toward the top. The projects are pretty focused on gaining product knowledge, but on the right hand side you will see several buttons for related topics, like "voltage" or "current". Click on those to get a more general idea of those concepts. This site will eventually contain a similar course layout as the previous site, but that is still being developed.

As far as printed books go, as soon as I get mine back from my friend, I will let you know.

padbravo (author)2014-06-15

This is one of the best explained instructables that I've found on this site (year from now).
And that is because it explains not only the construction, but the theory behind each steep, and in electronics, this is not that easy.

link to find this device? (the analog discovery scope)

brmarcum (author)padbravo2014-06-15

Wow, thank you. That's very kind.
The Discovery is listed as the first tool in step one. The name is highlighted, which is a link to the product page.

gada888 (author)2014-06-14

Very nice informative the way,is Digilent analog discovery a worthwhile investment. I own a traditional bulky analog oscilloscope,but i want on e better or carry more functions.

brmarcum (author)gada8882014-06-14

I've been using the analog discovery for several months, both for school and work. In the interest of full disclosure, I am an intern at Digilent, but I was using it before that and have found it to be a remarkable piece of equipment. It easily takes the place of thousands of dollars of benchtop equipment, like an o-scope, spectrum analyzer, power supply, & logic analyzer. It does have limitations as it is powered by USB, but for everything I've done, it has performed beautifully. If you do need more power or scope channels than the discovery can provide, check out the Electronic Explorer Board, also from Digilent.
tl;dr: yes, definitely worth it.

What a great idea to save yourself the hassle of climbing under the tree to turn the lights on and off! I hate doing that too since I'm always afraid I'm going to knock it over or break the ornaments near the bottom of the tree.

Exactly. This also keeps my kids safe, since we know how much 3-5 year olds love to help. I love the help, but not plugging things into the wall socket while squirreling around under the tree.

About This Instructable




Bio: I've always loved to figure out how things work, so hacking and making just fits for me. I'm a husband, a father, an ... More »
More by brmarcum:Programming Digilent FPGAs Using NI MultisimMonitoring Digital Circuits With the Digital DiscoveryUsing the Voltmeter With the Analog Discovery 2
Add instructable to: