Practical case: Automatic Reservoir Pump Controller

Automatic Reservoir Pump Controller prototype (Maker Style)

Level: Medium | Construct a transistor-driven relay circuit to automatically control a water pump using a float switch.

Objective and use case

In this practical case, you will build an automatic reservoir pump controller. The circuit uses a mechanical float switch to trigger an NPN transistor, which energizes an electromechanical relay to drive a high-current DC pump (simulated here as a resistive load) and a status LED.

Why this is useful:
* Automates water level management in tanks, reservoirs, and sump basins.
* Safely isolates low-voltage control circuits from high-power loads.
* Demonstrates the practical interfacing of simple mechanical sensors with power electronics.
* Prevents overflow or dry-running conditions in industrial and agricultural settings.

Expected outcome:
* Closing the float switch applies a voltage to the transistor base, turning it on (saturation).
* The transistor sinks current for the relay coil, energizing it and closing its normally open (NO) contact.
* The simulated DC pump (load resistor) receives the full supply voltage.
* The status indicator LED illuminates when the pump is active.
* Releasing the switch de-energizes the relay, and the flyback diode safely dissipates the inductive voltage spike from the coil.

Target audience: Intermediate electronics students learning about transistor switching, electromechanical relays, and inductive load protection.

Materials

  • V1: 12 V DC supply, function: main power for relay coil and pump
  • V2: 5 V DC supply, function: control logic power for the float switch
  • SW1: SPST switch, function: simulated float switch or high-level sensor
  • R1: 1 kΩ resistor, function: transistor base current limiting
  • R2: 10 kΩ resistor, function: pull-down for transistor base to ensure turn-off
  • R3: 1 kΩ resistor, function: LED current limiting
  • RLOAD: 50 Ω high-power resistor, function: simulated DC pump load
  • Q1: 2N2222 NPN transistor, function: relay coil driver
  • D1: 1N4007 diode, function: flyback protection for relay coil
  • D2: Green LED, function: pump status indicator
  • K1: 12 V SPDT Relay, function: electromechanical switch for the pump

Wiring guide

  • V1 connects between node VCC12 and node 0.
  • V2 connects between node VCC5 and node 0.
  • SW1 connects between node VCC5 and node SENSE.
  • R1 connects between node SENSE and node VB.
  • R2 connects between node VB and node 0.
  • Q1 base connects to node VB, emitter connects to node 0, and collector connects to node COIL_NEG.
  • K1 coil connects between node VCC12 and node COIL_NEG.
  • K1 COM (Common) contact connects to node VCC12.
  • K1 NO (Normally Open) contact connects to node LOAD_SW.
  • D1 cathode connects to node VCC12 and anode connects to node COIL_NEG (placed anti-parallel to the relay coil).
  • RLOAD connects between node LOAD_SW and node 0.
  • R3 connects between node LOAD_SW and the anode of D2.
  • D2 cathode connects to node 0.

Conceptual block diagram

Conceptual block diagram — Relay Pump Controller
Quick read: inputs → main block → output (actuator or measurement). This summarizes the ASCII schematic below.

Schematic

VCC5 --> [ SW1 ] --(SENSE)--> [ R1 ] --(VB)--> [ Q1:B ]
                                              |          |
                                            [ R2 ]       |
                                              |          |
                                             GND         |
                                                         |
      VCC12 --> [ K1 Coil || D1(Rev) ] --(COIL_NEG)--> [ Q1:C ] --( )-- [ Q1:E ] --> GND
                       |
                (Magnetic Link)
                       v
      VCC12 --> [ K1 Switch (COM->NO) ] --(LOAD_SW)--> [ RLOAD (Pump) ] --> GND
                                              |
                                              +------> [ R3 ] --> [ D2 (LED) ] --> GND
Electrical Schematic

Electrical diagram

Electrical diagram for case: Automatic reservoir pump controller
Generated from the validated SPICE netlist for this case.

🔒 This electrical diagram is premium. With the 7-day pass or the monthly membership you can unlock the complete didactic material and the print-ready PDF pack.🔓 See premium access plans

Measurements and tests

  1. Control Logic Test: With SW1 open, measure the voltage at node SENSE. It should be 0 V. Close SW1 and verify the voltage rises to 5 V.
  2. Base Drive Verification: Measure the voltage at node VB with SW1 closed. It should read approximately 0.7 V, confirming the base-emitter junction of Q1 is forward-biased.
  3. Coil Switching Verification: Probe node COIL_NEG. When SW1 is open, it should measure 12 V. When SW1 is closed, it should drop to near 0 V (Vce_sat of the transistor), confirming the coil is energized.
  4. Load Delivery Test: Measure the voltage at node LOAD_SW. Verify that it reads 0 V when the relay is off, and jumps to 12 V when the relay clicks on. Check that the RLOAD draws current and D2 illuminates.

SPICE netlist and simulation

Reference SPICE Netlist (ngspice) — excerptFull SPICE netlist (ngspice)

* Automatic Reservoir Pump Controller
.width out=256

* Power Supplies
V1 VCC12 0 DC 12
V2 VCC5 0 DC 5

* Simulated Float Switch (SW1)
* Using a voltage-controlled switch and a pulse source to simulate a user/sensor triggering the switch
V_SW_CTRL SW_CTRL 0 PULSE(0 5 50u 1u 1u 200u 500u)
S1 VCC5 SENSE SW_CTRL 0 myswitch

* Base driving circuit
R1 SENSE VB 1k
R2 VB 0 10k

* Relay Driver Transistor
Q1 COIL_NEG VB 0 2N2222MOD

* Relay Coil (K1)
* ... (truncated in public view) ...

Copy this content into a .cir file and run with ngspice.

🔒 Part of this section is premium. With the 7-day pass or the monthly membership you can access the full content (materials, wiring, detailed build, validation, troubleshooting, variants and checklist) and download the complete print-ready PDF pack.

* Automatic Reservoir Pump Controller
.width out=256

* Power Supplies
V1 VCC12 0 DC 12
V2 VCC5 0 DC 5

* Simulated Float Switch (SW1)
* Using a voltage-controlled switch and a pulse source to simulate a user/sensor triggering the switch
V_SW_CTRL SW_CTRL 0 PULSE(0 5 50u 1u 1u 200u 500u)
S1 VCC5 SENSE SW_CTRL 0 myswitch

* Base driving circuit
R1 SENSE VB 1k
R2 VB 0 10k

* Relay Driver Transistor
Q1 COIL_NEG VB 0 2N2222MOD

* Relay Coil (K1)
* Modeled as a series resistor and inductor
R_K1 VCC12 K1_COIL_INT 400
L_K1 K1_COIL_INT COIL_NEG 10mH

* Flyback Diode
D1 COIL_NEG VCC12 1N4007MOD

* Relay Contacts (K1 NO)
* The switch closes when the voltage across the coil (VCC12 - COIL_NEG) exceeds 8V
S_RELAY VCC12 LOAD_SW VCC12 COIL_NEG relay_sw

* Simulated Pump Load
RLOAD LOAD_SW 0 50

* Status LED
R3 LOAD_SW D2_A 1k
D2 D2_A 0 DLED

* Models
.model myswitch SW(vt=2.5 vh=0.5 ron=0.1 roff=10MEG)
.model relay_sw SW(vt=8 vh=1 ron=0.05 roff=100MEG)
.model 2N2222MOD NPN(IS=1E-14 VAF=100 BF=200 IKF=0.3 XTB=1.5 BR=3 CJC=8E-12 CJE=25E-12 TR=100E-9 TF=400E-12 ITF=1 VTF=2 XTF=3 RB=10)
.model 1N4007MOD D(IS=7.02767n RS=0.0341512 N=1.80803 EG=1.11 XTI=3.0 BV=1000 IBV=5e-08 CJO=1e-11 VJ=0.7 M=0.5 FC=0.5 TT=1e-07)
.model DLED D(IS=1e-20 N=2.2 RS=2.5 BV=5 IBV=10u CJO=50p)

* Analysis Commands
.op
.tran 1u 500u
.print tran V(SENSE) V(LOAD_SW) V(COIL_NEG) V(VB) I(L_K1)

.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Analysis: The transient analysis spans 0 s to 500 us and captures the switching interval. The switching node and inductor current remain bounded, consistent with the flyback path protecting the switch. Main ranges: l_k1#branch -7.86 uA -> 29.9 mA; v(coil_neg) 9.89 mV -> 12.7 V; v(load_sw) 6 uV -> 12 V.
Show raw data table (961 rows)
Index   time            v(sense)        v(load_sw)      v(coil_neg)     v(vb)           l_k1#branch
0	0.000000e+00	5.494076e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.403801e-11
1	1.000000e-08	5.494076e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.403803e-11
2	2.000000e-08	5.494076e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.403801e-11
3	4.000000e-08	5.494076e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.403795e-11
4	8.000000e-08	5.494076e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.403772e-11
5	1.600000e-07	5.494076e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.403654e-11
6	3.200000e-07	5.494076e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.403033e-11
7	6.400000e-07	5.494076e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.400598e-11
8	1.280000e-06	5.494076e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.398528e-11
9	2.280000e-06	5.494076e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.403534e-11
10	3.280000e-06	5.494077e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.401174e-11
11	4.280000e-06	5.494076e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.394780e-11
12	5.280000e-06	5.494076e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.402136e-11
13	6.280000e-06	5.494077e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.408634e-11
14	7.280000e-06	5.494076e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.401469e-11
15	8.280000e-06	5.494076e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.399217e-11
16	9.280000e-06	5.494077e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.399919e-11
17	1.028000e-05	5.494076e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.393646e-11
18	1.128000e-05	5.494076e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.397704e-11
19	1.228000e-05	5.494077e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.408121e-11
20	1.328000e-05	5.494077e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.402567e-11
21	1.428000e-05	5.494076e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.395460e-11
22	1.528000e-05	5.494076e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.400449e-11
23	1.628000e-05	5.494077e-03	5.999997e-06	1.200000e+01	4.994626e-03	2.399821e-11
... (937 more rows) ...

Common mistakes and how to avoid them

  • Missing flyback diode (D1): When the relay turns off, the collapsing magnetic field in the coil generates a massive voltage spike. Without D1 to provide a safe discharge path, this spike will instantly destroy Q1. Always place D1 reverse-biased across the coil.
  • Insufficient base drive current: If R1 is too large, Q1 will operate in its linear region instead of fully saturating. This will cause the transistor to overheat and the relay may fail to actuate reliably. Always ensure R1 provides enough base current (Ib) for the required collector current (Ic).
  • Undersized relay contacts: Motors and pumps draw a massive «inrush» current when starting up. Using a relay rated exactly for the running current will cause the contacts to weld shut or burn. Always select a relay rated for at least 2-3 times the load’s continuous current.

