Building a motion-activated night light with Arduino is a fun and simple electronics project that can be completed in around 10 minutes. With just a few basic components, you can create a handy night light that will turn on automatically when it detects motion.
What You Will Need
To build the motion-activated night light, you will need the following parts:
-
Arduino Uno board - The brains of the operation. This microcontroller board allows you to program the night light's behavior.
-
HC-SR501 PIR motion sensor - This sensor detects motion using infrared energy. It will send a signal to the Arduino when motion is detected.
-
LED - Any color LED will work. This provides the light that turns on when motion is detected.
-
220 ohm resistor - Limits the current flowing to the LED. Prevents the LED from burning out.
-
Jumper wires - Used to connect the components together.
-
Breadboard - Allows you to easily prototype circuits without soldering.
-
9V battery - Provides power to the Arduino.
-
USB cable - Used to program the Arduino code onto the board.
That's all you need! Now let's look at how to put it together.
Assembling the Motion-Activated Night Light Circuit
With all the parts gathered, assembling the circuit on a breadboard is straightforward:
-
Connect the LED's positive leg to Arduino pin 12 through a 220 ohm resistor.
-
Connect the LED's negative leg directly to the Arduino's GND pin.
-
Connect the PIR sensor's VCC pin to 5V on the Arduino.
-
Connect the PIR sensor's GND pin to GND on the Arduino.
-
Connect the PIR sensor's OUT pin to Arduino pin 2.
That completes the circuit! The PIR sensor will detect motion and output a HIGH signal to pin 2, turning the LED on pin 12 on. Now we need to upload the code.
Uploading the Arduino Code
To program the night light behavior, just a few lines of Arduino code are needed:
```cpp
const int pirPin = 2; //PIR Out pin connected to pin 2
const int ledPin = 12; //LED connected to pin 12
void setup() {
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
if (digitalRead(pirPin) == HIGH) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}
```
This initializes the PIR sensor and LED pins, then continuously checks the PIR pin. If motion is detected, the LED turns on!
To upload the code:
- Connect the Arduino board to your PC with the USB cable.
- Open the Arduino IDE and paste in the code.
- Select the Arduino board type and COM port.
- Click the "Upload" button to load the code.
Once uploaded, the night light is ready for motion-activated action!
Testing and Using the Motion-Activated Night Light
With everything assembled and programmed, now you can test out the night light:
-
Power the Arduino with the 9V battery or USB cable.
-
Verify the LED turns on when you walk in front of the PIR sensor.
-
Adjust the PIR sensitivity and LED brightness as needed.
-
Optionally, enclose the project in a decorative box or casing.
Some ways to use the finished motion-activated night light:
-
Place it in a dark hallway or room to automatically illuminate the area at night when you walk by.
-
Put it outside facing a door or walkway to automatically light up when visitors approach.
-
Use it in a closet that doesn't have a permanent light installed.
-
Perfect for lighting up a dark path at night hands-free!
The possibilities are endless for practical uses of this handy Arduino project. With just a few common components, you can build your own motion-activated night light in about 10 minutes!