How to use PIR motion sensor with Arduino





Materials:-
Diagram:-







Connections:-

PIR motion sensor to Arduino
  • Pir VCC = Arduino 5V
  • pir GND = Arduino GND
  • Pir out = Arduino D8
LED to Arduino
  • LED (+) = Arduino D13
  • LED (-) = Arduino GND
Downloads:-


int led = 13;
int pir = 8;
void setup() {
pinMode(pir, INPUT);
pinMode(led, OUTPUT);
}

void loop() {
  int val =digitalRead(pir);
if(val== 1){
  digitalWrite(led, HIGH);
}else{
  digitalWrite(led, LOW);
}
}