Troubleshooting

  • Symptom: The relay chatters or buzzes rapidly instead of latching cleanly.
  • Cause: The 12 V power supply is too weak and drops voltage under the heavy load of the pump, causing the relay coil to lose holding power, disconnect the load, recover, and repeat.
  • Fix: Use a bench power supply with a higher current capacity or test with a battery.
  • Symptom: Transistor Q1 becomes extremely hot and fails.
  • Cause: Missing flyback diode, or the relay coil’s current demand exceeds the maximum collector current of the 2N2222.
  • Fix: Verify D1 is correctly installed. Check the relay coil resistance; ensure it draws less than 600 mA.
  • Symptom: Circuit turns on randomly without float switch action.
  • Cause: The base of Q1 is floating, picking up environmental electromagnetic interference.
  • Fix: Ensure the pull-down resistor R2 is securely connected between node VB and ground.
  • Symptom: The LED turns on, but the simulated pump (RLOAD) does not work.
  • Cause: Broken connection at the relay NO contact or a blown load resistor.
  • Fix: Check the wiring between the relay’s NO pin and LOAD_SW. Verify the resistance of RLOAD with a multimeter.

Possible improvements and extensions

  • Low-Water Cutoff (Latching Logic): Add a second float switch and configure the relay as a latching circuit. This ensures the pump runs continuously until the tank is completely full, rather than short-cycling.
  • Debounce Delay Network: Water ripples in a tank can cause the float switch to rapidly bounce on and off. Add an RC delay network (a capacitor and resistor) at the transistor base, or use a 555 timer, to introduce a turn-on/turn-off delay and protect the pump.

More Practical Cases on Prometeo.blog

Find this product and/or books on this topic on Amazon

Go to Amazon

As an Amazon Associate, I earn from qualifying purchases. If you buy through this link, you help keep this project running.

Quick Quiz

Question 1: What is the primary purpose of the circuit described in the text?




Question 2: What type of transistor is used to energize the electromechanical relay?




Question 3: Why is the use of an electromechanical relay important in this circuit?




Question 4: What happens to the transistor when the float switch is closed?




Question 5: Which relay contact closes when the relay coil is energized?




Question 6: What happens when the float switch is released?




Question 7: What component is used to trigger the NPN transistor?




Question 8: What happens to the status indicator LED when the pump is active?




Question 9: What is one of the benefits of this circuit in industrial and agricultural settings?




Question 10: How is the high-current DC pump simulated in this practical case?




Carlos Núñez Zorrilla
Carlos Núñez Zorrilla
Electronics & Computer Engineer

Telecommunications Electronics Engineer and Computer Engineer (official degrees in Spain).

Follow me:


Practical case: Overvoltage protection

Overvoltage protection prototype (Maker Style)

Level: Medium – Disconnect a critical load using a normally closed relay contact when a voltage threshold is exceeded.

Objective and use case

In this practical case, you will build a hardware-based overvoltage protection circuit. It uses a Zener diode to set a voltage threshold and a bipolar junction transistor (BJT) to actuate an electromechanical relay, mechanically disconnecting power when the voltage spikes to dangerous levels.

This topology is highly useful in real-world scenarios:
– Safeguarding sensitive 5 V microcontrollers from accidental power supply surges.
– Protecting expensive sensors or instruments in automotive environments where alternator spikes occur.
– Ensuring battery-powered or USB-powered devices mechanically cut out during a charger regulator failure.

Expected outcome:
– When the input voltage (v-in) is in the safe range (e.g., 5.0 V), the BJT remains off, the relay is unpowered, and the normally closed (NC) contact feeds power to the load.
– When v-in exceeds the Zener threshold plus the BJT base-emitter drop (around 6.3 V), the Zener conducts.
– Base current flows, the BJT switch turns on, and the relay coil energizes.
– The relay’s NC contact opens, triggering a v-load-disconnect event that drops the load voltage to 0 V.
– Target audience and level: Intermediate electronics students exploring analog voltage thresholds and electromechanical switching.

Materials

  • V1: Variable DC supply (0-9 V), function: provides system input voltage (v-in)
  • D1: 5.6 V Zener diode (e.g., 1N4734 A), function: sets the overvoltage threshold reference
  • R1: 1 kΩ resistor, function: base current limiting for the BJT
  • R2: 10 kΩ resistor, function: base pull-down to ensure the BJT turns off cleanly
  • Q1: 2N3904 NPN transistor, function: relay driver switch
  • D2: 1N4148 or 1N4007 diode, function: flyback protection for the relay coil
  • K1: 5 V SPDT Relay, function: disconnects the load using its normally closed (NC) contact
  • R_LOAD: 100 Ω resistor, function: simulated critical load

Wiring guide

  • V1: positive terminal connects to node V_IN, negative terminal connects to node 0 (GND).
  • D1: cathode connects to node V_IN, anode connects to node V_ZENER.
  • R1: connects between node V_ZENER and node BASE.
  • R2: connects between node BASE and node 0.
  • Q1: collector connects to node COLLECTOR, base connects to node BASE, emitter connects to node 0.
  • K1_COIL: the relay coil connects between node V_IN and node COLLECTOR.
  • D2: cathode connects to node V_IN, anode connects to node COLLECTOR (wired anti-parallel to the relay coil).
  • K1_COM: the relay’s common contact connects to node V_IN.
  • K1_NC: the relay’s normally closed contact connects to node LOAD_PWR.
  • R_LOAD: connects between node LOAD_PWR and node 0.

Conceptual block diagram

Conceptual block diagram — Overvoltage Protection
Quick read: inputs → main block → output (actuator or measurement). This summarizes the ASCII schematic below.

Schematic

POWER SOURCE:
[ V1: 0-9 V DC ] --(V_IN)--> System Power
[ V1: Negative ] ---------> GND

1. OVERVOLTAGE SENSING & CONTROL PATH:
V_IN --> [ D1: 5.6 V Zener ] --(V_ZENER)--> [ R1: 1 kΩ ] --(BASE)--> [ Q1:Base ]
                                                             |
                                                        [ R2: 10 kΩ ]
                                                             |
                                                            GND

2. RELAY COIL & DRIVER PATH:
V_IN --> [ K1_COIL || D2: Flyback(Rev) ] --(COLLECTOR)--> [ Q1:Collector ]
                       |                                        |
                (Magnetic Link)                            [ Q1:Emitter ]
                       |                                        |
                       v                                       GND

3. PROTECTED LOAD PATH:
V_IN --> [ K1_COM ] --(Normally Closed)--> [ K1_NC ] --(LOAD_PWR)--> [ R_LOAD: 100 Ω ] --> GND
Electrical Schematic

Electrical diagram

Electrical diagram for case: Overvoltage protection
Generated from the validated SPICE netlist for this case.

🔒 This electrical diagram is premium. With the 7-day pass or the monthly membership you can unlock the complete didactic material and the print-ready PDF pack.🔓 See premium access plans

Measurements and tests

  1. Set the variable power supply V1 to exactly 5.0 V.
  2. Measure v-in relative to ground. Verify it is 5.0 V.
  3. Measure the voltage across the load (LOAD_PWR to 0). It should read 5.0 V, indicating the relay is deactivated and the NC contact is closed.
  4. Slowly increase the voltage of V1. Monitor v-zener (the voltage at the anode of D1). It will remain near 0 V until v-in crosses the ~5.6 V breakdown threshold of the Zener diode.
  5. Push V1 up to 6.5 V. Observe that v-zener rises, pushing current into the base of Q1.
  6. Verify the v-load-disconnect event: listen for the relay click. Measure the voltage at LOAD_PWR; it should instantly drop to 0 V as the NC contact opens, successfully protecting the load.

SPICE netlist and simulation

Reference SPICE Netlist (ngspice) — excerptFull SPICE netlist (ngspice)

* Practical case: Overvoltage protection
.width out=256

* Input Voltage Source (Sweeps from 0V to normal 5V, then overvoltage 9V, then back)
V1 V_IN 0 PWL(0 0 1m 5 4m 5 5m 9 6m 9 7m 5 9m 5 10m 0)

* Zener Diode for threshold detection
D1 V_IN V_ZENER DZENER

* Base resistors for Q1
R1 V_ZENER BASE 1k
R2 BASE 0 10k

* Relay Driver Transistor
Q1 COLLECTOR BASE 0 2N3904

* Relay Coil (Modeled as series inductor and resistor)
L_K1_COIL V_IN K1_COIL_INT 10m
R_K1_COIL K1_COIL_INT COLLECTOR 100

* ... (truncated in public view) ...

Copy this content into a .cir file and run with ngspice.

🔒 Part of this section is premium. With the 7-day pass or the monthly membership you can access the full content (materials, wiring, detailed build, validation, troubleshooting, variants and checklist) and download the complete print-ready PDF pack.

* Practical case: Overvoltage protection
.width out=256

* Input Voltage Source (Sweeps from 0V to normal 5V, then overvoltage 9V, then back)
V1 V_IN 0 PWL(0 0 1m 5 4m 5 5m 9 6m 9 7m 5 9m 5 10m 0)

* Zener Diode for threshold detection
D1 V_IN V_ZENER DZENER

* Base resistors for Q1
R1 V_ZENER BASE 1k
R2 BASE 0 10k

* Relay Driver Transistor
Q1 COLLECTOR BASE 0 2N3904

* Relay Coil (Modeled as series inductor and resistor)
L_K1_COIL V_IN K1_COIL_INT 10m
R_K1_COIL K1_COIL_INT COLLECTOR 100

* Flyback Diode
D2 V_IN COLLECTOR D4148

* Relay Normally Closed (NC) Contact
* Modeled as a voltage-controlled switch controlled by the coil voltage (V_IN - COLLECTOR)
* When Q1 is OFF, coil voltage is 0V -> Switch is CLOSED (roff = 0.1)
* When Q1 is ON, coil voltage is > 6V -> Switch is OPEN (ron = 100meg)
S1 V_IN LOAD_PWR V_IN COLLECTOR RelayNC

* Critical Load
R_LOAD LOAD_PWR 0 100

* Models
.model DZENER D(IS=1e-15 RS=10 N=1 BV=5.6 IBV=5m)
.model D4148 D(IS=1e-14 RS=0.1 N=1)
.model 2N3904 NPN(IS=1E-14 VAF=100 BF=300 IKF=0.4 XTB=1.5 BR=4 CJC=4E-12 CJE=8E-12 RB=20 RC=0.1 RE=0.1 TR=250E-9 TF=350E-12 ITF=1 VTF=2 XTF=3)
.model RelayNC SW(vt=3 vh=0.5 ron=100meg roff=0.1)

