PIR Sensor with Arduino UNO

Introduction
The PIR (Passive Infrared) Sensor is a popular motion detection sensor used in Arduino projects. It detects infrared radiation emitted by humans and animals, making it ideal for security systems, automatic lighting, smart home automation, and motion-triggered devices.
In this tutorial, you will learn how to interface a PIR Sensor with an Arduino UNO, upload the code, and detect motion using the Serial Monitor. By the end of this guide, you'll understand how PIR sensors work and how they can be used in motion detection applications.
Components Required
Tools Required
Software Required
| Item Name | Action |
|---|---|
Arduio IDE | Download |
Circuit Diagram
Source Code
const int pirPin = 2;
void setup()
{
pinMode(pirPin, INPUT);
Serial.begin(9600);
}
void loop()
{
int motionState = digitalRead(pirPin);
if(motionState == HIGH)
{
Serial.println("Motion Detected");
}
else
{
Serial.println("No Motion");
}
delay(500);
}Step by Step Instructions
Step 1: Connect the PIR Sensor
Make the following connections:
PIR Sensor | Arduino UNO |
|---|---|
VCC | 5V |
GND | GND |
OUT | D2 |
Step 2: Open Arduino IDE
Launch Arduino IDE.
Connect Arduino UNO using USB.
Select:
Board → Arduino UNO
Port → Correct COM Port
Step 3: Create a New Sketch
Create a new Arduino sketch and paste the provided code.
Step 4: Verify the Code
Click the Verify button to check for syntax errors.
Step 5: Upload the Code
Click Upload and wait for the upload process to complete successfully.
Step 6: Open Serial Monitor
Open Serial Monitor.
Set the baud rate to 9600.
Wait 30–60 seconds for the PIR sensor to stabilize.
Move your hand or walk in front of the sensor.
The Serial Monitor will display motion detection messages.
Expected Output
When motion is detected:
Motion Detected
Motion Detected
Motion DetectedWhen no movement is present:
No Motion
No Motion
No MotionConclusion
In this tutorial, you learned how to interface a PIR Sensor with Arduino UNO and detect motion using infrared sensing technology. This basic setup can be used in various Arduino projects that require human presence detection and motion sensing.









