From the minds at http://arduinotronics.blogspot.com/

We wanted to save energy, and create convenience, by adding motion sensors to our lighting circuits. Maybe you want some notification of an intruder. Both can be done with a PIR Motion sensor.  When I walk into a room, the lights come on automatically, and when I leave, shut off after a short period of time. You can choose how long that time delay is in the code. No more fumbling for a light switch in the dark with my arms full of groceries!

I also wanted a override switch for times I want the light to stay on, or off.

So, I took an Arduino, added a PIR sensor, a SSR, a SPDT switch,  two 10k ohm resistors and whipped up a small sketch to glue it all together. Enjoy!

Original article, and more at http://arduinotronics.blogspot.com/2013/01/motion-sensors-ssrs.html

Multiple motion sensors, and multiple SSR's can be serviced by a single Arduino. A embedded Atmel chip can be built into the project instead of dedicating a complete Arduino board.

A CdS light sensor can be added to prevent the lights from activating if light level's are considered sufficient (user programmable). http://arduinotronics.blogspot.com/2012/03/light-sensing-with-cds-ldr.html

Step 1: The PIR Sensor

The first step was connecting a PIR sensor. A PIR detects "motion" by recognizing an increase in Infra Red emission in the focus area, put out by the human body.

For background info on PIR, see http://en.wikipedia.org/wiki/Passive_infrared_sensor

We obtained our PIR Sensor from Amazon.

