Project Overview:

This beginner-friendly project demonstrates how to use a Passive Infrared (PIR) sensor with an Arduino to detect motion and activate an LED. It’s perfect for creating motion-based alerts or simple security systems.

How It Works:

The PIR sensor detects changes in infrared radiation (heat) from moving objects. When motion is detected, the sensor sends a HIGH signal to the Arduino, which then turns on an LED. When no motion is detected, the LED is turned off.

Components List:

  1. Arduino Board (e.g., Uno, Nano, etc.)
  2. PIR Motion Sensor
  3. LED
  4. 220-ohm Resistor (for the LED)
  5. Jumper Wires
  6. Breadboard (optional)
  7. Power Supply (for Arduino)

Software List:

  • Arduino IDE (Integrated Development Environment)

Circuit Diagram and Connection:

Component

Arduino Pin

PIR Sensor (VCC)

5V

PIR Sensor (GND)

GND

PIR Sensor (OUT)

Digital Pin 2

LED (Anode)

Digital Pin 13

LED (Cathode)

GND

Resistor (220-ohm)

Between LED and GND

  1. Connect the VCC pin of the PIR sensor to the 5V pin on the Arduino.

  2. Connect the GND pin of the PIR sensor to the GND pin on the Arduino.

  3. Connect the OUT pin of the PIR sensor to Digital Pin 2 on the Arduino.

  4. Connect the anode (longer leg) of the LED to Digital Pin 13 on the Arduino.

  5. Connect the cathode (shorter leg) of the LED to the GND pin on the Arduino through a 220-ohm resistor.

Project Code:

int sensorState = 0; // Variable to hold the state of the PIR sensor


void setup() {

  pinMode(2, INPUT);  // Set digital pin 2 as input for the PIR sensor

  pinMode(13, OUTPUT); // Set digital pin 13 as output for the LED

}

void loop() {

  sensorState = digitalRead(2); // Read the state of the PIR sensor


  if (sensorState == HIGH) { // Check if motion is detected

    digitalWrite(13, HIGH); // Turn on the LED

  } else {

    digitalWrite(13, LOW); // Turn off the LED

  }

}


Explanation of the Code:

  • Variable Declaration: int sensorState = 0; initializes a variable to store the sensor’s state.

  • Setup Function:

    • pinMode(2, INPUT); configures pin 2 as an input for the PIR sensor.

    • pinMode(13, OUTPUT); configures pin 13 as an output for the LED.

  • Loop Function:

    • sensorState = digitalRead(2); reads the current state of the PIR sensor.

    • if (sensorState == HIGH) { digitalWrite(13, HIGH); } turns on the LED if motion is detected.

    • else { digitalWrite(13, LOW); } turns off the LED if no motion is detected.

Test and Troubleshooting:

  1. Testing: Upload the code to your Arduino and test the PIR sensor. When motion is detected, the LED should light up.

  2. Troubleshooting:

    • Ensure all connections are secure and correctly made.

    • Verify that the PIR sensor and LED are functioning properly.

    • Check if the PIR sensor’s sensitivity and delay settings are correctly adjusted (if applicable).

Summary:

In this project, you used a PIR sensor to detect motion and control an LED with an Arduino. This simple yet effective setup can be expanded for various applications such as security systems or motion-activated alerts.


No comments

Theme images by Dizzo. Powered by Blogger.