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:

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:

  1. Connect the LED's positive leg to Arduino pin 12 through a 220 ohm resistor.

  2. Connect the LED's negative leg directly to the Arduino's GND pin.

  3. Connect the PIR sensor's VCC pin to 5V on the Arduino.

  4. Connect the PIR sensor's GND pin to GND on the Arduino.

  5. 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:

  1. Connect the Arduino board to your PC with the USB cable.
  2. Open the Arduino IDE and paste in the code.
  3. Select the Arduino board type and COM port.
  4. 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:

Some ways to use the finished motion-activated night light:

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!