Introduction

A motion-activated night light can be a useful addition to any home. It turns on automatically when it detects motion, providing illumination when you need it. Making one is a relatively simple electronics project using just a few components, including an Arduino microcontroller and a PIR (passive infrared) motion sensor.

In this guide, I will walk through the steps to build a basic motion-activated night light with an Arduino Uno and PIR sensor. I will cover:

With just a little bit of soldering and coding, you can create a handy gadget to light your way in the dark!

Components Needed

To build the motion-activated night light, you will need the following parts:

That covers the essential electronics pieces. You may also want hot glue, tape, solder, and basic hand tools to assemble the project.

Circuit Diagram

Here is a diagram showing how to connect the components:

How to Make a Simple Motion-Activated Night Light with an Arduino and PIR Sensor

The PIR sensor has three pins - power, ground, and output. The power pin connects to 5V, ground to GND, and output to Arduino digital pin 2.

The LED connects through a 220 ohm resistor to Arduino pin 3. The resistor protects the LED from too much current.

Power comes from the 9V battery clip connected to the breadboard rails.

Assembling the Circuit

To begin, connect the PIR motion sensor to the breadboard according to the circuit diagram. The pins on PIR sensors are typically labeled, so match the GND, 5V, and OUT pins to the corresponding rows on the breadboard.

Next, insert the LED and resistor. Make sure the positive LED leg lines up with the resistor and Arduino pin 3.

Connect four jumper wires - one from the PIR output to Arduino pin 2, one from the PIR 5V to Arduino 5V, and one each from PIR and Arduino GND to a ground rail.

Attach the 9V battery clip by snapping the red and black clips onto the breadboard's power rails.

Plug the Arduino into your computer using a USB cable so you can program it shortly.

Once everything is neatly lined up on the breadboard based on the circuit diagram, double check the connections against the diagram. Also confirm the resistor value and that the LED polarity is correct.

Programming the Arduino

With the hardware assembled, it's time to program. The Arduino code for this project simply reads the PIR sensor pin and turns the LED on or off based on whether motion is detected.

Here are the steps:

  1. Install the Arduino IDE on your computer if you don't already have it.

  2. Open the IDE, then open a new sketch (File > New).

  3. Copy the code below and paste it into the sketch:

```c++
int pirPin = 2; //PIR Out pin connected to pin 2
int ledPin = 3; //LED connected to pin 3

void setup() {

pinMode(ledPin, OUTPUT); // Set LED as output
pinMode(pirPin, INPUT); // Set PIR Out as input

}

void loop(){

if(digitalRead(pirPin) == HIGH){ // If motion detected

digitalWrite(ledPin, HIGH); // Turn on LED

}
else{

digitalWrite(ledPin, LOW); // Else turn off LED

}

}
```

  1. Verify and upload the sketch to your Arduino board.

This simple sketch continually checks the PIR sensor pin in the loop. When motion is detected, the PIR output goes HIGH and the code turns the LED on. When no motion, the LED turns off.

Setting Up the PIR Sensor

The PIR sensor requires a few adjustments to work properly for this project:

Make tweaks to these settings as needed so the sensor reliably detects you walking by but doesn't trigger unnecessarily.

Enclosing the Project in a Case

For a polished finish, mount the project in an enclosure. Here are options:

Use hot glue, tape, screws or mounting brackets to secure the components inside the enclosure. Make it light-tight so the LED illuminates only when triggered.

Attach the 9V battery with velcro or glue, or solder the battery clip wires directly to a power switch. Add a removable lid to access the electronics.

Conclusion

Building a motion-activated night light with Arduino is an easy, inexpensive project using common components like a PIR sensor, LED, and resistor.

With the help of the circuit diagram, sample code, and setup instructions in this guide, you now have the knowledge to create your own motion-sensing light for navigating dark rooms and corridors.

Customize the design by adding more LEDs in different colors, incorporating a photoresistor to detect ambient light, or using a brighter lamp in place of the LED. The basic functionality will work the same.

So get building and soon you'll have a handy gadget to light up the night! Let me know if you have any other questions.