Materials:-
- Arduino uno = https://bit.ly/30v5XcY
- PIR sensor = https://bit.ly/30hBAIJ
- Relay = https://bit.ly/2ZPVydK
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);
}
}