Hi guys (I'm using google translate). I'm planning to use motion sensors (HC-SR501)
I have made an automatic garage lighting with arduino nano. But I can't make it work because I want the light to stay on when I'm inside but turn off after 5 minutes when I come out but I don't know how much the sensor detects motion. And because of the length of the cable there will be no signal loss. I would put the sensors on the ceiling and the signal legs in a node and then in the arduino so any good or better ideas are welcome
The code:
const int motionPin = 2; // PIR mozgásérzékelő csatlakozása a D2-es tüskére
const int relayPin = 3; // Relé csatlakozása a D3-as tüskére
const int lightTime = 1200000; // Lámpa bekapcsolási idő (20 perc = 1200000 milliszekundum)
void setup() {
pinMode(motionPin, INPUT);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW); // Kezdetben a relét kikapcsoljuk
}
void loop() {
int motionDetected = digitalRead(motionPin);
if (motionDetected == HIGH) {
// Ha mozgást érzékelünk, bekapcsoljuk a lámpát
digitalWrite(relayPin, HIGH);
delay(lightTime);
}
// Ha 20 perc eltelt, és nem érzékelt mozgást, kikapcsoljuk a lámpát
digitalWrite(relayPin, LOW);
}