Quite right : poor grammar and bad explanation. I’ll fix that, particularly for other interested folk.
The main supply (+12…24V) charges C1 via R3. The purpose of this RC is so that when the button is pressed a single pulse is triggered to start the SMPS, the Arduino and the signal to start the timer.
The moment the button is pressed this pulse (of 12…24V) is sent via D2 and R4 to T2 switching it on, which in turn switches T1 on to supply the SMPS with current from the main supply. The Arduino now has power and bootload starts up.
At the same time of this particular button press the pulse is sent via D1 and R5 to Arduino pin A0 to start the 5 hour timer - the voltage is clamped to 5.1V by the zener to avoid possible damage to Arduino.
[The charge time of C1 is set by R3/C1. The pulse duration is set by the size of C1 and must be sufficient to cover the loading resulting from switching T2 on (and obviously T2, the SMPS and Arduino) long enough for proper bootloading PLUS the result of keeping pin A0 on during this time to ensure that the timer is started.
When the timer starts pin A1 goes HIGH. This voltage via D3 and R4 keeps T2, T1, the SMPS and the Arduino on. So now the Arduino is running and the timer has started.
When the 5 hours is up pin A1 switches LOW and turns T2, T1, SMPS and Arduino off.
However, if the button is pressed a second time before the 5 hours is up a new pulse via D1 and R5 to pin A0 interrupts the timer switching A1 LOW which then performs exactly the same as time-out, i.e. full turn-off.
(The pulse is long enough to ride over the bootloader period and timer-trigger, but short enough to avoid possible problems of holding the button down too long. In my bench test case R3 = 470k, C1 = 4u7 works perfectly.)
I hope this makes more sense.
Thanks again.
Just for clarity let’s summarise the real necessity of the sketch :
-
start 5 hour timer with HIGH on pin A0 [or this could be auto on start-up] and set pin A1 HIGH
-
when the timer time-out happens set A1 LOW (which will turn off the everything)
-
if A0 goes HIGH while the timer is running, set A1 to LOW (which will turn everything off).