Introduction: DIY Arduino PIR Motion Sensor Lighting & Security

About: 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), Wind, and veggie oil fueled diesel generator power for 6 yea…

From the minds at

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

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).

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

We obtained our PIR Sensor from Amazon.

Connect the 3 pins of the PIR to +5vdc, Arduino Pin 2 (data out), and Ground.

Step 2: SSR

A SSR is a solid state relay. It consists of a photo transistor and a triac, along with supporting circuitry. This isolates the 120vac load from the Arduino, so no damage from the high voltage AC can happen.

For background info on SSR's see

We obtained our SSR from Amazon.

Connect Screw Terminal 4 to Ground, Screw Terminal 3 to Arduino Pin 13, and Screw terminals 1 & 2 insert in Series (this is important) with the HOT wire going to your appliance (make sure your cord is unplugged or breaker is off if hardwiring).

Step 3: Manual Control Switch

We wanted a way to override the PIR, and offer a Automatic (PIR), Manual ON, and Manual OFF mode. We added a SPDT Switch, with center off, and connected the center pin to +5vdc, and the two outer pins to Arduino pins 11 & 12. The two outer pins also have a 10k ohm resistor (each) to Ground.

Radio Shack carries a 5 pack of resistors for $1.20 or so.

We obtained the SPDT w/ Center Off switch from Amazon.

For more info on SPDT and other types of switches, see,_double_throw#Contact_terminology

Step 4: The Arduino Code

The code that makes this all happen is as follows:

int inPin1 = 11;   // switch connected to digital pin 11
int inPin2 = 12;   // switch connected to digital pin 12

int ssrPin = 13;
int pirPin = 2;
int motionDetect= 0;
int manualSwitch = 0;
int motionSwitch = 0;

void setup() {
pinMode(ssrPin, OUTPUT);
pinMode(pirPin, INPUT);
pinMode(inPin1, INPUT);
pinMode(inPin2, INPUT);
digitalWrite(ssrPin, LOW);

void loop() {

motionSwitch = digitalRead (inPin1);
manualSwitch = digitalRead (inPin2);

if (motionSwitch == HIGH) // Motion Mode
  motionDetect = digitalRead(pirPin);
  if (motionDetect == HIGH)
     digitalWrite(ssrPin, HIGH);
     delay (180000); //Optional 3 minute delayed off
     digitalWrite(ssrPin, LOW);
else if (manualSwitch == HIGH) // Manual On
  digitalWrite(ssrPin, HIGH);
else // Manual Off

  digitalWrite(ssrPin, LOW);

Step 5: The Schematic

Here is the schematic that shows all the wiring:

Step 6: Using a Light Sensor (LDR/CdS)

One option is to prevent the lights from coming on if the ambient light levels are over a certain amount. This is the typical operation of an outdoor motion sensor. If the sun is up, the lights do not come on. This CdS tutorial will get you started on adding that option. If the reading is over a certain amount, inhibit the light on function.