int detectedLED = 13; // Вказуємо ніжку
int readyLED = 12; // Вказуємо ніжку
int waitLED = 11; // Вказуємо ніжку
int pirPin = 7; // Вказуємо ніжку датчика
int motionDetected = 0; // Змінна для виявлення руху
int pirValue; // Змінна для збереження значення з PIR
void setup ()
{
pinMode (detectedLED, OUTPUT); // Установка ніжки як вихід
pinMode (readyLED, OUTPUT); // Установка ніжки як вихід
pinMode (waitLED, OUTPUT); // Установка ніжки як вихід
pinMode (pirPin, INPUT); // Установка ніжки як вхід
// Початкова затримка 1 хвилина, для стабілізації датчика //
digitalWrite (detectedLED, LOW);
digitalWrite (readyLED, LOW);
digitalWrite (waitLED, HIGH);
delay (4000);
digitalWrite (readyLED, HIGH);
digitalWrite (waitLED, LOW);
}
void loop ()
{
pirValue = digitalRead (pirPin); // Прочитуємо значення від датчика руху
if (pirValue == 1) // Якщо рух є, робимо затримку в 3 с.
{
digitalWrite (detectedLED, HIGH);
motionDetected = 1;
delay (2000);
}
else
{
digitalWrite (detectedLED, LOW);
}
// Затримка після спрацьовування //
if (motionDetected == 1)
{
digitalWrite (detectedLED, LOW);
digitalWrite (readyLED, LOW);
digitalWrite (waitLED, HIGH);
delay (4000);
digitalWrite (readyLED, HIGH);
digitalWrite (waitLED, LOW);
motionDetected = 0;
}
}