// V2HswitchCtrl // Dfrobot Beetle ESP32-c3 /* (c)2026 Forward Computing and Control Pty. Ltd. * NSW Australia, www.forward.com.au * This code is not warranted to be fit for any purpose. You may only use it at your own risk. * This generated code may be freely used for both private and commercial use * provided this copyright is maintained. */ /** The aim of this code it to provide a dead time between switching to and from the car supply. This is to allow large transformers to discharge befor seeing the new AC waveform. This entire circuit is powered from the cars V2L 240V AC supply via a 240V monitor relay On power up, from Car supply, drive IO1 High to disconnect output from change over relay then after 20ms drive IO0 High to change over from House to Car supply then after 40ms drive IO1 Low to reconnect the new supply On loss of Car supply, just let power supply discharge and use that time delay to delay dropping back to house supply. The delay in power supply discharge is controlled by a resistor grounding the 12V supply only when there is not car supply. */ const int isolationRelayPin = 0; // disconnect power to house while changing over const int changeoverRelayPin = 1; // swaps between mains/enphase and Inster V2L const unsigned long relayActivationDelay = 20; // ms how long to ensure relay has activated. const unsigned long changeoverRelayDeadtimeDelay = 20; // ms add to relayActivationDelay //after this release isolation relay void setup() { pinMode(isolationRelayPin,OUTPUT); digitalWrite(isolationRelayPin, HIGH); // energise isolation relay delay(relayActivationDelay); // wait for isolation relay to energize, 20ms pinMode(changeoverRelayPin,OUTPUT); digitalWrite(changeoverRelayPin, HIGH); // energise changeover relay // wait for changover relay to energize + dead time for transformers to discharge delay(relayActivationDelay+changeoverRelayDeadtimeDelay); // i.e. 20 + 20 = 40ms delay here digitalWrite(isolationRelayPin, LOW); // release isolation relay to supply V2L power to house // total delay ~60ms i.e. 3 50Hz cycles, depending on isolation relay's response time. } void loop() { // nothing here, just hold changeover relay energized }