* Simulation Directives
.print tran V(V_IN) V(LOAD_PWR) V(BASE) V(COLLECTOR) V(V_ZENER) I(L_K1_COIL)
.tran 10u 10m
.op
.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Analysis: The simulation sweeps the input voltage from 0V to 5V, then up to 9V (overvoltage), and back down. The ngspice results show that when V_IN reaches 9V, the Zener diode conducts, raising V(BASE) to ~1.07V, which turns on Q1. This energizes the relay coil (current reaches ~9mA), opening the NC contact and disconnecting the load (V(LOAD_PWR) drops or follows the switch logic).
Show raw data table (1788 rows)
Index   time            v(v_in)         v(load_pwr)     v(base)         v(collector)    v(v_zener)      l_k1_coil#branc
0	0.000000e+00	0.000000e+00	0.000000e+00	4.369907e-29	1.104363e-28	4.276684e-29	-1.10436e-30
1	1.000000e-07	5.000000e-04	4.995005e-04	2.124049e-05	1.169502e-04	2.124049e-05	3.826672e-09
2	1.128896e-07	5.644481e-04	5.638843e-04	2.436647e-05	1.341994e-04	2.436647e-05	4.380682e-09
3	1.386689e-07	6.933444e-04	6.926518e-04	3.144704e-05	1.734710e-04	3.144704e-05	5.604067e-09
4	1.902274e-07	9.511370e-04	9.501868e-04	5.084817e-05	2.848367e-04	5.084817e-05	8.658258e-09
5	2.933444e-07	1.466722e-03	1.465257e-03	1.084331e-04	6.633002e-04	1.084332e-04	1.622310e-08
6	4.910392e-07	2.455196e-03	2.452743e-03	2.404937e-04	1.923047e-03	2.404937e-04	2.937980e-08
7	6.875077e-07	3.437539e-03	3.434104e-03	3.216141e-04	3.548938e-03	3.216141e-04	3.345128e-08
8	9.631281e-07	4.815640e-03	4.810829e-03	2.723800e-04	5.450903e-03	2.723800e-04	2.308361e-08
9	1.154824e-06	5.774121e-03	5.768352e-03	1.710095e-04	6.210657e-03	1.710095e-04	1.277625e-08
10	1.305686e-06	6.528429e-03	6.521907e-03	1.116498e-04	6.566319e-03	1.116498e-04	9.181046e-09
11	1.495573e-06	7.477865e-03	7.470395e-03	1.085076e-04	7.080935e-03	1.085076e-04	1.256925e-08
12	1.736950e-06	8.684750e-03	8.676074e-03	1.904626e-04	8.232826e-03	1.904626e-04	2.277129e-08
13	2.001986e-06	1.000993e-02	9.999931e-03	2.728041e-04	1.002166e-02	2.728041e-04	2.853663e-08
14	2.256607e-06	1.128304e-02	1.127176e-02	2.568832e-04	1.166727e-02	2.568832e-04	2.342944e-08
15	2.500031e-06	1.250016e-02	1.248767e-02	1.808629e-04	1.277687e-02	1.808630e-04	1.533781e-08
16	2.702903e-06	1.351451e-02	1.350101e-02	1.375223e-04	1.345800e-02	1.375223e-04	1.307538e-08
17	2.944974e-06	1.472487e-02	1.471016e-02	1.562745e-04	1.440894e-02	1.562745e-04	1.754621e-08
18	3.189115e-06	1.594558e-02	1.592965e-02	2.174467e-04	1.574153e-02	2.174467e-04	2.384313e-08
19	3.483820e-06	1.741910e-02	1.740170e-02	2.492948e-04	1.756940e-02	2.492949e-04	2.456373e-08
20	3.789826e-06	1.894913e-02	1.893020e-02	2.050542e-04	1.918736e-02	2.050543e-04	1.855307e-08
21	4.028198e-06	2.014099e-02	2.012087e-02	1.627875e-04	2.016491e-02	1.627876e-04	1.538812e-08
22	4.364653e-06	2.182326e-02	2.180146e-02	1.717346e-04	2.161154e-02	1.717346e-04	1.849039e-08
23	4.749559e-06	2.374779e-02	2.372407e-02	2.249970e-04	2.370014e-02	2.249971e-04	2.340138e-08
... (1764 more rows) ...

Common mistakes and how to avoid them

  • Omitting the flyback diode (D2): Failing to place a diode across the relay coil will result in a massive inductive voltage spike when the transistor turns off, permanently destroying the BJT. Always include the anti-parallel diode.
  • Installing the Zener diode backward: If the Zener is installed forward-biased (anode to V_IN), it will act like a standard diode with a 0.7 V drop. The relay will trigger almost immediately. Ensure the cathode faces the positive input.
  • Wiring the load to the NO contact: If you accidentally connect R_LOAD to the Normally Open (NO) terminal instead of the NC terminal, the load will only receive power during an overvoltage event, which defeats the purpose of the protection circuit.

Troubleshooting

  • Symptom: The relay chatters rapidly or buzzes when the input voltage is right at the threshold (e.g., 6.2 V).
  • Cause: The circuit lacks hysteresis. A slow-moving analog voltage at the exact threshold causes the BJT to partially turn on, putting the relay in an undefined mechanical state.
  • Fix: In a practical setup, overvoltage events are usually fast spikes. For slow-rising voltages, a Schmitt trigger or a latching circuit is required to ensure a clean transition.
  • Symptom: The load never powers on, even at 5.0 V.
  • Cause: The relay might be stuck energized, the BJT is shorted, or the load was mistakenly wired to the NO contact.
  • Fix: Check LOAD_PWR continuity to V_IN while the circuit is unpowered. Replace Q1 if it reads a dead short from collector to emitter.
  • Symptom: The transistor gets exceptionally hot during an overvoltage event.
  • Cause: The input voltage was raised far beyond the threshold (e.g., 12 V into a 5 V relay), causing excessive coil current through the BJT.
  • Fix: Do not exceed the absolute maximum ratings of the relay coil and the 2N3904 transistor. If higher voltages are expected, use a beefier transistor (like a TIP120) or a pre-regulator.

Possible improvements and extensions

  • Add a fault indicator: Connect a red LED with an appropriate current-limiting resistor to the Normally Open (NO) contact. When the overvoltage triggers, the load loses power, and the red LED instantly illuminates to warn the user.
  • Implement a mechanical latch: Wire a secondary contact of the relay (if using a DPDT relay) or an SCR in the base circuit so that once an overvoltage event triggers the relay, it stays locked in the «disconnect» state until the user manually presses a reset button, preventing repeated power cycling.

More Practical Cases on Prometeo.blog

Find this product and/or books on this topic on Amazon

Go to Amazon

As an Amazon Associate, I earn from qualifying purchases. If you buy through this link, you help keep this project running.

Quick Quiz

Question 1: What is the primary objective of the circuit described in the article?




Question 2: Which component is primarily used to set the overvoltage threshold reference?




Question 3: What happens to the relay when the input voltage is in the safe range (e.g., 5.0 V)?




Question 4: At approximately what input voltage does the circuit trigger the overvoltage protection?




Question 5: What happens when the input voltage exceeds the Zener threshold plus the BJT base-emitter drop?




Question 6: How does the load lose power during an overvoltage event?




Question 7: Which of the following is a mentioned use case for this topology?




Question 8: What type of transistor is used to actuate the electromechanical relay?




Question 9: What is the state of the BJT when the input voltage is in the safe range?




Question 10: What is the difficulty level of this practical case as stated in the text?




Carlos Núñez Zorrilla
Carlos Núñez Zorrilla
Electronics & Computer Engineer

Telecommunications Electronics Engineer and Computer Engineer (official degrees in Spain).

Follow me:


Practical case: AND and OR logic using relays

AND and OR logic using relays prototype (Maker Style)

Level: Medium – Build basic logic gates by wiring the contacts of multiple relays in series and parallel.

Objective and use case

  • What you will build: A circuit that utilizes two DPDT (Double Pole Double Throw) electro-mechanical relays to simultaneously demonstrate basic Boolean logic operations (AND and OR gates).
  • Why it is useful:
    • Forms the historical foundation of industrial automation and ladder logic programming.
    • Demonstrates how to handle logic for high-voltage or high-current systems where standard silicon ICs are unsuitable.
    • Provides complete electrical isolation between the control inputs (coils) and the logic outputs (contacts).
    • Illustrates the fundamental fail-safe interlock principles used in heavy machinery and safety circuits.
  • Expected outcome:
    • The AND output (Green LED) will only illuminate when both relay coils are energized (series contacts).
    • The OR output (Red LED) will illuminate when either relay coil is energized (parallel contacts).
    • Successful measurement of control voltages confirming the activation of specific logic paths.
  • Target audience and level: Intermediate electronics students exploring automated control systems and electromechanical switching.

Materials

  • V1: 5 V DC supply, function: power for coils and logic
  • SW1: SPST switch, function: Input A control
  • SW2: SPST switch, function: Input B control
  • K1: 5 V DPDT relay, function: Logic gate element A
  • K2: 5 V DPDT relay, function: Logic gate element B
  • D1: Green LED, function: AND logic output indicator
  • D2: Red LED, function: OR logic output indicator
  • D3: 1N4148 diode, function: K1 flyback protection
  • D4: 1N4148 diode, function: K2 flyback protection
  • R1: 330 Ω resistor, function: D1 current limiting
  • R2: 330 Ω resistor, function: D2 current limiting

Wiring guide

  • V1 connects between VCC and 0.
  • SW1 connects between VCC and node VA.
  • SW2 connects between VCC and node VB.
  • K1 coil connects between node VA and 0.
  • K2 coil connects between node VB and 0.
  • D3 cathode connects to node VA, anode connects to 0 (anti-parallel to K1 coil).
  • D4 cathode connects to node VB, anode connects to 0 (anti-parallel to K2 coil).
  • AND Logic (Series Wiring – Pole 1):
    • K1 Pole 1 Common contact connects to VCC.
    • K1 Pole 1 Normally Open (NO) contact connects to node AND_MID.
    • K2 Pole 1 Common contact connects to node AND_MID.
    • K2 Pole 1 Normally Open (NO) contact connects to node OUT_AND.
  • OR Logic (Parallel Wiring – Pole 2):
    • K1 Pole 2 Common contact connects to VCC.
    • K1 Pole 2 Normally Open (NO) contact connects to node OUT_OR.
    • K2 Pole 2 Common contact connects to VCC.
    • K2 Pole 2 Normally Open (NO) contact connects to node OUT_OR.
  • Outputs:
    • R1 connects between OUT_AND and node D1_ANODE.
    • D1 connects between D1_ANODE and 0 (cathode to ground).
    • R2 connects between OUT_OR and node D2_ANODE.
    • D2 connects between D2_ANODE and 0 (cathode to ground).

Conceptual block diagram

Conceptual block diagram — Relay AND/OR Logic
Quick read: inputs → main block → output (actuator or measurement). This summarizes the ASCII schematic below.

Schematic

[ CONTROL SECTION: RELAY COILS ]

VCC --> [ SW1 (Input A) ] --(VA)--> [ K1 Coil || D3(Rev) ] --> GND
                                          |
                                   (Magnetic Link)
                                          v
                                    (To K1 Poles)

VCC --> [ SW2 (Input B) ] --(VB)--> [ K2 Coil || D4(Rev) ] --> GND
                                          |
                                   (Magnetic Link)
                                          v
                                    (To K2 Poles)


[ AND LOGIC SECTION: SERIES WIRING (POLE 1) ]

VCC --> [ K1 Pole 1 (NO) ] --(AND_MID)--> [ K2 Pole 1 (NO) ] --(OUT_AND)--> [ R1 ] --(D1_ANODE)--> [ D1 (Green LED) ] --> GND


[ OR LOGIC SECTION: PARALLEL WIRING (POLE 2) ]

VCC --> [ K1 Pole 2 (NO) ] --(OUT_OR)--+
                                       |--> [ R2 ] --(D2_ANODE)--> [ D2 (Red LED) ] --> GND
VCC --> [ K2 Pole 2 (NO) ] --(OUT_OR)--+
Electrical Schematic

Electrical diagram

Electrical diagram for case: AND and OR logic using relays
Generated from the validated SPICE netlist for this case.

🔒 This electrical diagram is premium. With the 7-day pass or the monthly membership you can unlock the complete didactic material and the print-ready PDF pack.🔓 See premium access plans

Truth table

