How to make a motion(PIR) sensor light




 Materials:- 

Diagram:-



Connections:-

PIR motion sensor to Arduino

  • PIR VCC = Arduino 3.3V
  • PIR GND = Arduino GND
  • PIR  out   = Arduino D7

Relay to Arduino

  • Relay VCC = Arduino 5V
  • Relay GND = Arduino GND
  • Relay IN1 = Arduino D9


Downloads:-

Code = https://bit.ly/3ip9zoZ


Code


int pir = 7;

int relay = 9;


void setup() {

pinMode(pir, INPUT);

pinMode(relay, OUTPUT);

}


void loop() {

  int val =digitalRead(pir);

if(val== 1){

  digitalWrite(relay, HIGH);

}else{

  digitalWrite(relay, LOW);

}

}