const int relayPin = 4; // define the output for relay
const int pirPin = 7; // define the input where the PIR sensor is connected
int pirState = LOW; // starting state for the PIR detector
int var = 0;
void setup() {
pinMode(relayPin, OUTPUT);
pinMode(pirPin, INPUT);
}
void loop() {
pirState = digitalRead(pirPin);
if(pirState == LOW){
// nothing is moving; no change
digitalWrite(relayPin, LOW);
}
else{
digitalWrite(relayPin, HIGH);
}
}