// .
// .
#define Sensor_1 10 // -SR501.
#define Sensor_2 11 // -SR501.
#define D0 3 // .
int Relay[2] = {8, 9}; // .
int Button[2] = {5, 6}; // .
// .
boolean Start_Sensor = false; // .
boolean relayEnabled[2] = {true, true}; // .
boolean buttonWasUp[2] = {true, true}; // .
unsigned long previousMillis = 0; /*
. */
unsigned long activateTime; // .
int value = 0; // .
// .
const int T_hold = 10000; // .
const int T_motion = 200; // .
void setup()
{
// .
pinMode(D0, INPUT); // - .
for (int i = 0; i < 2; ++i)
{
pinMode(Relay[i], OUTPUT); // - .
pinMode(Button[i], INPUT_PULLUP); // - .
digitalWrite(Relay[i], relayEnabled[i]); /* ,
. */
}
}
void loop()
{
if(digitalRead(D0)) // " ?"
{
Sensor_Work();
if (relayEnabled[0] == true && Start_Sensor == true)
// 1 () .
{
relayEnabled[0] = false; // ().
digitalWrite(Relay[0], relayEnabled[0]); // .
activateTime = millis(); // .
while((millis() - activateTime) < T_hold)
{
// .
}
relayEnabled[0] = true; // ().
digitalWrite(Relay[0], relayEnabled[0]); // .
}
}
// , .
for (int i = 0; i < 2; ++i)
{
boolean buttonIsUp = digitalRead(Button[i]);
// (&&) ...
if (buttonWasUp[i] && !buttonIsUp)
{
/* , (),
,
*/
delay(10);
// .
buttonIsUp = digitalRead(Button[i]);
if (!buttonIsUp)
{
// ...
relayEnabled[i] = !relayEnabled[i]; // .
digitalWrite(Relay[i], relayEnabled[i]); // .
}
}
// .
buttonWasUp[i] = buttonIsUp;
}
}
void Sensor_Work() // .
{
if (digitalRead(Sensor_1) == HIGH || digitalRead(Sensor_2) == HIGH) /*
. */
{
// .
if (millis() - previousMillis > T_motion)
{
previousMillis = millis();
value++;
}
}
else
{
Start_Sensor = false; // .
value = 0;
}
if(value >= 10)
{
Start_Sensor = true; // .
value = 0;
}
}
Arduino Pro Mini Atmega 328 5 V 16 MHz Controller | one |
Pyroelectric infrared sensor HC-SR501 | 2 |
Light sensor on the LM393 chip | one |
Voltage stabilizer L7805CV | one |
0.33 uF ceramic capacitor | one |
Ceramic condenser 0.1 microfarad | one |
PBS 1 × 40 2.54 socket | one |
SWD1-1 switch | 2 |
Two-pin screw terminal | 9 |
Glass fiber 61 × 46 mm | one |
Glass fiber 40 × 20 mm | one |
Clock Button | 2 |
Textolite | one |
Fluorescent lamp Camelion WL-4002, 16 W | 12 |
Ceiling lamp with two incandescent lamps | one |
Junction box | eight |
PUNP cable 2 × 2.5 | |
Cable telephone ShTLP -4 0.12 × 7 | |
Cable channel (various sizes) | |
Consumables (glue, glue Moment Crystal, solder, rosin, TAGS flux, tips) | |
Fasteners (bolts, nuts, screws, dowels, clamps) |
Source: https://habr.com/ru/post/370623/