Arduino Project – Automated Light System with PIR Sensor

In this article, we’ll walk you through the process of designing and building a simple automated light system using a PIR sensor.

A PIR sensor is a type of sensor used to detect motion by measuring the infrared radiation (heat) emitted by objects. It is commonly used in motion detectors, security systems, and lighting applications.

Visit Introduction to PIR Sensor: What Is It and How Does It Work? for more details about PIR sensors.

Hardware Required

  • Arduino UNO
Arduino UNO

For more information, visit Getting to Know Your Arduino Uno: A Beginner’s Guide to Its Components.

PIR Sensor
Relay
Breadboard
AC Bulb Socket
  • AC Power Plug
AC Power Plug
  • Bulb
Bulb
  • 9V Battery
9V Battery
  • Battery Connector
9V Battery Connector with DC Plug
  • Jumper Wires
Jumper Wires
Jumper Wire

Working Principle

Relays are used to control high-power devices with low-power signals, often from a microcontroller like an Arduino or Raspberry Pi. Trigger level refers to the logic voltage level (HIGH or LOW) required to activate the relay. You can determine the trigger type by checking the relay module’s datasheet or documentation.

  • Low-Level Trigger Relay: A LOW signal (0V) from the microcontroller turns the relay ON; a HIGH signal (5V) turns it OFF.
  • High-Level Trigger Relay: A HIGH signal (5V) from the microcontroller turns the relay ON; a LOW signal (0V) turns it OFF.

For further information, visit An Essential Introduction to DC Relays in Arduino Projects: What They Are and How They Work.

We use the low level trigger relay and normally open mode in this project. The circuit is normally open. The relay is activated when the control pin receives a low signal (0V). Then, the NO contact closes the circuit, causing the light to turn on.

If object movement is detected, the sensor value will be High. Then the Low signal will be sent to the relay. The activated relay will turn on the light.

Diagram

The circuit diagram for this project is provided below, and the details will be discussed in the setup section.

Automated Light System with PIR Sensor Diagram

Setup

Automated Light System Setup3
1. Connect the 5V and GND pins from the Arduino to the Breadboard
ArduinoBreadboard
5V+
GND
2. Connect the PIR Sensor to the Arduino
PIR SensorArduinoBreadboard
GND
OUTD3
VCC+
3. Wire the bulb socket

First, distinguish the hot wire and the neutral wire. In polarized plugs, the hot wire, which carries electrical current, is typically the one with the smooth insulation and the narrow blade, while the neutral wire has a ribbed or grooved insulation and a wider blade.

Connect the hot wire to the brass screw terminal and the neutral wire to the silver screw terminal. The details are in the video Which Wire is Hot on a Lamp Cord.

4. Cut the hot wire
5. Connect the relay to the hot wire

Connect the side leading to the light bulb to the NO terminal of the relay, and the side leading to the plug to the COM terminal.

It’s unsafe to switch the neutral wire with a relay, as it can create a hazardous situation where parts of the circuit remain energized even when the device is “off,” potentially leading to dangerous shocks or equipment damage.

6. Connect the relay to the Arduino
RelayArduinoBreadboard
VCC+
GND
IND2
7. Upload the program

Connect the Arduino to your computer using a USB cable. Upload the program to the Arduino through the Arduino IDE software. Visit Getting Started with Arduino IDE: A Beginner’s Guide to Coding and Creating for more information.

8. Connect the 9V battery to the Arduino
9. Connect the AC plug to the mains power supply

Code

#define SENSOR_PIN 3
#define RELAY_PIN 2

void setup()
{
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(SENSOR_PIN, INPUT);  
}

void loop()
{
  //If object movement is detected then the sensor value will be 1 else the value will be 0
  int sensorValue = digitalRead(SENSOR_PIN);

  if (sensorValue == HIGH)
  {
    digitalWrite(RELAY_PIN, LOW);  //Relay is low level trigger relay so we need to write LOW to switch on the light
  }
  else
  {
    digitalWrite(RELAY_PIN, HIGH);    
  }
}