Connect the 3 pins of the PIR to +5vdc, Arduino Pin 2 (data out), and Ground.
<p>I have used 220V ac instead of 120V ac. The LED burnt out each time I turned on the voltage. Can you tell me why this is happening? Can I build the circuit without an SSR? </p><p>The specification olf the SSR i used is: 40VA</p><p>24~380VAC across pins 1&amp;2</p><p>500Kohm/0.25W across pins 3&amp;4</p>
Why are you using a 500k across pins 3 &amp; 4? Those pins are for direct 5v control from the Arduino.<br><br>Since you are using 220vac on the primary side, You have to use 220vac lights. Yes, you have to use a SSR because an arduino is 5vdc only, and would fail spectacularly at 220vac. You could use a arduino relay board instead of the ssr.
hi i am having problem with connecting the spdt swicth it has 6 pins but in the given circuit you have used 4 pins only , here i m confused please help me
<p>6 pins is a DPDT switch, just use one side of it. Leave the other 3 empty.</p>
<p>how do i use embedded atmel chip</p>
See http://www.instructables.com/id/The-Embedded-Arduino-building-an-Arduino-into-a-p/
<p>how do i use embedded atmel chip</p>
see http://www.instructables.com/id/The-Embedded-Arduino-building-an-Arduino-into-a-p/
<p>how will connect atmel chip if i dont use arduino</p>
Sir, I'm about to use your creative work as my project. I just wanted to ask, we already have the PIR sensor, what's the use of the LDR??
The LDR deactivates the lights during daylight hours in a security lighting application. The lights only come on from dusk to dawn.
Hi, are you selling this or any place that I can buy this?
I'm not selling it, but there are parts links in the instructable.
Sir, I'm about to use your creative work as my project. I just wanted to ask, we already have the PIR sensor, what's the use of the LDR??
Sir, I'm about to use your creative work as my project. I just wanted to ask, we already have the PIR sensor, what's the use of the LDR??
<p>Thanks! I understand now how it all works. This is great! I just have one more question though. Can the arduino take 4 motion sensors (like the ones in this tutorial) and 4 SSr's relays? my concern is the 5v, if it will be OK to handle all that. I think I could use just the two switches to control on/off the whole thing....</p>
there's no problem supporting 4 motion sensors and 4 ssr's. The ssr's are just a LED connected to the Arduino.
<p>Stupid but quick question. The diagram shows two +5vdc, but the Arduino uno only has 1 (?). Does this mean the switch (center pin) and the motion sensor share the same +5vdc pin in the Arduino? (does it matter which order you connect the three motion sensor points into the arduino too?)</p>
yes, they share the same +5vdc. the motion sensor typically has three pins, one is ground, one is 5v. the out has to connect to whatever pin you specify in code.
<p>does this PIR sensor work? </p><p><a href="http://www.amazon.com/gp/product/B007XQRKD4/ref=ox_sc_act_title_8?ie=UTF8&psc=1&smid=A2JO7YP9I9Y3D6" rel="nofollow">http://www.amazon.com/gp/product/B007XQRKD4/ref=ox_sc_act_title_8?ie=UTF8&amp;psc=1&amp;smid=A2JO7YP9I9Y3D6</a></p>
That should work fine.
<p>Is it safe to use this 25A SSR ( http://amzn.to/1rVuILv ) if I am only using it to control a 4 Amp vacuum?</p>
Sure. It's rated for a max of 25 amps. It will control anything less than that.
<p>Is it possible to activate two sensor at the same time?</p><p>i think delay(---) is the main problem.</p><p>because triggering two sensor at the same time by human motion is impossible.</p><p>if one sensor goes to high then wait until delay() is completed. </p><p>what do you think? Is there any idea to overcome? your comment is appriciated. </p>
<p>Redusing the delay would allow near realtime multiple sensor activation. Using interrupts would allow multiple reads very quickly. Larger Atmel chips have more interrupts available.</p>
<p>Thanks for your comments and suggestion.</p><p>yeah short dealy() is good for another trigger. but usually we need one sensor activates and stay some time for light up. </p><p>however, by this time if another motion is occurred, the other sensor should be activated. </p>
<p>How to add another PIR sensor in this circuit??? i.e. how to connect two PIR sensor in a single circuit??? If i cross either of the sensor means the light should glow.</p>
<p>We are using pin 2 for the data connection of our sensor, add a second sensor to pin 3.</p><p>1. in the code, add (in the appropriate places):</p><p>int pirPin2 = 3;</p><p>pinMode(pirPin2, INPUT);</p><p>motionDetect2 = digitalRead(pirPin2);</p><p>2. and replace</p><p>if (motionDetect == HIGH)</p><p>with</p><p>if (motionDetect == HIGH || motionDetect2 == HIGH)</p>
<p>Thankyou very much for ur reply sir. Could you please tell me that where i have to add the first part code in the existing code??</p>
<p>Right after the existing lines that match:</p><p>after</p><p>int pirPin = 2;</p><p>put</p><p>int pirPin2 = 3;</p><p>-----</p><p>after</p><p>pinMode(pirPin, INPUT);</p><p>put</p><p>pinMode(pirPin2, INPUT);</p><p>----</p><p>after</p><p>motionDetect = digitalRead(pirPin);</p><p>put</p><p>motionDetect2 = digitalRead(pirPin2);</p>
<p>After the modifying the existing code with the above one , the circuit have to work as i am thinking. If i cross any one of the two PIR sensors means the bulb will glow for 3 mins. suppose if i crossed any one of the two sensor, the bulb is started glowing for 3 mins. With in that 3 mins if cross the same sensor or another sensor means the time wil be reset for 3 mins and the wil glow for 3 mins. It wont bling once while the time is getting reset. Am i correct sir?? And the 5vdc and ground in the diagram mentioned is 5vdc adapter connected to the circuit. Am I correct sir?? This is my first Arduino project sir. Thats y I am clarifying my doubts this much. I hope u dont mind. Thank you sir.</p>
<p>The +5vdc is the 5vdc from the arduino, not the input. power to the arduino comes from a USB cable or a power supply using the barrel jack (9-12v typically).</p>
<p>Hello sir, I tried the coding for restart the timer if new event is seen by the sensor. But no success. could u pls help me by providing the code for that?? </p><p>And where I have to add the LDR coding in the main code??</p><p>Pls help...</p>
<p>The code is not currently written to restart the timer if a new event is seen, but it could easily be made to.</p>
<p>Sir, In the schematic diagram, +5vdc is connected to either pin 11 or pin 12 with the help of switch s1 to transfer the positive charge to the circuit. But the Ground also connected to the same pin 11 and pin 12. Here the both +ve and -ve terminals are connecting in one pin itself. Will it create short circuit?? If not means how that part is working??</p><p>And what will be the code to restart the timer if a new event is seen??</p><p>Thank you sir...</p>
<p>Gnd is not shorted to 11 &amp; 12, there are pulldown resistors in line. This prevents floating inputs. I do not have the time right now to build the timer restart code. It's not that difficult, give it a try.</p>
<p>ok sir. I will try. Thank you for spending some time to answering for my clarifications. :-)</p>
<p>There is an error in the code. The delay cannot be adjusted to a small duration (5 seconds). It wasn't until I added in this line to the void loop that it worked as I wanted it to: </p><p>digitalWrite (ssrPin, LOW);</p><p>You have that line in the setup and that wasn't working. I added it to the loop and the delay was then able to actually shut off the light the moment the delay ended.</p>
Awesome. Thank you.
<p>Nice tutorial!</p><p>You can get the hc-sr501 PIR motion sensor for cheap here: <a href="http://voltatek.com/en/sensors/69-motion-sensor-module-hc-sr501-pyroelectric-ir-infrared-adjustable.html" rel="nofollow">http://voltatek.com/en/sensors/69-motion-sensor-m...</a></p>
My SSR operates when the DC volatge is 12V.so i even if my arduino gives a high the ssr doesnt close the switch and my lamp doesnt glow.what to do?
SSR's don't switch DC, They switch AC. You need a MOSFET.
I'm not getting any errors but I can't get either code to work, the light just stays on constantly, I'm using a SSR-40 DA. Also I don't get the switch. What is it for? When I first download it, the lights off, I wave my hand in front of it and the light comes on but never goes off.
You may have the delay set on the motion sensor for a long timeout. The switch is for a over ride, as described in the instructable. on , off, or automatic.
I think I see what I did, I'll try putting the close bracket at line 29 to close the nested if statement, and removing the extra I put at the end.
yep, I see it, should be a } after delay (180000); //Optional 3 minute delayed off <br> <br> <br>delay (180000); //Optional 3 minute delayed off <br>} <br> <br>I'll fix the instructable.
Ha ha, sorry I'm new at this. I'm not driving anything that's not in the instructable, but I'll definitely check the voltage, maybe one of my components are defective. <br> <br>Yes, the symptoms are as follows: With everything connected and nothing in front of the sensor the lamp blinks, I tried different lamps and some blink very quickly and some blink slowly. When I walk in front of the sensor the lamp goes from blinking to solidly on. When the wire from screw 3 of the SSR to arduino pin 13 is dosconnected, the lamp is solidly off. This lead me to believe the problem was the SSR &quot;off state&quot; but maybe not. I've tried a couples SSRs and the same thing happens. <br> <br>The code I used is mostly the same as in your instructable. I couldn't get it to compile so I added a semicolon after &quot;digitalWrite(ssrPin, HIGH)&quot; in line 33, after &quot;digitalWrite(ssrPin, LOW)&quot; in line 38. It was also saying that it wanted an additional close bracket so I put it at the end, but maybe I've done this wrong as well. At what line is the loop meant to end? <br> <br>int inPin1 = 11; // switch connected to digital pin 11 <br>int inPin2 = 12; // switch connected to digital pin 12 <br> <br>int ssrPin = 13; <br>int pirPin = 2; <br>int motionDetect= 0; <br>int manualSwitch = 0; <br>int motionSwitch = 0; <br> <br>void setup() { <br>pinMode(ssrPin, OUTPUT); <br>pinMode(pirPin, INPUT); <br>pinMode(inPin1, INPUT); <br>pinMode(inPin2, INPUT); <br>digitalWrite(ssrPin, LOW); <br>} <br> <br>void loop() { <br> <br>motionSwitch = digitalRead (inPin1); <br>manualSwitch = digitalRead (inPin2); <br> <br>if (motionSwitch == HIGH) // Motion Mode <br>{ <br> motionDetect = digitalRead(pirPin); <br> if (motionDetect == HIGH) { <br> digitalWrite(ssrPin, HIGH); <br> delay (180000); //Optional 3 minute delayed off <br> <br>} <br>else if (manualSwitch == HIGH) // Manual On <br>{ <br> digitalWrite(ssrPin, HIGH); <br>} <br>else // Manual Off <br> <br>{ <br> digitalWrite(ssrPin, LOW); <br>} <br>} <br>}
I did find two missing ;<br><br>but no missing }<br><br>fixed the code.<br><br>I have a whole new code sketch to upload this week with different features, but works better.
I've been having some trouble with the light blinking in the ssr &quot;off&quot; state. From some googling I've found that this might be due to something called &quot;leaking&quot; but adding a 10k resistor from screw 3 to ground doesn't resolve it. The light does not blink when screw 3 is disconnected from the breadboard. Does anyone know what might be causing this?

About This Instructable


131 favorites


Bio: Professionally, I'm an IT Engineer (Executive Level) and Electronics Tech. I'm a Amateur Radio Operator (KK4HFJ). I lived off grid, with Solar (PV ... More »
More by sspence: Raspberry Pi & the Neo 6M GPS Earthquake / Vibration Sensor Arduino Internet Time Client
Add instructable to: