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:
- The components needed for this project
- How a PIR sensor works
- Connecting the components on a breadboard
- Programming the Arduino
- Assembling the project into an enclosure
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:
-
Arduino Uno - The brains of the operation. This microcontroller board will run the code and control the night light.
-
PIR motion sensor - This sensor detects motion using infrared radiation. It will send a signal to the Arduino when motion is detected.
-
Breadboard - Used to easily connect the components.
-
Jumper wires - Used to wire up the components on the breadboard.
-
10K ohm resistor - Used with the PIR sensor.
-
LED - The light source for the night light. Pick any color you like.
-
220 ohm resistor - Used with the LED to limit current.
-
5V wall adapter - Powers the Arduino and breadboard.
-
Enclosure - Houses the project. I used a cardboard box.
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:
- PIR VCC pin to 5V pin on Arduino
- PIR GND pin to GND on Arduino
- PIR OUT pin to Arduino pin 2
- 10K ohm resistor from PIR OUT to GND
- LED positive leg (longer leg) to Arduino pin 13
- LED negative leg to 220 ohm resistor
- Other leg of resistor to GND
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:
- Use hot glue to secure the components in the enclosure
- Cut holes for the PIR sensor and LED
- Use a protoboard inside for a clean look
- Power the Arduino via a hole in the enclosure
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:
- Understanding how a PIR motion sensor works
- Wiring up the simple circuit on a breadboard
- Programming the Arduino to detect the PIR and control the LED
- Assembling the project into an enclosure
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.