How to Build a Simple Motion-Activated Night Light for Under $15
Introduction
Having a motion-activated night light can be incredibly convenient. It turns on automatically when you enter a dark room, allowing you to navigate safely without fumbling for a switch. Best of all, with just a few inexpensive components, you can build one yourself for under $15! In this guide, I'll walk you through a simple DIY motion-activated night light project step-by-step.
What You'll Need
To build this motion-activated night light, you'll need just a few basic components:
-
PIR motion sensor - This infrared sensor detects movement and allows the light to turn on automatically when you enter the room. They're inexpensive and widely available.
-
LED light - Choose any small LED lamp or strip light. I used a puck-style LED accent light.
-
Arduino microcontroller - The brains of the operation. An Arduino Nano or Uno will work well.
-
Jumper wires - To make connections.
-
9V battery and clip - Powers the Arduino.
-
9V battery snap connector - To connect the LED light.
-
Enclosure - Like a small project box to mount it all. I used a mint tin!
Circuit Design
The circuit for this project is very simple. We just need to connect the PIR motion sensor and the LED light to the Arduino.
Connect the PIR motion sensor
- Connect VCC on the PIR to 5V on the Arduino
- Connect GND to GND
- Connect the output pin on the PIR to any digital pin on the Arduino. I used pin 2.
Connect the LED light
- Connect the positive lead from the LED to a 9V snap connector
- Connect the negative lead to a 220 ohm resistor (for limiting current)
- Connect the other end of the resistor to the Arduino's GND
- Connect the snap connector to a digital pin on the Arduino. I used pin 12.
That's it for the circuit! The Arduino code will handle the rest.
The Arduino Sketch
The Arduino sketch reads the output of the PIR sensor to detect motion. When motion is detected, it turns the LED light on.
Include the Servo library
```c
include
```
Pin constants
c
const int pirPin = 2; // PIR output pin
const int ledPin = 12; // LED pin
Global variables
c
Servo myLed; // Create LED object
int pirValue; // Store PIR value
Setup
Attaches the LED to its pin to be controlled.
```c
void setup() {
myLed.attach(ledPin);
pinMode(pirPin, INPUT); // Set PIR pin as input
}
```
Main loop
Continuously checks the PIR sensor and turns the LED on when motion detected.
```c
void loop(){
pirValue = digitalRead(pirPin); // Read PIR value
if(pirValue == HIGH){ // If motion detected
myLed.write(255); // Turn LED fully on
}
else {
myLed.write(0); // Turn LED fully off
}
}
```
And that's it! Upload this code to your Arduino and your motion-sensing night light is complete.
Putting It Together
With the circuit assembled and code uploaded, all that's left is mounting everything inside your enclosure.
- I secured my Arduino, PIR sensor, and LED inside the mint tin with hot glue.
- Drill a small hole for the power cables to pass through.
- Add the batteries, put on the lid, and you're done!
Be sure to position the PIR sensor so it can effectively "see" motion in the area you want to detect.
Some optional enhancements you could add:
- Use a relay or transistor to control a higher voltage/current light.
- Add a potentiometer to adjust the light threshold.
- Use a photoresistor to have it only activate in darkness.
Conclusion
Building your own motion-activated night light is an easy Arduino project that requires only basic components. In under an hour, you can have a custom automated light turning on whenever you enter a room, all for less than $15! Adjustments like setting the light threshold or adding a darkness sensor can take it to the next level. I hope this guide gave you everything you need to build your own. Let me know if you have any other questions!