![How to Build a Simple Motion-Activated Night Light Circuit With an Arduino How to Build a Simple Motion-Activated Night Light Circuit With an Arduino](https://www.circuit-diagram.org/images/arduino-pir-motion-detector-circuit.png)
How to Build a Simple Motion-Activated Night Light Circuit With an Arduino
Introduction
Building a motion-activated night light with an Arduino is a fun and relatively straightforward electronics project. The end result is a useful circuit that will turn on a light automatically when motion is detected in a dark room.
In this guide, I will walk through all the steps required to build the motion-activated night light circuit from start to finish.
Components Needed
To build the motion-activated night light, you will need the following components:
-
Arduino Uno - The brain of the circuit that will control the light turning on when motion is detected.
-
PIR motion sensor - Detects motion in the room and sends a signal to the Arduino.
-
Relay module - Controls power to the light and allows the Arduino to switch it on/off.
-
LED light - The light that will turn on when motion is detected. Any small LED lamp will work.
-
Jumper wires - For connecting the components together.
-
Breadboard - Used to easily prototype and connect the circuit components.
-
9V battery - Powers the Arduino.
-
9V battery clip - Connects the 9V battery to the Arduino.
Circuit Diagram
Here is a circuit diagram showing how all the components are connected:
The PIR motion sensor, relay module, and LED light all connect to the Arduino's GPIO pins to be controlled by the program code.
Setting up the Hardware
Follow these steps to construct the circuit on the breadboard:
Step 1: Connect the PIR motion sensor
- Connect VCC on the PIR to 5V pin on the Arduino
- Connect GND to GND
- Connect OUT pin to Arduino digital pin 2
Step 2: Connect the relay module
- Connect VCC to 5V
- Connect GND to GND
- Connect IN pin to Arduino pin 3
Step 3: Connect the LED light
- Connect the LED's positive (+) leg to the NO (normally open) pin on the relay module
- Connect the negative (-) leg to GND rail
Step 4: Power the Arduino
- Connect the 9V battery's positive and negative terminals to the battery clip
- Connect the battery clip to power the Arduino
Once all the connections are made, the hardware portion of the circuit is complete!
Loading the Code
With the hardware set up, now the Arduino needs to be programmed:
- Download the Arduino IDE software on your computer
- Copy and paste the code from this source into a new sketch
- Upload the code to the Arduino
The code instructs the Arduino to turn the relay on and light on when motion is detected by the PIR sensor.
Key portions:
digitalWrite(relay, HIGH);
- turns relay and light ONdigitalWrite(relay, LOW);
- turns relay and light OFFdelay(500)
-leaves light on for 5 seconds after motion stops
Testing and Using the Night Light
Once programmed, the motion-activated night light circuit should function!
To test it out:
- Make sure the room is dark
- Wave your hand in front of the PIR sensor
- The light should turn on automatically
- When motion stops, the light will turn off after 5 seconds
Try experimenting with different delay times and light sources to customize the night light to your needs.
The finished circuit can provide hands-free lighting in dark hallways, closets, or rooms easily and automatically!
Troubleshooting Issues
If the motion light does not work properly:
- Check all component connections against the circuit diagram
- Confirm the Arduino is powered on
- Verify the correct Arduino pins are used in the code
- Adjust PIR sensor position and sensitivity
- Check for issues with the relay module or LED
With some tweaks, you should be able to get the motion-activated night light working reliably.
Conclusion
Building a motion-activated night light with an Arduino is an easy and fun electronics project. With just a few components, some basic code, and following this guide, you can create a useful automated lighting solution. Customize the circuit to suit your needs for the perfect hands-free night light! Let me know in the comments if you have any other questions.