How to Build a Simple Motion-Activated Light for Your Front Porch with an Arduino and PIR Sensor

I'm excited to share how I built a simple motion-activated light for my front porch using an Arduino microcontroller and a PIR (passive infrared) sensor. This project is perfect for adding a bit of security and convenience to your outdoor space.

Intro: Why Build a Motion-Activated Porch Light?

Having a light that automatically turns on when it detects motion is really handy for a few reasons:

How a PIR Sensor Works

The key component that makes the motion detection work is the PIR sensor. PIR stands for passive infrared. These sensors can detect changes in infrared radiation, allowing them to effectively detect heat and motion.

Here's a quick overview:

So in summary, the PIR sensor allows the Arduino to sense when a person or animal is moving within its detection range.

Parts and Tools Needed

To build the motion-activated light, you'll need the following parts and tools:



Circuit Design and Connection

The circuit for this project is relatively simple. Here's a step-by-step overview of how everything needs to be connected:

  1. Connect the PIR sensor to the Arduino board. The sensor has 3 pins - power, ground, and signal. Connect power to 5V, ground to GND, and signal to digital pin 2.

  2. Connect the LED to a 220 ohm current limiting resistor. This resistor is needed to prevent too much current flowing to the LED.

  3. Connect the resistor side to Arduino ground, and the LED side to digital pin 13.

  4. Power the Arduino with a 9V battery connected to the barrel jack or Vin/GND pins.

  5. Upload the Arduino motion sensing sketch (code) to the board.

Once everything is wired up properly and the code is loaded, you're ready to test it out!

Arduino Sketch to Detect Motion

The Arduino sketch uses only a few lines of code to detect motion and activate the light:

const int pirPin = 2; //PIR connected to digital pin 2
const int ledPin = 13; //LED connected to digital pin 13

void setup() {
pinMode(ledPin, OUTPUT); //Set LED pin as output
pinMode(pirPin, INPUT); //Set PIR pin as input

void loop(){
if(digitalRead(pirPin) == HIGH){ //If motion detected
digitalWrite(ledPin, HIGH); //Turn on LED
digitalWrite(ledPin, LOW); //Turn off LED

The sketch checks the PIR sensor pin every loop. If motion is detected (HIGH signal), it turns the LED on. Otherwise, the LED remains off. This simple program is all that's needed to react to the sensor triggers.

Testing and Troubleshooting

Once everything is assembled according to the circuit diagram, power it up and open the Arduino IDE serial monitor.

Walk in front of the PIR sensor to test - the LED should turn on when motion is detected. Make sure to mount the sensor and LED at desired positions on your porch.

If the light isn't turning on properly, double check all connections and pin numbers in the code. Verify the PIR sensor is oriented correctly.

Some troubleshooting tips:

With some tweaking and adjustments, you should have your automated porch light working in no time!

Wrapping Up

Building a motion-activated light is a straightforward Arduino project that really pays off in terms of utility. I'm so glad I took the time to construct this for my front porch.

The PIR sensor and Arduino provide the brains, while the LED acts as a bright, energy-efficient light source whenever motion is detected.

I hope this guide gives you a clear overview of the process from start to finish. Let me know if you have any other questions! I'm happy to help out. Now go build something awesome.