Switch A (VA) Switch B (VB) K1 State K2 State AND Output (Green LED) OR Output (Red LED)
OFF (0 V) OFF (0 V) Resting Resting OFF (0 V) OFF (0 V)
OFF (0 V) ON (5 V) Resting Energized OFF (0 V) ON (~5 V)
ON (5 V) OFF (0 V) Energized Resting OFF (0 V) ON (~5 V)
ON (5 V) ON (5 V) Energized Energized ON (~5 V) ON (~5 V)

Measurements and tests

  1. Input Verification: Power on V1. Using a multimeter, measure the voltage at nodes VA and VB with respect to 0 (GND). Ensure it reads 0 V when the corresponding switch is open, and 5 V when closed.
  2. Mechanical Operation: Toggle SW1 and SW2 individually. You should hear a distinct mechanical «click» from K1 and K2, confirming coil activation.
  3. OR Gate Testing: Close SW1 only. Measure the voltage at OUT_OR (should be ~5 V) and ensure the Red LED lights up. Repeat this step for SW2 only.
  4. AND Gate Testing: Ensure both SW1 and SW2 are closed. Measure the voltage at OUT_AND (should be ~5 V) and confirm the Green LED lights up. If either switch is opened, the Green LED must turn off.

SPICE netlist and simulation

Reference SPICE Netlist (ngspice) — excerptFull SPICE netlist (ngspice)

* Practical case: AND and OR logic using relays
.width out=256

* Power Supply
V1 VCC 0 DC 5

* Input A Control (SW1)
* Modeled as a voltage-controlled switch toggled by a fast pulse source to simulate user input
S_SW1 VCC VA ctrl_A 0 switch_mod
V_ctrl_A ctrl_A 0 PULSE(0 5 0 1u 1u 100u 200u)

* Input B Control (SW2)
* Modeled as a voltage-controlled switch toggled by a fast pulse source
S_SW2 VCC VB ctrl_B 0 switch_mod
V_ctrl_B ctrl_B 0 PULSE(0 5 0 1u 1u 200u 400u)

* Relay K1 Coil and Flyback Diode
* Coil modeled as an RL series circuit
L_K1 VA K1_mid 1m
R_K1 K1_mid 0 100
* ... (truncated in public view) ...

Copy this content into a .cir file and run with ngspice.

🔒 Part of this section is premium. With the 7-day pass or the monthly membership you can access the full content (materials, wiring, detailed build, validation, troubleshooting, variants and checklist) and download the complete print-ready PDF pack.

* Practical case: AND and OR logic using relays
.width out=256

* Power Supply
V1 VCC 0 DC 5

* Input A Control (SW1)
* Modeled as a voltage-controlled switch toggled by a fast pulse source to simulate user input
S_SW1 VCC VA ctrl_A 0 switch_mod
V_ctrl_A ctrl_A 0 PULSE(0 5 0 1u 1u 100u 200u)

* Input B Control (SW2)
* Modeled as a voltage-controlled switch toggled by a fast pulse source
S_SW2 VCC VB ctrl_B 0 switch_mod
V_ctrl_B ctrl_B 0 PULSE(0 5 0 1u 1u 200u 400u)

* Relay K1 Coil and Flyback Diode
* Coil modeled as an RL series circuit
L_K1 VA K1_mid 1m
R_K1 K1_mid 0 100
D3 0 VA 1N4148

* Relay K2 Coil and Flyback Diode
L_K2 VB K2_mid 1m
R_K2 K2_mid 0 100
D4 0 VB 1N4148

* AND Logic (Series Wiring - Pole 1)
S_K1_P1 VCC AND_MID VA 0 relay_switch
S_K2_P1 AND_MID OUT_AND VB 0 relay_switch
* Anti-floating leak resistor for the midpoint of the series connection
R_leak AND_MID 0 1G 

* OR Logic (Parallel Wiring - Pole 2)
S_K1_P2 VCC OUT_OR VA 0 relay_switch
S_K2_P2 VCC OUT_OR VB 0 relay_switch

* Outputs
R1 OUT_AND D1_ANODE 330
D1 D1_ANODE 0 DLED_Green

R2 OUT_OR D2_ANODE 330
D2 D2_ANODE 0 DLED_Red

* Models
.model switch_mod SW(vt=2.5 vh=0.5 ron=0.1 roff=100MEG)
.model relay_switch SW(vt=2.5 vh=0.5 ron=0.1 roff=100MEG)
.model 1N4148 D(IS=2.682n N=1.836 RS=0.5623 BV=100 IBV=100p CJO=4p M=0.333 VJ=0.5 TT=11.54n)
.model DLED_Green D(IS=1e-20 N=2.2 RS=5)
.model DLED_Red D(IS=1e-15 N=2.0 RS=5)

* Analysis
.tran 1u 500u
.print tran V(VA) V(VB) V(OUT_AND) V(OUT_OR) V(AND_MID) I(L_K1)
.op
.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Analysis: The simulation results match the expected truth table for AND and OR logic. When both inputs are 5V, both outputs are near 5V. When only one input is 5V, only the OR output goes to 5V. The OFF state voltages are non-zero (around 1.6V and 0.9V) due to the finite off-resistance of the switch models, but these are below the LED forward voltages.
Show raw data table (5166 rows)
Index   time            v(va)           v(vb)           v(out_and)      v(out_or)       v(and_mid)      l_k1#branch
0	0.000000e+00	4.999967e-06	4.999967e-06	1.597015e+00	9.421253e-01	3.141436e+00	4.999967e-08
1	1.000000e-08	4.999967e-06	4.999967e-06	1.597015e+00	9.421253e-01	3.141436e+00	4.999967e-08
2	2.000000e-08	4.999967e-06	4.999967e-06	1.597015e+00	9.421253e-01	3.141436e+00	4.999967e-08
3	4.000000e-08	4.999967e-06	4.999967e-06	1.597015e+00	9.421253e-01	3.141436e+00	4.999967e-08
4	8.000000e-08	4.999967e-06	4.999967e-06	1.597015e+00	9.421253e-01	3.141436e+00	4.999967e-08
5	1.600000e-07	4.999967e-06	4.999967e-06	1.597015e+00	9.421253e-01	3.141436e+00	4.999967e-08
6	3.200000e-07	4.999967e-06	4.999967e-06	1.597015e+00	9.421253e-01	3.141436e+00	4.999967e-08
7	3.750000e-07	4.999967e-06	4.999967e-06	1.597015e+00	9.421253e-01	3.141436e+00	4.999967e-08
8	4.712500e-07	4.999967e-06	4.999967e-06	1.597015e+00	9.421253e-01	3.141436e+00	4.999967e-08
9	4.978906e-07	4.999967e-06	4.999967e-06	1.597015e+00	9.421253e-01	3.141436e+00	4.999967e-08
10	5.445117e-07	4.999967e-06	4.999967e-06	1.597015e+00	9.421253e-01	3.141436e+00	4.999967e-08
11	5.574158e-07	4.999967e-06	4.999967e-06	1.597015e+00	9.421253e-01	3.141436e+00	4.999967e-08
12	5.799979e-07	4.999967e-06	4.999967e-06	1.597015e+00	9.421253e-01	3.141436e+00	4.999967e-08
13	6.019875e-07	4.999887e+00	4.999887e+00	4.998416e+00	4.999485e+00	4.999208e+00	5.496234e-05
14	6.174611e-07	5.000094e+00	5.000094e+00	4.998416e+00	4.999485e+00	4.999208e+00	1.321856e-04
15	6.317917e-07	4.999872e+00	4.999872e+00	4.998416e+00	4.999485e+00	4.999208e+00	2.035976e-04
16	6.498539e-07	5.000078e+00	5.000078e+00	4.998416e+00	4.999485e+00	4.999208e+00	2.934595e-04
17	6.859784e-07	4.999845e+00	4.999845e+00	4.998416e+00	4.999485e+00	4.999208e+00	4.726966e-04
18	7.582273e-07	5.000025e+00	5.000025e+00	4.998416e+00	4.999485e+00	4.999208e+00	8.292335e-04
19	9.027252e-07	4.999739e+00	4.999739e+00	4.998416e+00	4.999485e+00	4.999208e+00	1.534627e-03
20	1.000000e-06	4.999907e+00	4.999907e+00	4.998416e+00	4.999485e+00	4.999208e+00	2.003774e-03
21	1.028900e-06	4.999786e+00	4.999786e+00	4.998416e+00	4.999485e+00	4.999208e+00	2.142075e-03
22	1.086699e-06	4.999758e+00	4.999758e+00	4.998416e+00	4.999485e+00	4.999208e+00	2.417880e-03
23	1.202297e-06	4.999704e+00	4.999704e+00	4.998416e+00	4.999485e+00	4.999208e+00	2.964729e-03
... (5142 more rows) ...

Common mistakes and how to avoid them

  • Omitting flyback diodes: Failing to include D3 and D4 can cause high voltage spikes when the switches are opened, which can damage the switches or surrounding sensitive electronics. Always wire them in reverse-bias across the coils.
  • Confusing NO and NC contacts: Accidentally wiring to the Normally Closed (NC) pin instead of the Normally Open (NO) pin will invert the logic, effectively creating NAND/NOR conditions instead of AND/OR. Double-check your relay’s datasheet or pinout.
  • Insufficient power supply current: Relays consume significantly more current than digital ICs (often 50–100 mA per coil). Ensure your 5 V supply can comfortably deliver at least 300 mA to prevent voltage dips when both relays are energized.

Troubleshooting

  • Symptom: Neither LED lights up under any switch combination, and no «clicks» are heard.
    • Cause: Power supply V1 is disconnected, dead, or current-limited.
    • Fix: Verify VCC and 0 connections to the main supply and check the supply limits.
  • Symptom: Relays click when switches are pressed, but LEDs never turn on.
    • Cause: The control side (coils) is working, but the logic side (contacts) is unpowered.
    • Fix: Verify that VCC is properly routed to the Common pins of both poles on K1 and K2.
  • Symptom: Power supply resets or dips severely when a switch is pressed.
    • Cause: A flyback diode (D3 or D4) is installed backward, creating a direct short circuit to ground when the switch closes.
    • Fix: Check diode orientation; the cathode (striped side) must face the positive incoming voltage (VA or VB).
  • Symptom: The AND logic acts like an OR logic.
    • Cause: The contacts for the AND gate were wired in parallel instead of series.
    • Fix: Inspect the node AND_MID. VCC should strictly flow through K1 into K2, not directly to both.

Possible improvements and extensions

  • Implement a NOT Gate (Inverter): Add a third relay or utilize an unused pole. Route VCC through its Normally Closed (NC) contact so that the output turns OFF when the relay is energized.
  • Build an XOR (Exclusive OR) Circuit: Using both poles of two SPDT/DPDT relays, wire the NO contact of K1 to the NC contact of K2, and the NC contact of K1 to the NO contact of K2. This implements a 2-way lighting circuit logic using relays.

More Practical Cases on Prometeo.blog

Find this product and/or books on this topic on Amazon

Go to Amazon

As an Amazon Associate, I earn from qualifying purchases. If you buy through this link, you help keep this project running.

Quick Quiz

Question 1: What is the primary objective of the circuit described in the article?




Question 2: How are the relay contacts wired to create an AND logic gate?




Question 3: Which component is used to indicate the output of the OR logic gate?




Question 4: What type of relays are used as logic gate elements in this circuit?




Question 5: Why is using relays for logic useful in certain industrial applications?




