How to Use PIR Motion Sensor (Digital Input)

by STEAM-DIY in Circuits > Arduino

89 Views, 0 Favorites, 0 Comments

How to Use PIR Motion Sensor (Digital Input)

t725.png

The PIR (Passive Infrared) sensor detects motion. This project will trigger an LED when motion is detected using Arduino.

Supplies

Arduino UNO

PIR Motion Sensor

Breadboard

Jumper Wires

LED

Resistor (220Ω)

Step 1

Wiring:

  1. PIR Sensor:
  2. Connect the VCC to the 5V pin on Arduino.
  3. Connect GND to the ground (GND) on Arduino.
  4. Connect the OUT pin to digital pin 2 on Arduino.
  5. LED:
  6. Connect the long leg (+) to digital pin 13 with a resistor.
  7. Connect the short leg (-) to GND.

Step 2 Coding

int sensorState = 0;

void setup()

{

pinMode(2, INPUT);

pinMode(LED_BUILTIN, OUTPUT);

Serial.begin(9600);

}

void loop()

{

// read the state of the sensor/digital input

sensorState = digitalRead(2);

// check if sensor pin is HIGH. if it is, set the

// LED on.

if (sensorState == HIGH) {

digitalWrite(LED_BUILTIN, HIGH);

Serial.println("Sensor activated!");

} else {

digitalWrite(LED_BUILTIN, LOW);

}

delay(10); // Delay a little bit to improve simulation performance

}

Testing

Upload the code, and when motion is detected by the PIR sensor, the LED will light up.

Let me know if you need further assistance!