Professional Documents
Culture Documents
Connect the VCC pin of the PIR sensor to the 5V pin of the Arduino Uno R3.
Connect the GND pin of the PIR sensor to the GND pin of the Arduino Uno R3.
Connect the DATA pin of the PIR sensor to a digital pin of the Arduino Uno R3 (e.g., pin 2).
Connect the LED to digital pin 13 of the Arduino Uno R3.
Connect a resistor between the LED's long leg (anode) and digital pin 13 to limit the current.
Software Setup
#include <Arduino.h>
int motionSensorPin = 2;
void setup() {
pinMode(motionSensorPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Open the Arduino IDE. }
Write the following code: C++ void loop() {
if (motionSensorValue == HIGH) {
digitalWrite(ledPin, HIGH);
Serial.println("Motion detected!");
} else {
digitalWrite(ledPin, LOW);
delay(1000);
}
Application Scenarios