Question 6: What does the circuit provide between the control inputs and the logic outputs?




Question 7: Under what condition will the Green LED (AND output) illuminate?




Question 8: What forms the historical foundation of industrial automation according to the text?




Question 9: How are the relay contacts wired to form an OR gate?




Question 10: What fundamental principle used in heavy machinery and safety circuits does this project illustrate?




Carlos Núñez Zorrilla
Carlos Núñez Zorrilla
Electronics & Computer Engineer

Telecommunications Electronics Engineer and Computer Engineer (official degrees in Spain).

Follow me:


Practical case: Automatic power switching

Automatic power switching prototype (Maker Style)

Level: Medium – Implement an SPDT relay to automatically alternate between a main power supply and a backup battery.

Objective and use case

In this practical case, you will build a power management circuit using a Single Pole Double Throw (SPDT) relay. The circuit will automatically switch a connected load to a backup battery whenever the main power supply fails.

This automated switching topology is highly useful in several real-world applications:
* Uninterruptible Power Supplies (UPS) for routers and critical network equipment.
* Alarm and security systems that require continuous operation during grid power outages.
* Medical monitoring devices that must remain functional during patient transport.
* Solar power systems that automatically switch to battery power after sunset.

Expected outcome:
* When the main supply (V_MAIN) is active, the relay coil energizes, and the load connects to the Normally Open (NO) contact powered by the main supply.
* When the main supply fails (drops to 0 V), the relay de-energizes, seamlessly transferring the load to the Normally Closed (NC) contact powered by the backup battery.
* The load voltage (V_LOAD_OUT) remains continuous, save for a minor mechanical switching delay.
* A visual LED indicator successfully reports the presence of the main power supply.

Target audience: Hobbyists and intermediate electronics students learning about electromechanical relays and power redundancy.

Materials

  • V1: 12 V DC supply, function: main power source
  • V2: 9 V DC supply, function: backup battery source
  • K1: 12 V SPDT relay, function: automatic power switch
  • D1: 1N4007 diode, function: flyback diode to protect against relay coil voltage spikes
  • D2: Red LED, function: main power indicator
  • R1: 1 kΩ resistor, function: LED current limiting
  • R2: 100 Ω resistor, function: simulated system load

Wiring guide

  • V1: Connect positive terminal to V_MAIN and negative terminal to 0 (GND).
  • V2: Connect positive terminal to V_BACKUP and negative terminal to 0 (GND).
  • K1 (Coil): Connect one side to V_MAIN and the other side to 0 (GND).
  • D1: Connect parallel to the K1 coil. Connect the cathode to V_MAIN and the anode to 0 (GND).
  • K1 (NO Contact): Connect the Normally Open terminal to V_MAIN.
  • K1 (NC Contact): Connect the Normally Closed terminal to V_BACKUP.
  • K1 (COM Contact): Connect the Common terminal to V_LOAD_OUT.
  • R2: Connect between V_LOAD_OUT and 0 (GND).
  • R1: Connect between V_MAIN and NODE_LED.
  • D2: Connect the anode to NODE_LED and the cathode to 0 (GND).

Conceptual block diagram

Conceptual block diagram — Relay Power Switch
Quick read: inputs → main block → output (actuator or measurement). This summarizes the ASCII schematic below.

Schematic

[ V1: 12 V Main ] --(V_MAIN)--> [ K1 Coil || D1 (Rev) ] --> GND
                                       |
                                 (Magnetic Link)
                                       v
[ V1: 12 V Main ] --(V_MAIN)--> [ K1: NO Contact ] --+
                                                    |
                                                  (COM)--> [ V_LOAD_OUT ] --> [ R2: 100 Ω Load ] --> GND
                                                    |
[ V2: 9 V Backup ] -(V_BACKUP)-> [ K1: NC Contact ] -+

[ V1: 12 V Main ] --(V_MAIN)--> [ R1: 1 kΩ ] --(NODE_LED)--> [ D2: Red LED ] --> GND
Electrical Schematic

Electrical diagram

Electrical diagram for case: Automatic power switching
Generated from the validated SPICE netlist for this case.

🔒 This electrical diagram is premium. With the 7-day pass or the monthly membership you can unlock the complete didactic material and the print-ready PDF pack.🔓 See premium access plans

Measurements and tests

  1. Connect and activate both V1 (12 V) and V2 (9 V).
  2. Measure the voltage at V_MAIN and V_BACKUP with a multimeter to verify both sources are stable.
  3. Measure the voltage at V_LOAD_OUT. It should read approximately 12 V. The relay should emit an audible «click» upon power-up, and the indicator LED (D2) should be brightly lit.
  4. Disconnect V1 to simulate a power outage (V_MAIN drops to 0 V).
  5. Measure the voltage at V_LOAD_OUT again. It should now read approximately 9 V, confirming the load has successfully transferred to the backup battery. The LED should turn off.
  6. Reconnect V1. Observe the relay clicking again as V_LOAD_OUT returns to 12 V.

SPICE netlist and simulation

Reference SPICE Netlist (ngspice) — excerptFull SPICE netlist (ngspice)

* Automatic power switching
.width out=256

* Power Sources
V1 V_MAIN 0 PULSE(12 0 200u 1u 1u 200u 500u)
V2 V_BACKUP 0 DC 9

* K1 Relay Coil (modeled as series inductor and resistor)
L_K1 V_MAIN K1_COIL_INT 1m
R_K1 K1_COIL_INT 0 400

* K1 Relay Contacts (modeled as voltage-controlled switches)
* Normally Open (NO) contact between V_MAIN and V_LOAD_OUT, controlled by V_MAIN
S_K1_NO V_MAIN V_LOAD_OUT V_MAIN 0 Relay_NO
* Normally Closed (NC) contact between V_BACKUP and V_LOAD_OUT, controlled by inverted V_MAIN
S_K1_NC V_BACKUP V_LOAD_OUT 0 V_MAIN Relay_NC

* D1 Flyback Diode (Anode to 0, Cathode to V_MAIN)
D1 0 V_MAIN 1N4007

* ... (truncated in public view) ...

Copy this content into a .cir file and run with ngspice.

🔒 Part of this section is premium. With the 7-day pass or the monthly membership you can access the full content (materials, wiring, detailed build, validation, troubleshooting, variants and checklist) and download the complete print-ready PDF pack.

* Automatic power switching
.width out=256

* Power Sources
V1 V_MAIN 0 PULSE(12 0 200u 1u 1u 200u 500u)
V2 V_BACKUP 0 DC 9

* K1 Relay Coil (modeled as series inductor and resistor)
L_K1 V_MAIN K1_COIL_INT 1m
R_K1 K1_COIL_INT 0 400

* K1 Relay Contacts (modeled as voltage-controlled switches)
* Normally Open (NO) contact between V_MAIN and V_LOAD_OUT, controlled by V_MAIN
S_K1_NO V_MAIN V_LOAD_OUT V_MAIN 0 Relay_NO
* Normally Closed (NC) contact between V_BACKUP and V_LOAD_OUT, controlled by inverted V_MAIN
S_K1_NC V_BACKUP V_LOAD_OUT 0 V_MAIN Relay_NC

* D1 Flyback Diode (Anode to 0, Cathode to V_MAIN)
D1 0 V_MAIN 1N4007

* Main Power Indicator
R1 V_MAIN NODE_LED 1k
D2 NODE_LED 0 DLED

* Simulated System Load
R2 V_LOAD_OUT 0 100

* Component Models
.model 1N4007 D(IS=7.02767n RS=0.0341512 N=1.80803 EG=1.05743 XTI=5 BV=1000 IBV=5e-08 CJO=1e-11 VJ=0.7 M=0.5 FC=0.5 TT=1e-07)
.model DLED D(IS=1e-15 RS=10 N=2.0)
.model Relay_NO SW(vt=6 vh=0.5 ron=0.05 roff=10Meg)
.model Relay_NC SW(vt=-6 vh=0.5 ron=0.05 roff=10Meg)

* Analysis Directives
.op
.tran 1u 500u
.print tran V(V_MAIN) V(V_LOAD_OUT) V(V_BACKUP) V(NODE_LED) I(L_K1)

.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Analysis: The simulation shows V_MAIN starting at 12V, during which V_LOAD_OUT is approximately 12V. At t=200us, V_MAIN drops to 0V, and V_LOAD_OUT seamlessly switches to the 9V backup supply. When V_MAIN recovers at t=400us, V_LOAD_OUT returns to 12V.
Show raw data table (557 rows)
Index   time            v(v_main)       v(v_load_out)   v(v_backup)     v(node_led)     l_k1#branch
0	0.000000e+00	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
1	1.000000e-08	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
2	2.000000e-08	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
3	4.000000e-08	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
4	8.000000e-08	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
5	1.600000e-07	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
6	3.200000e-07	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
7	6.400000e-07	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
8	1.280000e-06	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
9	2.280000e-06	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
10	3.280000e-06	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
11	4.280000e-06	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
12	5.280000e-06	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
13	6.280000e-06	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
14	7.280000e-06	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
15	8.280000e-06	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
16	9.280000e-06	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
17	1.028000e-05	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
18	1.128000e-05	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
19	1.228000e-05	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
20	1.328000e-05	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
21	1.428000e-05	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
22	1.528000e-05	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
23	1.628000e-05	1.200000e+01	1.199400e+01	9.000000e+00	1.653685e+00	3.000000e-02
... (533 more rows) ...

Common mistakes and how to avoid them

  • Relay coil voltage mismatch: Using a 5 V relay on a 12 V line will cause the coil to overheat and fail quickly. Always ensure the relay’s rated coil voltage matches the main supply voltage exactly.
  • Omitting the flyback diode: Failing to install the reverse-biased diode across the relay coil can result in high-voltage spikes when the main power is abruptly disconnected, potentially damaging parallel components on the main power bus.
  • Reversing NO and NC contacts: Wiring the backup battery to the NO contact and the main supply to the NC contact will result in a dead system when the main power fails. Verify the relay pinout before soldering or powering the circuit.

Troubleshooting

  • Symptom: The load completely loses power when the main supply drops.
    • Cause: The backup battery is either dead or connected to the Normally Open (NO) terminal instead of the Normally Closed (NC) terminal.
    • Fix: Measure the battery voltage independently, then verify its connection to the NC terminal of the relay.
  • Symptom: The relay chatters or buzzes continuously instead of switching cleanly.
    • Cause: The main power supply cannot provide enough current for both the relay coil and the load, causing the voltage to repeatedly dip below the relay’s hold threshold.
    • Fix: Upgrade the main power supply to a higher current rating, or add a large smoothing capacitor across the V_MAIN line.
  • Symptom: The indicator LED does not light up, but the switching works.
    • Cause: The LED is inserted with reverse polarity, or the current limiting resistor is disconnected.
    • Fix: Verify that the flat side (cathode) of the LED is connected to ground.

Possible improvements and extensions

  • Add a large electrolytic capacitor (e.g., 1000 µF) in parallel with the load (R2) to smooth out the brief power interruption (brownout) caused by the mechanical switching time of the relay contacts.
  • Replace the mechanical relay with a solid-state diode OR-ing circuit (using Schottky diodes) for completely seamless, zero-delay switching without any moving parts.

More Practical Cases on Prometeo.blog

Find this product and/or books on this topic on Amazon

Go to Amazon

