Motion Sensor

by shaurya_sh3 in Circuits > Arduino

50 Views, 0 Favorites, 0 Comments

Motion Sensor

WIN_20240703_15_30_36_Pro.jpg
WIN_20240703_15_32_00_Pro.jpg
WIN_20240703_15_31_03_Pro.jpg

School project. Feel free to use it for your school project.

Supplies

Aurdino UNO

LED

PIR motion sensor

jumper wires


Add the Wires to the Sensor

Take the jumper wires and connect male to female from the motion sensors CVV to 5V, then do GND to GND, and finally OUT to Digital pin 2. This will sen our code to the aurdino and send if motion is detected.

Code

write this code for it


// Constants

const int pirSensorPin = 2; // Pin connected to PIR sensor

const int ledPin = 13;      // Pin connected to LED


void setup() {

  pinMode(ledPin, OUTPUT);        // LED pin as output

  pinMode(pirSensorPin, INPUT);   // PIR sensor pin as input

  Serial.begin(9600);             // Initialize serial communication for debugging

}


void loop() {

  int pirState = digitalRead(pirSensorPin); // Read the PIR sensor state


  Serial.println(pirState); // Print the PIR sensor state for debugging

 

  if (pirState == HIGH) {   // If motion is detected (PIR sensor outputs 1)

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

  } else {                  // If no motion is detected (PIR sensor outputs 0)

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

  }

 


}





Connect Led

Connect the led to the Digital pin 13 and the GND pin. The longer one to 13 and shorter on to gnd. You finished your project!