Introduction
Build an automatic transfer switch that switches between mains and generator power within seconds during outages. This comprehensive guide covers everything from design through implementation, testing, and deployment.
Build an automatic transfer switch that switches between mains and generator power within seconds during outages.
Build an automatic transfer switch that switches between mains and generator power within seconds during outages. This comprehensive guide covers everything from design through implementation, testing, and deployment.
An ATS monitors the main supply continuously. When mains voltage falls below threshold (typically <180V or >270V) for more than 3 seconds, the ATS: (1) opens the mains contactor, (2) sends auto-start signal to the generator, (3) waits for generator to reach stable voltage and frequency, (4) closes the generator contactor. On mains restoration, the reverse sequence executes with a time delay to confirm supply stability.
10 components required for this project.
| # | Component | Purpose | Qty |
|---|---|---|---|
| 1 | Arduino Uno | ATS control logic | x1 |
| 2 | 2-Pole 40A Contactor | Mains and generator switching (interlocked) | x2 |
| 3 | ZMPT101B Voltage Sensor | Mains and generator voltage monitoring | x2 |
| 4 | 5V 5A Relay Module (4-channel) | Contactor coil control and generator signals | x1 |
| 5 | LCD 16×2 with I2C | Status and timer display | x1 |
| 6 | MOFSET Driver Module (IRF540N) | Driving contactor coils from Arduino | x2 |
| 7 | 24V DC Power Supply | Control circuit power (isolated) | x1 |
| 8 | Buzzer 5V | Alarm for mains failure and transfer | x1 |
| 9 | DIN Rail Enclosure (8-module) | Professional panel mounting | x1 |
| 10 | Mechanical Interlock Kit | Prevent simultaneous mains+generator connection | x1 |
Follow these 7 steps carefully.
An ATS monitors the main supply continuously. When mains voltage falls below threshold (typically <180V or >270V) for more than 3 seconds, the ATS: (1) opens the mains contactor, (2) sends auto-start signal to the generator, (3) waits for generator to reach stable voltage and frequency, (4) closes the generator contactor. On mains restoration, the reverse sequence executes with a time delay to confirm supply stability.
The most critical safety feature is the mechanical and electrical interlock preventing both contactors from closing simultaneously — connecting mains and generator together would be catastrophic. Mechanical interlock: use a physical interlock kit between the two contactors (they mechanically prevent each other from closing). Electrical interlock: wire each contactor's NC (normally closed) auxiliary contact in series with the other contactor's coil circuit.
Sample mains and generator voltages using two ZMPT101B sensors on Arduino analog inputs. Calculate RMS voltage using the Emonlib approach or direct zero-crossing timing. Set trip thresholds: undervoltage < 180V, overvoltage > 270V, for Indian 230V supply. Also monitor frequency by timing between zero-crossings: 1/(2 × time_between_ZC). Alert if frequency deviates beyond 48–52 Hz.
Most generators with electric start have a remote start interface: connecting two pins triggers auto-crank. Wire a relay output from Arduino to this interface. On mains failure detection, activate the relay for 3–5 seconds (crank time) then release. Monitor generator voltage sensor — if generator reaches >200V within 30 seconds, declare generator ready. If not, retry crank up to 3 times before raising a fault alarm.
Implement a state machine: MAINS_NORMAL → MAINS_FAULT_DETECTED (3s delay) → GENERATOR_STARTING (30s timeout) → GENERATOR_STABLE (2s confirm) → TRANSFERRED_TO_GENERATOR → [mains restored] → MAINS_RESTORED_DETECTED (10s stability confirm) → RETRANSFER_TO_MAINS → MAINS_NORMAL. All transitions must be logged with timestamp and reason.
For large generators where not all loads can run simultaneously, implement load shedding. Define load priority levels 1–4 in code. On generator mode, energize only priority-1 and priority-2 loads initially. If generator is running at <80% capacity for 5 minutes, add priority-3 loads. This prevents generator overload during cold start when torque capacity is limited.
Test by manually cutting mains power with a switch while monitoring LCD and measuring voltages with a multimeter. Verify: transfer time < 10 seconds (generator start + stable + transfer), mechanical interlock prevents simultaneous closure, voltage thresholds trigger correctly, generator auto-start cranks and starts, retransfer occurs with proper delay after mains restoration, and all events are logged.
Core code for ats_controller.ino:
// ATS State Machine Controller enum ATSState { MAINS_OK, MAINS_FAULT, GEN_STARTING, GEN_STABLE, ON_GENERATOR, RETRANSFER }; ATSState state = MAINS_OK; unsigned long stateTimer = 0; int genStartAttempts = 0; #define MAINS_CONTACTOR 7 #define GEN_CONTACTOR 8 #define GEN_START_RELAY 9 #define BUZZER_PIN 6 float readVoltage(int pin) { return analogRead(pin) * (230.0 / 512.0); } void loop() { float mainsV = readVoltage(A0); float genV = readVoltage(A1); unsigned long now = millis(); switch(state) { case MAINS_OK: if (mainsV < 180 || mainsV > 270) { if (now - stateTimer > 3000) { state = MAINS_FAULT; stateTimer = now; tone(BUZZER_PIN, 1000, 500); } } else { stateTimer = now; } break; case MAINS_FAULT: digitalWrite(MAINS_CONTACTOR, LOW); digitalWrite(GEN_START_RELAY, HIGH); state = GEN_STARTING; stateTimer = now; genStartAttempts++; break; case GEN_STARTING: if (genV > 200) { state = GEN_STABLE; stateTimer = now; digitalWrite(GEN_START_RELAY, LOW); } else if (now - stateTimer > 30000) { if (genStartAttempts < 3) { state = MAINS_FAULT; } else { } } break; case GEN_STABLE: if (now - stateTimer > 2000) { digitalWrite(GEN_CONTACTOR, HIGH); state = ON_GENERATOR; } break; case ON_GENERATOR: if (mainsV > 200 && mainsV < 260) { if (now - stateTimer > 10000) { state = RETRANSFER; stateTimer = now; } } else { stateTimer = now; } break; case RETRANSFER: digitalWrite(GEN_CONTACTOR, LOW); delay(500); digitalWrite(MAINS_CONTACTOR, HIGH); genStartAttempts = 0; state = MAINS_OK; stateTimer = now; break; } }
Test Automatic Transfer Switch (ATS) by verifying each subsystem individually before full integration.
Verify power voltages, check ground connections, use serial monitor for debug.
An interactive simulator will be available here — simulate circuits and run code in-browser without hardware.