How does the circuit of ITD(Time delay) and voltage sense works?
With the first circuit, there is no means to charge C8 other than the ITD pin being held low by the microcontroller. Assuming the circuit is correct, this must be what the original unit does.
https://www.electronics-tutorials.ws/rc/rc_1.html
describes RC time constants. C8 is the capacitor and R8 is the discharge resistor. If the system is powered (5V) and ITD is held low, then the capacitor charges via R9 and D5. The operation of D5 can be ignored for the purposes of the calculation.
D5 &amp; D6 are most likely schottky diodes. Something like a BAT85. Don't be tempted to use a larger schottky diode like a 1N5819 as the leakage might be significant.
C8 will eventually be fully charged. When the power is removed, D5 will block any other discharge path and C8 will discharge via R8. This determines the 4 minutes (or so - it won't be super accurate).
When powered on, depending on the charge left on C8 (let's assume it is fully discharged) then the capacitor will apear as a short circuit and pass the 5V signal through D5 and R9. The microcontroller can then use it's ADC to measure the voltage which would be close to 5V (more like around 4.7V due to the diode drop of D5).
If the capacitor was fully charged (ie the circuit was not off for less than 4 minutes), the voltage at ITC will be less than 4.7V. The microcontroller code will keep on sampling that voltage until it reaches 4V or so thus creating a time delay.
once that has happened, the microcontroller would pull the ITC pin low to charge the capacitor again.
The second circuit is a half wave rectifier (D1) and a voltage divider consisting of R6,R7 and R21. based on the values the division is around 100:1. ie 100V in gives 1V out at Vsense. For a 240Vac input, Vsense will measure approximately 3.2V (240 * 1.4142 / 100). 1.4142 is the square root of two as 240VAC is the RMS value (google that) and 1.4142 determines the peak voltage.
Note that R6 &amp; R7 have significant voltage across them. They must be adequately rated for this application. Something like a Vishay PR01 series.
It also must be said that this circuit has mains voltages present - thus it is extremely dangerous. Unless you fully understand the implications, you can easily blow up the computer you connect the circuit to or worse still electrocute yourself and/or set fire to your house. No joking.