How to Build a Simple Motion-Activated Night Light with an Arduino and PIR Sensor

Introduction

Building a motion-activated night light with an Arduino and a passive infrared (PIR) sensor is an easy and fun electronics project that can be completed in just a few hours. The end result is a useful night light that will automatically turn on when it detects motion in a room.

In this article, I will provide a step-by-step guide on how to build this simple motion-activated night light using common electronic components. I will cover:

By the end of this guide, you will have the knowledge to build your own motion-activated night light that automatically turns on when you enter a room. This can be a useful tool for navigating your home at night safely.

Components Needed

To build the motion-activated night light, you will need the following components:

This is an easy component list to source. You likely have many of these parts on hand already. Now let's look at how a PIR sensor works.

How a PIR Sensor Works

The key component that makes this project work is the PIR sensor. PIR stands for passive infrared. This is a simple electronic device that can detect infrared radiation emitted from warm objects like people, animals, or anything generating heat.

The PIR sensor has 3 pins - power, ground, and signal. Inside, it contains a pyroelectric sensor that detects levels of infrared radiation. When it senses a change in infrared levels, meaning something warm entered or left its range, it signals its output pin.

We can detect this change in the output pin signal to activate the night light. PIR sensors are common in motion-detecting security lights and other electronics projects. They are easy to use with Arduino.

Connecting on a Breadboard

With the components ready, it's time to assemble the circuit on a breadboard. The wiring diagram is simple:

That's it for the wiring. The PIR sensor and LED are interfaced to the Arduino. The resistor for the PIR provides pull down to prevent false signals. The resistor for the LED limits current to a safe level.

Now let's program the Arduino to control the night light.

Programming the Arduino

With the physical wiring complete, now we need to upload code to the Arduino to operate the motion-activated light. I'll walk through the key parts of the Arduino sketch (code).

First, we need to initialize variables for the PIR pin and LED pin numbers:

c
int pirPin = 2; //input pin for PIR sensor
int ledPin = 13; //output pin for LED

In the setup() function we initialize the LED pin as an output:

c
pinMode(ledPin, OUTPUT);

The main logic goes in the loop() function. We repeatedly check the PIR pin for motion detected:

```c
if(digitalRead(pirPin) == HIGH){

//turn LED on
digitalWrite(ledPin, HIGH);

//wait 2 seconds
delay(2000);

//turn LED off
digitalWrite(ledPin, LOW);

}
```

This reads the PIR pin. If motion is detected, the pin will go HIGH. We turn the LED on, wait 2 seconds, then turn the LED off again. This creates a quick burst of light when motion is sensed by the PIR.

The rest of the loop() continues checking for motion. Upload this code to your Arduino and the motion sensing night light is complete!

Assembling the Enclosure

For a nice finished project, you will want to install the electronics in some type of enclosure. I used a simple cardboard box. You can decorate it as desired for the room.

Some tips for assembly:

And that's it! With the code loaded and electronics assembled, you now have a motion-activated night light to install anywhere.

Conclusion

Building a motion-activated night light with Arduino is an easy and educational electronics project. With just a PIR sensor, LED, Arduino, and basic components, you can construct a night light that automatically turns on when motion is detected.

The key steps are:

After following this guide, you should have the skills to build your own motion-activated lights using Arduino and PIR sensors. The same principles and code can be expanded to other projects as well. Arduino is a fun and versatile platform for DIY electronics.

Let me know if you have any other questions! I'm happy to help explain any step in more detail. Now go build something.