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


Having a motion-activated night light can be incredibly handy around the house. I recently decided to make one for myself using an Arduino microcontroller and a passive infrared (PIR) motion sensor. In this article, I will walk you through the full process of making your own motion-activated night light with these components.

What You'll Need

To build this simple motion-activated night light, you will need:

Optionally, you may also want:

How a PIR Motion Sensor Works

Before we get into the build, it helps to understand how a PIR motion sensor works.

PIR sensors can detect movement and changes in infrared radiation. They have a dome-shaped lens that focuses infrared radiation onto a pyroelectric sensor inside. When the sensor detects a change in infrared radiation, such as from a moving person, it signals the detection.

PIR sensors are very handy for detecting motion and are often used in security systems and automatic lighting applications. The one we'll use for this project will detect motion up to 6 meters away.

Circuit Diagram

Here is the circuit 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. We connect power to 5V and ground to GND. The output pin connects to a digital input on the Arduino, in this case pin 2.

The LED connects from Arduino pin 3 to ground, with an optional current limiting resistor. Later we'll program the Arduino to turn the LED on when motion is detected.

Setting up the Hardware

Follow these steps to set up the hardware for the motion-activated night light:

  1. Mount the Arduino, breadboard, PIR sensor, and other components inside your cardboard enclosure.

  2. Connect the PIR sensor to the breadboard. Connect the power pin to 5V, ground pin to GND, and output pin to Arduino digital pin 2.

  3. Connect the positive leg of the LED to Arduino pin 3. Connect the negative leg to ground through a 220 ohm resistor.

  4. Make sure the Arduino is connected to your computer via the USB cable. This provides power to the Arduino.

  5. Provide 5V power to the breadboard rails from the Arduino's 5V and GND pins. This will power the PIR sensor.

  6. Optionally install a power switch to turn the night light on/off.

Loading the Arduino Sketch

With the hardware set up, it's time to load the Arduino sketch that will control the night light. Here are the steps:

  1. Download the Adafruit PIR sensor library and install it in your Arduino IDE.

  2. Copy the following sketch and paste it into a new Arduino sketch:

// Motion-Activated Night Light





int pirPin = 2; // Input for PIR sensor
int ledPin = 3; // Output for LED

void setup() {

pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);

// Initialize serial connection


void loop(){

// Read PIR sensor value
int sensorStatus = digitalRead(pirPin);

if (sensorStatus == HIGH) {

// Motion detected
digitalWrite(ledPin, HIGH); 
Serial.println("Motion detected!");

else {

// No motion
digitalWrite(ledPin, LOW);
Serial.println("No motion");




This sketch reads the PIR sensor pin and turns the LED on when motion is detected. It prints messages to serial monitor for debugging.

  1. Upload the sketch to your Arduino board. Make sure the correct board is selected.

  2. Open the serial monitor to see the sensor readings.

Testing and Using the Night Light

Once uploaded, open the serial monitor and walk in front of the PIR sensor. You should see it print "Motion detected!" and the LED should light up.

Try adjusting the PIR sensitivity and the delay at the end of the loop() function to modify the behavior. Adding a light diffuser will make the LED light more subtle and ambient.

Power the Arduino via USB or a power bank for portable use. Install the power switch to turn it on/off easily. Mount the enclosure wherever you need a handy motion-sensing night light!

Let me know if you have any other questions! Making an Arduino motion-activated night light is a fun electronics project.