How to Build a Simple Motion-Sensing Night Light with Arduino in 10 Minutes
Introduction
Building a motion-sensing night light with Arduino is a fun beginner electronics project that can be completed in under 10 minutes. The night light turns on automatically when it detects motion and turns off after a set amount of time.
This project is a great way to learn about Arduino, PIR motion sensors, and basic circuit building. In this guide, I will walk through all the steps required to build the motion-sensing night light from start to finish.
What You Will Need
To build the motion-sensing night light, you will need the following components:
-
Arduino Uno - The microcontroller board that will control the night light circuitry.
-
PIR motion sensor - Detects motion and sends a signal to the Arduino.
-
LED - The light source for the night light. Any color will work.
-
220 ohm resistor - Limits current to the LED.
-
Breadboard - Used to build the circuit.
-
Jumper wires - For connecting the components on the breadboard.
-
9V Battery - Power source for the Arduino.
-
9V Battery clip - Connects the 9V battery to the Arduino.
Step 1: Connect the PIR Motion Sensor
The first step is to connect the PIR motion sensor to the Arduino. This allows the Arduino to detect when motion is present.
Follow these steps:
-
Place the PIR sensor on the breadboard.
-
Using jumper wires, connect the GND pin on the PIR sensor to a GND pin on the Arduino.
-
Connect the VCC pin on the PIR sensor to the 5V pin on the Arduino.
-
Finally, connect the OUT pin on the PIR sensor to digital pin 2 on the Arduino.
Step 2: Connect the LED
Next, we need to connect the LED:
-
Place the LED on the breadboard, with the longer leg on the positive rail.
-
Connect the 220 ohm resistor in series from a positive rail to the positive leg of the LED. This protects the LED from too much current.
-
Use a jumper wire to connect the negative leg of the LED to a GND pin on the Arduino.
Step 3: Install the Arduino Sketch
Now we need to upload the Arduino sketch that tells the night light how to function:
-
Open the Arduino IDE on your computer.
-
Copy and paste the following sketch code into a new sketch:
```cpp
int pirPin = 2; // PIR Out pin connected to pin 2
int ledPin = 13; // LED connected to pin 13
void setup() {
pinMode(ledPin, OUTPUT); // Set LED pin as output
pinMode(pirPin, INPUT); // Set PIR Out pin as input
}
void loop() {
int pirValue = digitalRead(pirPin); // Read PIR sensor value
if (pirValue == HIGH) { // If motion detected
digitalWrite(ledPin, HIGH); // Turn on LED
delay(5000); // Keep LED on for 5 seconds
digitalWrite(ledPin, LOW); // Turn off LED
}
}
```
- Upload the sketch to the Arduino board. This loads the code that controls the night light.
Step 4: Power the Circuit
The last step is to power up the circuit:
-
Connect the 9V battery to the 9V battery clip.
-
Attach the battery clip to the Vin pin and GND pin on the Arduino.
-
The Arduino and circuit will now power up.
-
When the PIR sensor detects motion, the LED will turn on for 5 seconds then automatically turn back off.
That's it! You now have a fully functioning motion-sensing night light built with Arduino. This project can easily be expanded by adding more LEDs, tweaking the time durations, or triggering other devices.
Troubleshooting Tips
If your night light is not working, here are some troubleshooting tips:
-
Double check all connections and wiring.
-
Make sure the Arduino sketch is uploaded properly without errors.
-
Adjust the PIR sensor positioning to cover the desired motion detection area.
-
Increase the LED delay time if needed (e.g. from 5 to 30 seconds).
-
Verify the battery is connected properly and has a charge.
-
Swap the LED or other components if defective.
With these simple tips, you should be able to get your DIY motion-sensing night light working quickly!