Skip to content

Instantly share code, notes, and snippets.

Created March 2, 2018 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/8f0be0ffb6366ebe814c6d9b0ef7cd49 to your computer and use it in GitHub Desktop.
Save anonymous/8f0be0ffb6366ebe814c6d9b0ef7cd49 to your computer and use it in GitHub Desktop.
int irmotionPin = 4; // Pin of IR Motion Sensor
int relayPin = 5; // Pin of Relay Module
void setup(){
Serial.begin(9600);
pinMode(relayPin, OUTPUT); // Set Pin connected to Relay as an OUTPUT
digitalWrite(relayPin, LOW); // Set Pin to LOW to turn Relay OFF
}
void loop(){
while (digitalRead(irmotionPin) == HIGH) { // If Motion detected
digitalWrite(relayPin, HIGH); // Turn Relay ON
Serial.println("Relay is ON");
delay(10000);
}
digitalWrite(relayPin, LOW); // Turn Relay OFF
Serial.println("Relay is OFF");
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment