Have you ever wanted a night light that turns on automatically when you walk into a dark room? With an Arduino microcontroller, some basic electronic components, and a bit of coding, you can build your own motion-activated night light in just 10 minutes.
What You'll Need
To build this simple motion-activated night light, you'll need the following parts:
-
Arduino Uno - The brains of the operation. This microcontroller board allows you to upload code and control electronic components.
-
PIR motion sensor - This sensor detects motion in its range, allowing it to turn the light on when movement is detected.
-
LED light - Any LED will work, but I prefer using a bright white LED for visibility.
-
220 ohm resistor - Limits current to the LED to prevent damage.
-
Breadboard - Allows for quick prototyping and connecting components.
-
Jumper wires - For making connections between components.
-
9V battery - Power source for the portable night light.
-
9V battery clip - Connects the 9V battery to the breadboard.
-
Arduino IDE - Software on your computer for coding and uploading to the Arduino.
That's it for supplies! Make sure you have all the components listed above before starting.
Step-by-Step Instructions
Follow these step-by-step instructions to assemble your motion-activated night light in 10 minutes or less:
1. Connect the PIR Motion Sensor
The PIR (passive infrared) motion sensor needs 4 connections - 5V power, ground, and 2 data lines to pins 2 and 3 on the Arduino.
Use jumper wires to connect the sensor:
- VCC to Arduino 5V
- GND to Arduino GND
- OUT to Arduino pin 2
- - to Arduino pin 3
This allows the Arduino to receive motion detection data from the sensor.
2. Connect the LED Light
Next, connect the LED light to the breadboard.
Insert the 220 ohm resistor in series to limit current. Then connect:
- Longer LED leg to Arduino pin 13
- Shorter LED leg to resistor
- Other resistor leg to Arduino GND
Later, we'll activate the LED light by turning pin 13 HIGH in code.
3. Connect the 9V Battery
The 9V battery will power the circuit. Use the 9V battery clip to connect positive and ground to the power rails on the breadboard.
- Red wire to + rail
- Black wire to - rail
This will feed power to the Arduino when switched on.
4. Upload the Arduino Code
With the hardware assembled, it's time to upload the code that controls the night light:
```arduino
// Motion-activated night light
int ledPin = 13; // LED on pin 13
int pirPin = 2; // PIR on pin 2
int pirValue; // PIR status
void setup() {
pinMode(ledPin, OUTPUT); // Set LED as output
pinMode(pirPin, INPUT); // Set PIR as input
}
void loop() {
pirValue = digitalRead(pirPin); // Read PIR
if (pirValue == HIGH) { // If motion detected
digitalWrite(ledPin, HIGH); // Turn on LED
}
else {
digitalWrite(ledPin, LOW); // Else turn off
}
}
```
This simple code reads the PIR motion value, and turns the LED on pin 13 HIGH when motion is detected.
Upload it to your Arduino board through the Arduino IDE.
5. Test It Out
Once coded and assembled, switch on the 9V battery power.
When you walk in front of the PIR sensor, the LED light should turn on automatically!
The light will turn off after a few seconds when you stop moving. Pretty cool for just 10 minutes of work!
Customizing Your Night Light
While a bright LED works well, you can customize your night light even more:
-
Use a calm blue or green LED for a soothing mood light.
-
Add a light diffuser so it's not blinding to look at directly.
-
Use a relay to control a mains lamp instead of a small LED.
-
Adjust the PIR sensitivity and delay times in code.
-
Add more LEDs in different colors for fun effects!
With Arduino, the possibilities are endless. Use this project as a base for your own creative motion-activated lighting ideas.
I hope you've enjoyed learning how to build a motion-activated night light in just 10 minutes! Let me know if you have any other Arduino project ideas you'd like to see. Happy making!