As an Amazon Associate, I earn from qualifying purchases. If you buy through this link, you help keep this project running.

Quick Quiz

Question 1: What is the primary function of the SPDT relay in this circuit?




Question 2: What does SPDT stand for in the context of relays?




Question 3: Which contact does the load connect to when the main supply (V_MAIN) is active?




Question 4: What happens to the relay coil when the main power supply fails?




Question 5: Which contact is powered by the backup battery in this circuit?




Question 6: Which of the following is a real-world application for this automated switching topology?




Question 7: What is the expected behavior of the load voltage (V_LOAD_OUT) during the switch?




Question 8: Why is this circuit useful for alarm and security systems?




Question 9: In a solar power system using this topology, when does the system automatically switch to battery power?




Question 10: What triggers the relay to switch the load back to the main power supply?




Carlos Núñez Zorrilla
Carlos Núñez Zorrilla
Electronics & Computer Engineer

Telecommunications Electronics Engineer and Computer Engineer (official degrees in Spain).

Follow me:


Practical case: High power circuit isolation

High power circuit isolation prototype (Maker Style)

Level: Basic – Control a high-power load using a low-voltage signal via galvanic isolation.

Objective and use case

You will build a driver circuit that uses a small 5 V signal to activate an electromechanical relay, which in turn switches a separate 12 V high-power circuit powering a bulb.

  • Why it is useful:

    • Automotive Systems: Allows a low-current ECU signal to switch high-current headlights.
    • Safety: Keeps high voltage/current (the load side) physically separated from the sensitive control logic (the user side).
    • Interface: Enables microcontrollers (like Arduino/ESP32) to control industrial equipment or AC appliances (simulated here with 12 V).
  • Expected outcome:

    • The 12 V bulb turns ON only when the 5 V control switch is closed.
    • An audible «click» is heard from the relay component when switching states.
    • Measurements: 0 V on the load when the control signal is 0 V; ~12 V on the load when the control signal is 5 V.
  • Target audience: Students dealing with electromechanical interfaces and circuit protection.

Materials

  • V1: 5 V DC voltage source, function: Control Logic Supply
  • V2: 12 V DC voltage source, function: High Power Load Supply
  • S1: SPST Toggle Switch, function: Control trigger
  • R1: 1 kΩ resistor, function: Base current limiter for Q1
  • Q1: 2N2222 NPN BJT Transistor, function: Relay coil driver
  • D1: 1N4007 Diode, function: Flyback protection (snubber)
  • K1: 5 V SPST Relay (coil resistance ~70 Ω), function: Galvanic isolation switch
  • L1: 12 V / 10 W Incandescent Bulb, function: High power load

Wiring guide

This guide uses specific node names to ensure correct connections in simulation and assembly. The circuit has two isolated sides: the Control Side (Nodes: V_CTRL, 0) and the Load Side (Nodes: V_HV, GND_LOAD).

Control Side (Low Power):
* V1 (+): Connects to Node V_CTRL.
* V1 (-): Connects to Node 0 (Common Ground).
* S1: Connects between V_CTRL and Node V_TRIG.
* R1: Connects between V_TRIG and Node V_BASE.
* Q1 (Base): Connects to Node V_BASE.
* Q1 (Emitter): Connects to Node 0.
* Q1 (Collector): Connects to Node COIL_LOW.
* K1 (Coil pin 1): Connects to Node V_CTRL.
* K1 (Coil pin 2): Connects to Node COIL_LOW.
* D1 (Anode): Connects to Node COIL_LOW.
* D1 (Cathode): Connects to Node V_CTRL (Reverse biased across coil).

Load Side (High Power):
* V2 (+): Connects to Node V_HV.
* V2 (-): Connects to Node GND_LOAD (Isolated from Node 0).
* K1 (Common Contact): Connects to Node V_HV.
* K1 (Normally Open Contact): Connects to Node BULB_IN.
* L1: Connects between Node BULB_IN and Node GND_LOAD.

Conceptual block diagram

Conceptual block diagram — Galvanic Isolation Control
Quick read: inputs → main block → output (actuator or measurement). This summarizes the ASCII schematic below.

Schematic

+-------------------------------------------------------------------------+
|               PRACTICAL CASE: HIGH POWER CIRCUIT ISOLATION              |
+-------------------------------------------------------------------------+

===========================================================================
  PART 1: CONTROL SIDE (5 V Logic)
  Nodes: V_CTRL, V_TRIG, V_BASE, COIL_LOW, 0 (GND)
===========================================================================

  (Trigger Signal Path)
  [ V1: 5 V (+) ] --> [ S1: Switch ] --> [ R1: 1k Ohm ] --> [ Q1: Base ]
                                                               |
                                                               | (Controls)
                                                               v
  (Coil Power Path)                                    [ Q1: Collector ]
  [ V1: 5 V (+) ] ---------> [ K1: Relay Coil ] --------------> |
                            [ || D1 Diode    ]                 |
                            [ (Rev Biased)   ]                 | (Conducts to)
                                                               |
                                                               v
                                                       [ Q1: Emitter ]
                                                               |
                                                               v
                                                       [ Node 0 (GND) ]


             ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
             ~      MAGNETIC LINK (GALVANIC ISOLATION)   ~
             ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~


===========================================================================
  PART 2: LOAD SIDE (12 V High Power)
  Nodes: V_HV, BULB_IN, GND_LOAD
===========================================================================

  (High Current Path)

  [ V2: 12 V (+) ] --> [ K1: Relay Switch ] --> [ L1: 12 V Bulb ] --> [ GND_LOAD ]
                      [   (COM -> NO)    ]
Electrical Schematic

Electrical diagram

Electrical diagram for case: High power circuit isolation
Generated from the validated SPICE netlist for this case.

🔒 This electrical diagram is premium. With the 7-day pass or the monthly membership you can unlock the complete didactic material and the print-ready PDF pack.🔓 See premium access plans

Measurements and tests

Follow these steps to validate the isolation and switching capability:

  1. Coil Voltage Test:

    • Close switch S1.
    • Measure voltage between V_CTRL and COIL_LOW.
    • Result: It should read approximately 5 V (indicating the transistor is sinking current).
  2. Load Activation:

    • Keep S1 closed.
    • Observe L1 (Bulb).
    • Result: The bulb illuminates. Measure voltage across L1; it should be ~12 V.
  3. Switch Latency (Oscilloscope required):

    • Connect Channel 1 to V_TRIG and Channel 2 to BULB_IN.
    • Toggle S1 from OFF to ON.
    • Result: You will observe a delay (typically 5–15 ms) between the signal rising on Ch1 and power appearing on Ch2. This is the mechanical switching time of the relay armature.

SPICE netlist and simulation

Reference SPICE Netlist (ngspice) — excerptFull SPICE netlist (ngspice)

* High power circuit isolation
*
* This netlist simulates a relay driver circuit with a high-power load.
* It includes a low-voltage control side (5V) and an isolated high-voltage load side (12V).
*

* --- Analysis Setup ---
.tran 10u 10m
.print tran V(V_TRIG) V(BULB_IN) V(COIL_LOW) I(L_K1_COIL)

* --- Control Side (Low Power) ---

* Supply V1: 5V DC
V1 V_CTRL 0 DC 5

* Switch S1: Modeled as a Pulse Voltage Source to simulate user actuation
* Connects to V_TRIG to drive the base resistor.
* Timing: Off for 1ms, On for 4ms, then Off.
V_S1 V_TRIG 0 PULSE(0 5 1m 10u 10u 4m 10m)

* ... (truncated in public view) ...

Copy this content into a .cir file and run with ngspice.

🔒 Part of this section is premium. With the 7-day pass or the monthly membership you can access the full content (materials, wiring, detailed build, validation, troubleshooting, variants and checklist) and download the complete print-ready PDF pack.

* High power circuit isolation
*
* This netlist simulates a relay driver circuit with a high-power load.
* It includes a low-voltage control side (5V) and an isolated high-voltage load side (12V).
*

* --- Analysis Setup ---
.tran 10u 10m
.print tran V(V_TRIG) V(BULB_IN) V(COIL_LOW) I(L_K1_COIL)

* --- Control Side (Low Power) ---

* Supply V1: 5V DC
V1 V_CTRL 0 DC 5

* Switch S1: Modeled as a Pulse Voltage Source to simulate user actuation
* Connects to V_TRIG to drive the base resistor.
* Timing: Off for 1ms, On for 4ms, then Off.
V_S1 V_TRIG 0 PULSE(0 5 1m 10u 10u 4m 10m)

* Resistor R1: 1k Base Current Limiter
R1 V_TRIG V_BASE 1k

* Transistor Q1: 2N2222 NPN Relay Driver
* Connections: Collector=COIL_LOW, Base=V_BASE, Emitter=0
Q1 COIL_LOW V_BASE 0 2N2222MOD

* Relay Coil K1 (Coil Side)
* Modeled as Inductance + Resistance in series between V_CTRL and COIL_LOW
R_K1_COIL V_CTRL INT_COIL 70
L_K1_COIL INT_COIL COIL_LOW 50m

* Diode D1: Flyback protection (Snubber)
* Anode=COIL_LOW, Cathode=V_CTRL
D1 COIL_LOW V_CTRL 1N4007MOD

* --- Load Side (High Power) ---

* Ground Isolation: High resistance path to global ground 0 to prevent singular matrix
R_ISO GND_LOAD 0 100Meg

* Supply V2: 12V DC
V2 V_HV GND_LOAD DC 12

* Relay Contact K1 (Switch Side)
* Modeled as a Voltage Controlled Switch
* Controlled by the voltage across the coil: V(V_CTRL) - V(COIL_LOW)
* Connects V_HV to BULB_IN when coil is energized
S_K1 V_HV BULB_IN V_CTRL COIL_LOW RELAY_SW_MOD

* Load L1: 12V / 10W Bulb
* Resistance ~ 14.4 Ohms (R = V^2 / P = 144 / 10)
R_L1 BULB_IN GND_LOAD 14.4

* --- Component Models ---

* NPN Transistor Model
.model 2N2222MOD NPN(IS=1E-14 VAF=100 BF=200 IKF=0.3 XTB=1.5 BR=3 CJC=8E-12 CJE=25E-12 TR=46.91E-9 TF=411.1E-12 ITF=0.6 VTF=1.7 XTF=3 RB=10 RC=0.3 RE=0.2)

* Diode Model
.model 1N4007MOD D(IS=7.02767n RS=0.0341512 N=1.80803 EG=1.11 XTI=3 BV=1000 IBV=5u CJO=10p VJ=0.7 M=0.5 FC=0.5 TT=100n)

* Relay Switch Model
* Threshold Vt=2.5V (Coil is 5V), Hysteresis Vh=0.5V
.model RELAY_SW_MOD SW(Vt=2.5 Vh=0.5 Ron=0.1 Roff=100Meg)

.op
.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)

