I tried the serial printing on your suggestion and came to the following conclusion. At the first voltage confirmation, it works partially correctly. However, after the next voltage confirmation, it opens the relay in the "relay()" function without waiting for the specified time. The "millis()" time runs from the moment the Arduino is powered up. This means that the specified waiting time expires before the voltage confirmation. So if I later confirm the voltage, nothing changes because of "currentmillis=millis()". I tried your suggestion but it still doesn't work as I want. I'm still struggling to solve this.