I used goto label in writing the program to keep with the flow chart, and keep the program simple to understand.
The first draft of the program I used Analog inputs to measure the voltage for both the Audio current sensor, and the ON hook sensor. The analog input for the Audio current sensor is OK as no audio results in 0 volts due to the .1 ufd capacitor and its 220 K ohm bleed resistor has a RC time of .022 seconds and the sample rate is at 5 second intervals.
Sometimes there may be 0 volts, but there should be at least one that is more than 0 volts during the 2 minutes, that would send the program back to the beginning.
A problem occurred with the ON hook sensor when ON hook. The opto isolator with its low LED current did not provide 0 volts when the output photo transistor was turned on. I simply changed the Analog input to a Digital input, I am looking for a LOW and a HIGH, which is what the opto isolator is providing.
One other problem I had was intermittent operation during the One Minute and Two Minute delay routines, as the variables twoMinuteTimer and oneMinuteTimer were originally int. I changed them to static int and the intermittent problem went away.
I have found that the Arduino C++ compiler reuses variable memory space unless it is made static, and if not static your counting variable will change during the program unexpectedly. Static prevents the memory space being reused during the program, it is reserved for that variable only, to be changed for that variable!
In keeping memory usage down I saved 4 bytes by changing the variables twoMinuteTimer and the oneMinuteTimer to static byte. The binary numbers for 12 and 24 easily fit within a 8 bit byte of memory.
The program is checking the sensor inputs every 5 seconds, starting if ON HOOK. The most common event is the phone is ON HOOK, but once OFF HOOK the audio sensor is checked for NO audio, if no audio is detected the program moves to the test for NO audio for 2 minutes, otherwise go to Start.
WAIT 2 MINUTES
Once in the Wait2Minute area of the program and the On hook remains OFF HOOK, and there is NO AUDIO, the program moves to the BasePowerOff for 1 minute, otherwise go to Start.
BASE POWER OFF
Once in the BasePowerOff area the relay output turns on the relay, breaking the Normally Closed contacts,
waits one minute,
turns off the relay re-making the Normally Closed contacts,
and then go back to START.
To start the process all over with the offending cordless phone that was OFF HOOK, now back ON HOOK!