PIR Motion Sensor With Arduino & LED

by 779577 in Circuits > Arduino

62 Views, 0 Favorites, 0 Comments

PIR Motion Sensor With Arduino & LED

Screenshot_22-1-2025_234940_www.tinkercad.com.jpeg

This project is a motion-activated LED circuit designed to automatically detect movement using a PIR (Passive Infrared) motion sensor. When motion is detected, the sensor sends a signal to the Arduino, which then turns on the LED. The purpose of this setup is to automate lighting, making it more energy-efficient by activating only when motion is present. It can be used in various applications, such as home automation, outdoor lighting, or basic security systems, where the detection of movement triggers a response. This makes it a practical and straightforward solution for convenience and energy savings!

Supplies

Screenshot_22-1-2025_235223_www.tinkercad.com.jpeg

1x Arduino Uno R3 ($42.58 CAD)

1x PIR Motion Sensor ($17.49 CAD (Pack of 5))

1x LED ($16.79 CAD, assorted pack)

1x Resistor (330Ω) ($8.71 CAD)

1x Breadboard ($20 CAD)

3x Male/Female Wires ($9.99 CAD)

Wires ($20.86 CAD)

Set Up the Circuit

Connect the PIR Motion Sensor:

  1. VCC (PIR) → Connect to 5V pin on Arduino.
  2. GND (PIR) → Connect to GND pin on Arduino.
  3. OUT (PIR) → Connect to a digital pin on Arduino (e.g., Pin 7).

Connect the LED:

  1. Insert the LED into the breadboard:
  2. Long leg (anode) → Connect to a digital pin (e.g., Pin 8) on Arduino through a 330Ω resistor.
  3. Short leg (cathode) → Connect to GND.

Power the Breadboard:

  1. Connect the breadboard's power and ground rails to the 5V and GND pins on the Arduino, respectively.

Write the Code

1) Open the Arduino IDE on your computer.

2) Enter the following code:

int pirPin = 7; // Pin connected to PIR sensor output
int ledPin = 8; // Pin connected to LED

void setup() {
pinMode(pirPin, INPUT); // Set PIR sensor pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Initialize serial communication (optional)
}

void loop() {
int motionDetected = digitalRead(pirPin); // Read PIR sensor output
if (motionDetected == HIGH) { // If motion is detected
digitalWrite(ledPin, HIGH); // Turn on LED
Serial.println("Motion Detected!"); // Print message to serial monitor
} else {
digitalWrite(ledPin, LOW); // Turn off LED
}
delay(100); // Small delay to stabilize sensor readings
}


3) Connect the Arduino to your computer via the USB cable and upload the code.

Test the Circuit

Screenshot_22-1-2025_235338_www.tinkercad.com.jpeg

1) Place the PIR motion sensor in an open area.

2) Power the Arduino by keeping it connected to your computer or through an external power source.

3) Observe the behavior of the LED:

  1. The LED should turn on when motion is detected.
  2. The LED should turn off after the motion stops (depending on the PIR sensor's delay settings).


Fine-Tune the PIR Sensor (Optional)

Adjust the sensitivity and delay time of the PIR sensor using the two potentiometers on the module:

  1. Delay time: Adjust how long the LED stays on after detecting motion.
  2. Sensitivity: Adjust the range of motion detection.

Troubleshooting Tips

1) If the LED is always on:

  1. Check the wiring of the PIR sensor and ensure the output pin is connected properly.
  2. Verify the sensor has had time to calibrate (usually 30–60 seconds after powering up).
  3. Ensure the PIR sensor is not placed near a heat source or other moving objects.

2) If the LED doesn’t turn on:

  1. Confirm the LED polarity (long leg to the resistor and digital pin).
  2. Check the resistor value (use 330Ω or similar).
  3. Make sure the PIR sensor is detecting motion (check the Serial Monitor for output).