Analysis: The simulation shows the trigger signal (V_TRIG) going high (5V) between 1ms and 5ms. During this window, the coil current (I(L_K1_COIL)) rises, causing the relay switch to close and V(BULB_IN) to switch to ~12V. After 5ms, the trigger drops, coil current decays (snubber active), and the load voltage returns to near zero.
Show raw data table (4100 rows)
Index   time            v(v_trig)       v(bulb_in)      v(coil_low)     l_k1_coil#branc
0	0.000000e+00	0.000000e+00	1.722670e-06	5.000000e+00	1.002664e-11
1	1.000000e-07	0.000000e+00	1.722670e-06	5.000000e+00	1.002626e-11
2	2.000000e-07	0.000000e+00	1.722670e-06	5.000000e+00	1.002547e-11
3	4.000000e-07	0.000000e+00	1.722670e-06	5.000000e+00	1.002342e-11
4	8.000000e-07	0.000000e+00	1.722670e-06	5.000000e+00	1.001814e-11
5	1.600000e-06	0.000000e+00	1.722670e-06	5.000000e+00	1.000316e-11
6	3.200000e-06	0.000000e+00	1.722670e-06	5.000000e+00	9.969744e-12
7	6.400000e-06	0.000000e+00	1.722670e-06	5.000000e+00	1.000801e-11
8	1.280000e-05	0.000000e+00	1.722670e-06	5.000000e+00	1.002921e-11
9	2.280000e-05	0.000000e+00	1.722670e-06	5.000000e+00	9.970357e-12
10	3.280000e-05	0.000000e+00	1.722670e-06	5.000000e+00	1.004993e-11
11	4.280000e-05	0.000000e+00	1.722670e-06	5.000000e+00	9.955463e-12
12	5.280000e-05	0.000000e+00	1.722670e-06	5.000000e+00	1.004077e-11
13	6.280000e-05	0.000000e+00	1.722670e-06	5.000000e+00	9.984500e-12
14	7.280000e-05	0.000000e+00	1.722670e-06	5.000000e+00	1.001134e-11
15	8.280000e-05	0.000000e+00	1.722670e-06	5.000000e+00	1.001578e-11
16	9.280000e-05	0.000000e+00	1.722670e-06	5.000000e+00	1.000519e-11
17	1.028000e-04	0.000000e+00	1.722670e-06	5.000000e+00	1.003686e-11
18	1.128000e-04	0.000000e+00	1.722670e-06	5.000000e+00	9.961732e-12
19	1.228000e-04	0.000000e+00	1.722670e-06	5.000000e+00	1.005266e-11
20	1.328000e-04	0.000000e+00	1.722670e-06	5.000000e+00	9.963169e-12
21	1.428000e-04	0.000000e+00	1.722670e-06	5.000000e+00	1.003205e-11
22	1.528000e-04	0.000000e+00	1.722670e-06	5.000000e+00	9.984436e-12
23	1.628000e-04	0.000000e+00	1.722670e-06	5.000000e+00	1.001919e-11
... (4076 more rows) ...

Common mistakes and how to avoid them

  1. Omitting the flyback diode (D1):

    • Error: The transistor Q1 fails permanently after a few switches.
    • Solution: Always place a diode in reverse bias parallel to the relay coil to absorb the high-voltage spike generated when the magnetic field collapses.
  2. Sharing Grounds unintentionally:

    • Error: Connecting GND_LOAD to Node 0 on the breadboard.
    • Solution: While the circuit will work, you lose galvanic isolation. Keep the high-power return path physically separate from the logic ground.
  3. Insufficient Base Current:

    • Error: Using a resistor R1 that is too high (e.g., 100 kΩ). The relay does not click or clicks weakly.
    • Solution: Ensure the transistor is in saturation. For a 2N2222 driving a standard relay, 1 kΩ is usually sufficient.

Troubleshooting

  • Symptom: Relay clicks, but the bulb does not light up.

    • Cause: Issue on the Load Side (Secondary circuit).
    • Fix: Check V2 supply, verify the bulb L1 is not burnt, and ensure connections to the Relay COM/NO pins are tight.
  • Symptom: No sound from relay, Bulb OFF.

    • Cause: The coil is not energizing.
    • Fix: Check voltage at Node V_BASE. If 0 V, check S1. If ~0.7 V, check if Q1 is installed correctly (E-B-C pinout).
  • Symptom: Transistor gets extremely hot.

    • Cause: Coil current is too high for the selected transistor.
    • Fix: Verify the relay coil resistance. If it draws >600 mA, the 2N2222 might be underpowered; use a power transistor (e.g., TIP31) or a MOSFET.

Possible improvements and extensions

  1. Status Indicator: Add a small LED and a 330 Ω resistor in parallel with the Relay Coil to visually indicate when the control signal is active.
  2. Solid State Upgrade: Replace the mechanical relay (K1) and transistor driver with an Optocoupler and a MOSFET (or Triac for AC) to eliminate mechanical wear and reduce switching latency.

More Practical Cases on Prometeo.blog

Find this product and/or books on this topic on Amazon

Go to Amazon

As an Amazon Associate, I earn from qualifying purchases. If you buy through this link, you help keep this project running.

Quick Quiz

Question 1: What is the primary function of the electromechanical relay in this circuit?




Question 2: Which component is typically responsible for driving the relay coil in this type of driver circuit?




Question 3: What is the purpose of the flyback diode (D1) placed across the relay coil?




Question 4: What voltage is specified for the Control Logic Supply (V1)?




Question 5: What physical indication is expected from the relay component when it switches states?




Question 6: Why is this relay circuit useful in automotive systems?




Question 7: What is the function of the base resistor (R1) connected to the transistor?




Question 8: What voltage measurement is expected on the load when the control signal is 0 V?




Question 9: Which component represents the high-power load in this specific circuit?




Question 10: What is the main safety benefit of using a relay for galvanic isolation?




Carlos Núñez Zorrilla
Carlos Núñez Zorrilla
Electronics & Computer Engineer

Telecommunications Electronics Engineer and Computer Engineer (official degrees in Spain).

Follow me:


Practical case: DC Motor Reversing

DC Motor Reversing prototype (Maker Style)

Level: Basic – Understand how to use two SPDT relays to change polarity and direction of a DC motor.

Objective and use case

In this case, you will build a relay-based H-bridge circuit to control a DC motor. By using two Single Pole Double Throw (SPDT) relays, you will be able to drive the motor clockwise, counter-clockwise, or brake it using simple pushbuttons.

  • Real-world scenarios:
  • Automotive Power Windows: Reversing the motor to raise or lower the glass.
  • Robotics: Controlling wheel direction for forward and backward movement.
  • Industrial Conveyors: Changing the direction of a belt to route products.
  • Motorized Curtains: Opening and closing mechanisms.

  • Expected outcome:

  • Idle State: When no buttons are pressed, the motor terminals are grounded (0 V difference), resulting in a dynamic brake (motor stops).
  • Forward State: Pressing Button A applies +5 V to the motor; it spins Clockwise (CW).
  • Reverse State: Pressing Button B applies -5 V (polarity swap) to the motor; it spins Counter-Clockwise (CCW).
  • Braking/Safety: If both buttons are pressed simultaneously, both motor terminals connect to VCC, resulting in 0 V difference and the motor remains stopped.

Target audience: Hobbyists and students getting started with electromechanical control.

Materials

  • V1: 5 V DC Power Supply, function: Main energy source.
  • M1: 5 V DC Motor, function: The actuator to be controlled.
  • K1: 5 V SPDT Relay, function: Controls the «Positive» side of the motor.
  • K2: 5 V SPDT Relay, function: Controls the «Negative» side of the motor.
  • S1: Momentary Pushbutton (NO), function: Activates Relay K1 (Forward).
  • S2: Momentary Pushbutton (NO), function: Activates Relay K2 (Reverse).
  • D1: 1N4007 Diode, function: Flyback protection for K1 coil.
  • D2: 1N4007 Diode, function: Flyback protection for K2 coil.

Wiring guide

This guide uses node names to describe connections.
Nodes: VCC (5 V Supply), 0 (Ground), COIL_A, COIL_B, MOT_A, MOT_B.

  • Power Supply:
  • V1 (+): Connects to node VCC.
  • V1 (-): Connects to node 0.

  • Control Circuit (Coils):

  • S1: Connects between VCC and COIL_A.
  • K1 (Coil): Connects between COIL_A and 0.
  • D1: Cathode to COIL_A, Anode to 0 (Protects against inductive spikes).
  • S2: Connects between VCC and COIL_B.
  • K2 (Coil): Connects between COIL_B and 0.
  • D2: Cathode to COIL_B, Anode to 0.

  • Power Circuit (Motor Drive):

  • K1 (Normally Open – NO): Connects to VCC.
  • K1 (Normally Closed – NC): Connects to 0.
  • K1 (Common – COM): Connects to node MOT_A.
  • K2 (Normally Open – NO): Connects to VCC.
  • K2 (Normally Closed – NC): Connects to 0.
  • K2 (Common – COM): Connects to node MOT_B.
  • M1: Connects between MOT_A and MOT_B.

Conceptual block diagram

Conceptual block diagram — Relay H-Bridge Motor Control
Quick read: inputs → main block → output (actuator or measurement). This summarizes the ASCII schematic below.

Schematic

+-------------------------------------------------------------------------+
|                DC MOTOR REVERSING CIRCUIT (H-BRIDGE)                    |
+-------------------------------------------------------------------------+

[ CONTROL SUBSYSTEM ]                                [ POWER SUBSYSTEM ]

      (Forward Input)                                   (Left Side Drive)
VCC --> [ S1 Button ]                                  VCC (NO)
            |                                             |
            v                                             v
    [ Node: COIL_A ]                               [ K1 Switch (COM) ] --(MOT_A)--+
            |                                      [  (Relay 1)      ]            |
            +--> [ K1 Coil || D1 ] --> GND                ^                       |
            |    (D1 is Reverse Biased)                   |                       |
            |                                             |                       |
            +----------(Magnetic Link)--------------------+                       |
                                                          |                       |
                                                  GND (NC) +                      |
                                                                                  v
                                                                           [ DC MOTOR ]
                                                                           [    M1    ]
                                                                                  ^
                                                  GND (NC) +                      |
                                                          |                       |
            +----------(Magnetic Link)--------------------+                       |
            |                                             |                       |
            |    (D2 is Reverse Biased)                   |                       |
            +--> [ K2 Coil || D2 ] --> GND         [ K2 Switch (COM) ] --(MOT_B)--+
            |                                      [  (Relay 2)      ]
    [ Node: COIL_B ]                                      ^
            ^                                             |
            |                                             |
VCC --> [ S2 Button ]                                  VCC (NO)
      (Reverse Input)                                   (Right Side Drive)

+-------------------------------------------------------------------------+
| LOGIC KEY:                                                              |
| 1. Idle: Both Switches connect COM to NC (GND). Motor is braked (0 V).   |
| 2. Press S1: K1 switches to NO (VCC). Current: VCC->MOT_A->MOT_B->GND.  |
| 3. Press S2: K2 switches to NO (VCC). Current: VCC->MOT_B->MOT_A->GND.  |
+-------------------------------------------------------------------------+
Electrical Schematic

Electrical diagram

Electrical diagram for case: DC motor reversing
Generated from the validated SPICE netlist for this case.

🔒 This electrical diagram is premium. With the 7-day pass or the monthly membership you can unlock the complete didactic material and the print-ready PDF pack.🔓 See premium access plans

Measurements and tests

