How to Build a Simple Motion-Activated Night Light for Under $15

Introduction

Having a motion-activated night light can be incredibly convenient. It turns on automatically when you enter a dark room, allowing you to navigate safely without fumbling for a switch. Best of all, with just a few inexpensive components, you can build one yourself for under $15! In this guide, I'll walk you through a simple DIY motion-activated night light project step-by-step.

What You'll Need

To build this motion-activated night light, you'll need just a few basic components:

Circuit Design

The circuit for this project is very simple. We just need to connect the PIR motion sensor and the LED light to the Arduino.

Connect the PIR motion sensor

Connect the LED light

That's it for the circuit! The Arduino code will handle the rest.

The Arduino Sketch

The Arduino sketch reads the output of the PIR sensor to detect motion. When motion is detected, it turns the LED light on.

Include the Servo library

```c

include

```

Pin constants

c
const int pirPin = 2; // PIR output pin
const int ledPin = 12; // LED pin

Global variables

c
Servo myLed; // Create LED object
int pirValue; // Store PIR value

Setup

Attaches the LED to its pin to be controlled.

```c
void setup() {

myLed.attach(ledPin);
pinMode(pirPin, INPUT); // Set PIR pin as input

}
```

Main loop

Continuously checks the PIR sensor and turns the LED on when motion detected.

```c
void loop(){

pirValue = digitalRead(pirPin); // Read PIR value

if(pirValue == HIGH){ // If motion detected

myLed.write(255); // Turn LED fully on

}
else {

myLed.write(0); // Turn LED fully off

}

}
```

And that's it! Upload this code to your Arduino and your motion-sensing night light is complete.

Putting It Together

With the circuit assembled and code uploaded, all that's left is mounting everything inside your enclosure.

Be sure to position the PIR sensor so it can effectively "see" motion in the area you want to detect.

Some optional enhancements you could add:

Conclusion

Building your own motion-activated night light is an easy Arduino project that requires only basic components. In under an hour, you can have a custom automated light turning on whenever you enter a room, all for less than $15! Adjustments like setting the light threshold or adding a darkness sensor can take it to the next level. I hope this guide gave you everything you need to build your own. Let me know if you have any other questions!