Files
motionsensorrelay/motionsensorrelay.ino
2019-10-25 17:32:22 +03:00

25 行
564 B
C++

const int lightDelay = 90000;
const byte movePin = 3;
const byte relayPin = 4;
long lastmoveMillis = 0;
void setup() {
pinMode(movePin, INPUT);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH);
}
void loop(){
if (digitalRead(movePin) == 1) lastmoveMillis = millis();
delay(100);
if (lastmoveMillis > 0) activateRelay();
}
void activateRelay() {
if ((millis() - lastmoveMillis) < lightDelay) digitalWrite(relayPin, LOW);
if ((millis() - lastmoveMillis) > lightDelay) {
digitalWrite(relayPin, HIGH);
lastmoveMillis = 0;
}
}