To validate the circuit, perform the following steps using a multimeter and visual inspection:

  1. Idle Check: Ensure neither S1 nor S2 is pressed. Measure voltage between MOT_A and MOT_B.
    • Result: Should be 0 V. Both terminals are connected to GND via the NC contacts. The motor is locked (hard to turn by hand due to back EMF shorting).
  2. Forward Actuation: Press and hold S1.
    • Result: K1 clicks. Measure voltage from MOT_A (Red probe) to MOT_B (Black probe). Voltage should be approximately +5 V. Motor spins Clockwise.
  3. Reverse Actuation: Release S1, then press and hold S2.
    • Result: K2 clicks. Measure voltage from MOT_A to MOT_B. Voltage should be approximately -5 V. Motor spins Counter-Clockwise.
  4. Double Press (Safety Test): Press both S1 and S2 simultaneously.
    • Result: Both relays click. Voltage between MOT_A and MOT_B is 0 V (Both at 5 V potential). Motor does not move.

SPICE netlist and simulation

Reference SPICE Netlist (ngspice) — excerptFull SPICE netlist (ngspice)

* Practical case: DC Motor Reversing
.width out=256
* Ngspice Netlist
*
* Description: H-Bridge configuration using two SPDT relays to control a DC motor.
* Logic:
* - S1 Pressed -> K1 Active -> MOT_A = 5V, MOT_B = 0V (Forward)
* - S2 Pressed -> K2 Active -> MOT_A = 0V, MOT_B = 5V (Reverse)
* - None Pressed -> MOT_A = 0V, MOT_B = 0V (Stop/Brake)
*
* Simulation Time: 10ms (Captures S1 pulse at 1ms and S2 pulse at 5ms)
.tran 10u 10m

* -----------------------------------------------------------------------------
* Power Supply
* -----------------------------------------------------------------------------
* V1: 5V DC Power Supply, function: Main energy source.
* Connected between VCC (+) and 0 (-).
V1 VCC 0 DC 5

* ... (truncated in public view) ...

Copy this content into a .cir file and run with ngspice.

🔒 Part of this section is premium. With the 7-day pass or the monthly membership you can access the full content (materials, wiring, detailed build, validation, troubleshooting, variants and checklist) and download the complete print-ready PDF pack.

* Practical case: DC Motor Reversing
.width out=256
* Ngspice Netlist
*
* Description: H-Bridge configuration using two SPDT relays to control a DC motor.
* Logic:
* - S1 Pressed -> K1 Active -> MOT_A = 5V, MOT_B = 0V (Forward)
* - S2 Pressed -> K2 Active -> MOT_A = 0V, MOT_B = 5V (Reverse)
* - None Pressed -> MOT_A = 0V, MOT_B = 0V (Stop/Brake)
*
* Simulation Time: 10ms (Captures S1 pulse at 1ms and S2 pulse at 5ms)
.tran 10u 10m

* -----------------------------------------------------------------------------
* Power Supply
* -----------------------------------------------------------------------------
* V1: 5V DC Power Supply, function: Main energy source.
* Connected between VCC (+) and 0 (-).
V1 VCC 0 DC 5

* -----------------------------------------------------------------------------
* User Inputs (Pushbuttons)
* -----------------------------------------------------------------------------
* Modeled as Voltage Controlled Switches (S1, S2) driven by Pulse Sources.
* This strictly simulates the user pressing the button at specific times.

* Stimulus for S1 (Forward Request)
* Pulse: 0V to 5V, starts at 1ms, duration 2ms.
V_USER_S1 CTRL_S1 0 PULSE(0 5 1m 1u 1u 2m 10m)

* Stimulus for S2 (Reverse Request)
* Pulse: 0V to 5V, starts at 5ms, duration 2ms.
V_USER_S2 CTRL_S2 0 PULSE(0 5 5m 1u 1u 2m 10m)

* S1: Momentary Pushbutton (NO)
* Connects VCC to COIL_A when activated by V_USER_S1.
S1 VCC COIL_A CTRL_S1 0 SW_PUSH

* S2: Momentary Pushbutton (NO)
* Connects VCC to COIL_B when activated by V_USER_S2.
S2 VCC COIL_B CTRL_S2 0 SW_PUSH

* -----------------------------------------------------------------------------
* Control Circuit (Relay Coils)
* -----------------------------------------------------------------------------
* Relay K1 Coil Circuit
* K1 Coil: Connects between COIL_A and 0. Modeled as L+R.
L_K1 COIL_A K1_INT 10m
R_K1 K1_INT 0 100
* D1: 1N4007 Diode, function: Flyback protection.
* Cathode to COIL_A, Anode to 0.
D1 0 COIL_A D_1N4007

* Relay K2 Coil Circuit
* K2 Coil: Connects between COIL_B and 0. Modeled as L+R.
L_K2 COIL_B K2_INT 10m
R_K2 K2_INT 0 100
* D2: 1N4007 Diode, function: Flyback protection.
* Cathode to COIL_B, Anode to 0.
D2 0 COIL_B D_1N4007

* -----------------------------------------------------------------------------
* Power Circuit (Motor Drive via Relay Contacts)
* -----------------------------------------------------------------------------
* Relay K1 Contacts (SPDT)
* COM: MOT_A
* NO: VCC (Connected when Coil is Energized/High)
* NC: 0   (Connected when Coil is De-energized/Low)
S_K1_NO VCC MOT_A COIL_A 0 SW_NO_RELAY
S_K1_NC MOT_A 0   COIL_A 0 SW_NC_RELAY

* Relay K2 Contacts (SPDT)
* COM: MOT_B
* NO: VCC (Connected when Coil is Energized/High)
* NC: 0   (Connected when Coil is De-energized/Low)
S_K2_NO VCC MOT_B COIL_B 0 SW_NO_RELAY
S_K2_NC MOT_B 0   COIL_B 0 SW_NC_RELAY

* M1: 5 V DC Motor
* Modeled as a resistive load (50 Ohms) to visualize voltage polarity.
* Connects between MOT_A and MOT_B.
R_M1 MOT_A MOT_B 50

* -----------------------------------------------------------------------------
* Component Models
* -----------------------------------------------------------------------------
* Standard Diode Model
.model D_1N4007 D(IS=1N N=1 RS=0.1 BV=1000 IBV=10u)

* Pushbutton Switch Model (Normally Open)
* Closes (Low R) when Control Voltage > 2.5V
.model SW_PUSH SW(Vt=2.5 Vh=0.1 Ron=0.01 Roff=10Meg)

* Relay Contact Models
* NO (Normally Open): Conducts when Coil > 2.5V
.model SW_NO_RELAY SW(Vt=2.5 Vh=0.1 Ron=0.01 Roff=10Meg)

* NC (Normally Closed): Conducts when Coil < 2.5V
* SPICE SW Logic: If V < Vt, R = Roff. If V > Vt, R = Ron.
* For NC: We want Low R when V < Vt. So Roff=0.01, Ron=10Meg.
.model SW_NC_RELAY SW(Vt=2.5 Vh=0.1 Ron=10Meg Roff=0.01)

* -----------------------------------------------------------------------------
* Output Directives
* -----------------------------------------------------------------------------
* Outputs: Motor Terminals (MOT_A, MOT_B)
* Inputs: Coil Control Voltages (COIL_A, COIL_B)
.print tran V(MOT_A) V(MOT_B) V(COIL_A) V(COIL_B) I(L_K1)

.op
.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)

Analysis: At 1ms, S1 activates, energizing Coil A (approx 5V). Consequently, MOT_A goes to 5V while MOT_B stays near 0V (Forward). At 3ms, S1 releases and the motor stops. At 5ms, S2 activates, energizing Coil B. MOT_B goes to 5V while MOT_A stays near 0V (Reverse). Inductive kickback is visible on coil nodes when switches open.
Show raw data table (1104 rows)
Index   time            v(mot_a)        v(mot_b)        v(coil_a)       v(coil_b)       l_k1#branch
0	0.000000e+00	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
1	1.000000e-07	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
2	2.000000e-07	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
3	4.000000e-07	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
4	8.000000e-07	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
5	1.600000e-06	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
6	3.200000e-06	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
7	6.400000e-06	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
8	1.280000e-05	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
9	2.280000e-05	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
10	3.280000e-05	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
11	4.280000e-05	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
12	5.280000e-05	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
13	6.280000e-05	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
14	7.280000e-05	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
15	8.280000e-05	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
16	9.280000e-05	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
17	1.028000e-04	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
18	1.128000e-04	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
19	1.228000e-04	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
20	1.328000e-04	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
21	1.428000e-04	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
22	1.528000e-04	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
23	1.628000e-04	5.000000e-09	5.000000e-09	4.999931e-05	4.999931e-05	4.999931e-07
... (1080 more rows) ...

Common mistakes and how to avoid them

  1. Wiring the Motor to NO/NC instead of COM:
    • Mistake: Connecting the motor to the Normally Open or Closed pins, and power to the Common pin.
    • Solution: Always connect the Load (Motor) to the Common (COM) pin of the SPDT relay for H-bridge configurations. Power and Ground go to NO and NC.
  2. Omitting Flyback Diodes:
    • Mistake: Forgetting D1 and D2 across the relay coils.
    • Solution: Always install diodes in reverse bias across coils to prevent high-voltage spikes from damaging switches or power supplies when the relay turns off.
  3. Using SPST Relays:
    • Mistake: Attempting this topology with 4-pin relays that lack a Normally Closed contact.
    • Solution: Ensure you use 5-pin SPDT relays so the motor can be grounded when the relay is off.

Troubleshooting

  • Motor vibrates but does not spin:
    • Cause: Power supply current is insufficient.
    • Fix: Check the current rating of your power supply; motors draw high current upon startup.
  • Relay clicks but motor does not move:
    • Cause: Burnt internal contacts or loose wiring on the COM/NO/NC terminals.
    • Fix: Verify continuity between COM and NO when the relay is active using a multimeter.
  • Sparks visible inside the relay:
    • Cause: Inductive load kickback from the motor.
    • Fix: While not always fatal, adding a small capacitor (e.g., 100 nF) across the motor terminals can reduce arcing and noise.

Possible improvements and extensions

  1. Limit Switches: Add Normally Closed limit switches in series with the relay coils (COIL_A and COIL_B) to automatically stop the motor when a mechanism reaches its end of travel.
  2. Speed Control: Insert a high-wattage rheostat or a PWM transistor driver in series with the main VCC supply to the relay contacts (not the coils) to vary the motor speed.

More Practical Cases on Prometeo.blog

Find this product and/or books on this topic on Amazon

Go to Amazon

As an Amazon Associate, I earn from qualifying purchases. If you buy through this link, you help keep this project running.

Quick Quiz

Question 1: What is the primary objective of the circuit described in the text?




Question 2: Which type of relay is specifically required for this project?




Question 3: What happens to the motor in the 'Idle State' when no buttons are pressed?




Question 4: Which real-world scenario is NOT mentioned as a use case for this circuit?




Question 5: According to the text, what occurs when Button A is pressed?




Question 6: How is the 'Reverse State' achieved in this circuit?




Question 7: What is the result if both Button A and Button B are pressed simultaneously?




Question 8: In the context of this circuit, what does 'dynamic braking' refer to?




Question 9: What voltage level is applied to the motor to achieve the Forward State in this example?




Question 10: Which of the following is listed as an industrial application for this circuit?




Carlos Núñez Zorrilla
Carlos Núñez Zorrilla
Electronics & Computer Engineer

Telecommunications Electronics Engineer and Computer Engineer (official degrees in Spain).

Follow me: