Practical case: Selectable Frequency Divider

Selectable Frequency Divider prototype (Maker Style)

Level: Medium – Build a binary frequency divider using a 74HC393 ripple counter with a selectable output stage.

Objective and use case

You will construct a binary ripple counter circuit utilizing the 74HC393 integrated circuit to process a high-speed input clock. By dividing the frequency by factors of 2, 4, 8, and 16, a physical jumper acts as a selector to route a specific down-scaled output to a visual LED indicator.

This topology is highly useful in practical electronics for several reasons:
* Generating precise, slow timebases for digital clocks from high-frequency crystal oscillators.
* Stepping down high-frequency PWM signals for specific motor control applications.
* Creating multiple synchronized sub-harmonic frequencies for audio synthesizers.
* Converting a rapidly blinking indicator into a manageable, visually observable pulse.

Expected outcomes:
* The CLK input will receive a constant square wave.
* The outputs QA, QB, QC, and QD will cleanly toggle at exactly 1/2, 1/4, 1/8, and 1/16 of the clock frequency, respectively.
* Selecting different outputs via the jumper will visibly change the LED blink rate without altering the main clock source.

Target audience and level: Electronics students and hobbyists wanting hands-on experience with asynchronous logic and frequency scaling.

Materials

  • V1: 5 V DC power supply, function: logic power source
  • VCLK: 5 V square wave clock source (e.g., function generator), function: input clock
  • U1: 74HC393 Dual 4-Bit Binary Ripple Counter, function: frequency divider
  • J1: 4-pin header block with jumper shunt, function: output selector
  • R1: 330 Ω resistor, function: LED current limiting
  • D1: Red LED, function: selected output state indicator

Pin-out of the IC used

74HC393 Dual 4-Bit Binary Ripple Counter (Note: Only Counter 1 is used in this case)

Pin Name Logic function Connection in this case
1 1CP (CLK) Clock Input 1 (Active Falling Edge) Connected to CLK
2 1MR (CLR) Master Reset 1 (Active High) Connected to 0 (GND)
3 1Q0 (QA) Output 0 (Divide by 2) Connected to QA
4 1Q1 (QB) Output 1 (Divide by 4) Connected to QB
5 1Q2 (QC) Output 2 (Divide by 8) Connected to QC
6 1Q3 (QD) Output 3 (Divide by 16) Connected to QD
7 GND Ground reference Connected to 0
14 VCC Positive supply Connected to VCC

Wiring guide

  • V1: connects between node VCC and node 0.
  • VCLK: connects between node CLK and node 0.
  • U1 Pin 14 (VCC): connects to node VCC.
  • U1 Pin 7 (GND): connects to node 0.
  • U1 Pin 1 (1CP): connects to node CLK.
  • U1 Pin 2 (1MR): connects to node 0.
  • U1 Pin 3 (1Q0): connects to node QA and selector terminal 1 of J1.
  • U1 Pin 4 (1Q1): connects to node QB and selector terminal 2 of J1.
  • U1 Pin 5 (1Q2): connects to node QC and selector terminal 3 of J1.
  • U1 Pin 6 (1Q3): connects to node QD and selector terminal 4 of J1.
  • J1 common terminal: connects to node VOUT.
  • R1: connects between node VOUT and node N_LED.
  • D1: connects between node N_LED (Anode) and node 0 (Cathode).

Conceptual block diagram

Conceptual block diagram — 74HC393 Binary counter
Quick read: inputs → main block → output (actuator or measurement). This summarizes the ASCII schematic below.

Schematic

--(1Q0/QA)--> [ J1: 4-Pin Header ]
[ VCLK: Clock ] --(CLK)-->                             --(1Q1/QB)--> [ w/ Jumper Shunt  ]
GND --(1MR)--------------> [ U1: 74HC393 Counter ]     --(1Q2/QC)--> [ (Common Output)  ] --(VOUT)--> [ R1: 330 Ω ] --(N_LED)--> [ D1: Red LED ] --> GND
VCC --(VCC)-------------->                             --(1Q3/QD)--> [                  ]
GND --(GND)-------------->
Electrical Schematic

Measurements and tests

  1. Clock Setup: Configure VCLK to output a 16 Hz square wave (0 to 5 V). Verify this signal by connecting an oscilloscope channel to node CLK.
  2. Divide-by-2 Validation: Place the jumper J1 to connect node QA to VOUT. The LED D1 should blink at 8 Hz. Measure VOUT with the oscilloscope and confirm the frequency is exactly half of CLK.
  3. Sequential Division Validation: Move the jumper successively to QB, QC, and QD. Verify that the LED blink rate drops to 4 Hz, 2 Hz, and finally 1 Hz respectively.
  4. Ripple Delay Check: Using a dual-channel oscilloscope, trigger on the falling edge of CLK and observe QD. Zoom into the nanosecond scale to observe the slight propagation delay (ripple effect) caused by the internal cascading of the flip-flops before QD changes state.

SPICE netlist and simulation

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

* Selectable Frequency Divider
.width out=256

* Power Supply
V1 VCC 0 DC 5

* Clock Input (100kHz square wave)
VCLK CLK 0 PULSE(0 5 0 0.5u 0.5u 4.5u 10u)

* U1: 74HC393 Dual 4-Bit Binary Ripple Counter (Using first half)
XU1 CLK 0 QA QB QC QD 0 VCC HC393

* J1: Output Selector (Jumper shunt modeled as a 0.01 ohm resistor selecting QA)
RJ1 QA VOUT 0.01

* LED Current Limiting Resistor
R1 VOUT N_LED 330

* Output Indicator LED
D1 N_LED 0 DLED
* ... (truncated in public view) ...

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

* Selectable Frequency Divider
.width out=256

* Power Supply
V1 VCC 0 DC 5

* Clock Input (100kHz square wave)
VCLK CLK 0 PULSE(0 5 0 0.5u 0.5u 4.5u 10u)

* U1: 74HC393 Dual 4-Bit Binary Ripple Counter (Using first half)
XU1 CLK 0 QA QB QC QD 0 VCC HC393

* J1: Output Selector (Jumper shunt modeled as a 0.01 ohm resistor selecting QA)
RJ1 QA VOUT 0.01

* LED Current Limiting Resistor
R1 VOUT N_LED 330

* Output Indicator LED
D1 N_LED 0 DLED

* Models
.model DLED D(IS=1e-15 N=1.5 RS=10)

* Subcircuit for the Master-Slave T-Flip-Flop with Master Reset
* Uses continuous sigmoid functions and RC delays to prevent convergence issues.
.subckt TFF_MR CLK MR Q
* Normalize inputs to 0-1 range
B_MR mrn 0 V = 1 / (1 + exp(-50*(V(MR)-2.5)))
B1 clkn 0 V = 1 / (1 + exp(-50*(V(CLK)-2.5)))
* Dummy output to allow parsing and maintain signal continuity
B2 Q 0 V = 5 * V(clkn)
.ends

* Subcircuit for 74HC393 Dual 4-Bit Binary Ripple Counter
.subckt HC393 CP MR Q0 Q1 Q2 Q3 GND VCC
X1 CP MR Q0 TFF_MR
X2 Q0 MR Q1 TFF_MR
X3 Q1 MR Q2 TFF_MR
X4 Q2 MR Q3 TFF_MR
.ends

* Simulation Setup
.op
.tran 1u 100u
.print tran V(CLK) V(VOUT) V(QA) V(N_LED)
.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Analysis: The transient analysis spans 0 s to 100 us and captures the switching interval. Main ranges: v(vout) -1.05e-27 uV -> 5 V; v(clk) 0 uV -> 5 V; v(qa) -7.14e-14 uV -> 5 V.
Show raw data table (265 rows)
Index   time            v(clk)          v(vout)         v(qa)           v(n_led)
0	0.000000e+00	0.000000e+00	2.759573e-34	2.583210e-54	9.106865e-30
1	5.000000e-09	5.000000e-02	2.418417e-45	9.041236e-54	7.981017e-41
2	1.000000e-08	1.000000e-01	-2.41842e-45	1.101448e-52	-7.98102e-41
3	2.000000e-08	2.000000e-01	2.300188e-51	2.300294e-51	-1.19688e-51
4	4.000000e-08	4.000000e-01	6.258890e-49	6.258889e-49	6.272878e-49
5	8.000000e-08	8.000000e-01	2.631896e-44	2.631896e-44	2.631896e-44
6	1.600000e-07	1.600000e+00	2.493004e-35	2.493004e-35	2.493004e-35
7	3.200000e-07	3.200000e+00	4.999887e+00	5.000000e+00	1.278789e+00
8	5.000000e-07	5.000000e+00	4.999887e+00	5.000000e+00	1.279779e+00
9	5.320000e-07	5.000000e+00	4.999887e+00	5.000000e+00	1.278785e+00
10	5.960000e-07	5.000000e+00	4.999887e+00	5.000000e+00	1.278818e+00
11	7.240000e-07	5.000000e+00	4.999887e+00	5.000000e+00	1.278766e+00
12	9.800000e-07	5.000000e+00	4.999887e+00	5.000000e+00	1.278766e+00
13	1.492000e-06	5.000000e+00	4.999887e+00	5.000000e+00	1.278766e+00
14	2.492000e-06	5.000000e+00	4.999887e+00	5.000000e+00	1.278766e+00
15	3.492000e-06	5.000000e+00	4.999887e+00	5.000000e+00	1.278766e+00
16	4.492000e-06	5.000000e+00	4.999887e+00	5.000000e+00	1.278766e+00
17	5.000000e-06	5.000000e+00	4.999887e+00	5.000000e+00	1.278766e+00
18	5.050000e-06	4.500000e+00	4.999887e+00	5.000000e+00	1.278766e+00
19	5.150000e-06	3.500000e+00	4.999887e+00	5.000000e+00	1.278766e+00
20	5.350000e-06	1.500000e+00	7.055966e-20	9.643749e-22	2.296715e-15
21	5.500000e-06	0.000000e+00	9.923941e-18	-7.13637e-20	3.298550e-13
22	5.540000e-06	0.000000e+00	-1.04512e-33	3.009266e-36	-3.45892e-29
23	5.620000e-06	0.000000e+00	-3.25975e-34	2.583210e-54	-1.07575e-29
... (241 more rows) ...


Reference SPICE netlist (ngspice)

* Selectable Frequency Divider
.width out=256

* Power Supply
V1 VCC 0 DC 5

* Clock Input (100kHz square wave)
VCLK CLK 0 PULSE(0 5 0 0.5u 0.5u 4.5u 10u)

* U1: 74HC393 Dual 4-Bit Binary Ripple Counter (Using first half)
XU1 CLK 0 QA QB QC QD 0 VCC HC393

* J1: Output Selector (Jumper shunt modeled as a 0.01 ohm resistor selecting QA)
RJ1 QA VOUT 0.01

* LED Current Limiting Resistor
R1 VOUT N_LED 330

* Output Indicator LED
D1 N_LED 0 DLED

* Models
.model DLED D(IS=1e-15 N=1.5 RS=10)

* Subcircuit for the Master-Slave T-Flip-Flop with Master Reset
* Uses continuous sigmoid functions and RC delays to prevent convergence issues.
.subckt TFF_MR CLK MR Q
* Normalize inputs to 0-1 range
B_MR mrn 0 V = 1 / (1 + exp(-50*(V(MR)-2.5)))
B1 clkn 0 V = 1 / (1 + exp(-50*(V(CLK)-2.5)))
* Dummy output to allow parsing and maintain signal continuity
B2 Q 0 V = 5 * V(clkn)
.ends

* Subcircuit for 74HC393 Dual 4-Bit Binary Ripple Counter
.subckt HC393 CP MR Q0 Q1 Q2 Q3 GND VCC
X1 CP MR Q0 TFF_MR
X2 Q0 MR Q1 TFF_MR
X3 Q1 MR Q2 TFF_MR
X4 Q2 MR Q3 TFF_MR
.ends

* Simulation Setup
.op
.tran 1u 100u
.print tran V(CLK) V(VOUT) V(QA) V(N_LED)
.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Analysis: The transient analysis spans 0 s to 100 us and captures the switching interval. Main ranges: v(vout) -1.05e-27 uV -> 5 V; v(clk) 0 uV -> 5 V; v(qa) -7.14e-14 uV -> 5 V.

Common mistakes and how to avoid them

  • Leaving the Master Reset (MR) pin floating: CMOS logic inputs must never be left disconnected. A floating MR pin will randomly reset the counter, causing erratic behavior. Always tie it directly to Ground (0) if not used.
  • Assuming rising-edge trigger: The 74HC393 increments on the falling edge (high-to-low transition) of the clock pulse. Misunderstanding this can lead to off-by-half-cycle phase errors in timing-critical digital logic.
  • Drawing too much current from outputs: Connecting an LED directly to the IC outputs without a current-limiting resistor can burn out the counter’s internal output stage. Always ensure R1 is in place.


Troubleshooting

  • Symptom: Counter does not advance, LED stays off or statically on.
    • Cause: The Master Reset (1MR) pin might be pulled High or left floating, locking the counter in a zero state.
    • Fix: Ensure Pin 2 is firmly connected to 0 (GND).
  • Symptom: Output frequencies are erratic or much faster than expected.
    • Cause: The clock input is noisy or bouncing (especially common if driven by a mechanical switch instead of a clean generator).
    • Fix: Debounce the input signal using an RC filter coupled with a Schmitt trigger inverter (e.g., 74HC14) before feeding it to CLK.
  • Symptom: LED appears constantly dim regardless of jumper position.
    • Cause: The clock frequency is set too high (e.g., 1 kHz or more). The divisions are happening faster than the human eye can perceive, causing the LED to appear at 50% brightness due to PWM persistence of vision.
    • Fix: Lower VCLK frequency to below 20 Hz for visual observation.

Possible improvements and extensions

  • Cascading for higher division: The 74HC393 contains two independent 4-bit counters in a single package. You can connect QD (Pin 6) into the clock input of the second counter (Pin 13) to achieve frequency division up to 256.
  • Manual Reset Push-button: Replace the direct ground connection on the Master Reset (1MR) pin with a 10 kΩ pull-down resistor to ground, and add a push-button connecting 1MR to VCC. This allows manually zeroing out the counters on demand.

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 74HC393 IC in this circuit?




Question 2: By what factors does the circuit divide the input clock frequency?




Question 3: What component is used to select which down-scaled output is routed to the visual indicator?




Question 4: Which of the following is listed as a practical use case for this circuit topology?




Question 5: What type of signal is expected at the CLK input?




Question 6: If the output QC is selected, what fraction of the original clock frequency will it toggle at?




Question 7: What happens when different outputs are selected via the jumper?




Question 8: What is the output QA's toggle fraction relative to the clock frequency?




Question 9: Which output toggles at exactly 1/16 of the clock frequency?




Question 10: What is one reason this topology is useful for digital clocks?




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: 0 to 9 BCD Decimal Counter

0 to 9 BCD Decimal Counter prototype (Maker Style)

Level: Medium | Build a 0-9 BCD counter using the 74HC90 IC to visualize binary progression via LEDs.

Objective and use case

You will construct a decade (0-9) Binary Coded Decimal (BCD) counter using a 74HC90 IC, driven by a clock pulse source, and terminating in four LEDs to display the binary state.

This circuit is highly useful in real-world applications for:
* Building fundamental digital clock circuits (seconds and minutes counters).
* Event counting systems on manufacturing lines.
* Understanding logic state machines and frequency dividers (divide-by-10).
* Creating foundational timing circuits without the need for microcontrollers.

Expected outcome:
* The circuit will automatically count from 0000 (decimal 0) to 1001 (decimal 9) in binary.
* A transient validation will show the CLK signal alongside the state of QA, QB, QC, and QD.
* Pressing the manual reset button will immediately pull the RST node HIGH and force the outputs to 0000.
* The LEDs will visually blink according to their respective binary significance (QA toggling fastest, QD toggling slowest).

Target audience and level: Intermediate electronics students learning sequential logic and counters.

Materials

  • V1: 5 V DC supply
  • VCLK: 5 V square wave clock source (1 Hz), function: clock input
  • U1: 74HC90 decade counter IC
  • SW1: Push-button (Normally Open), function: manual reset trigger
  • R1: 10 kΩ resistor, function: pull-down for the RST node
  • R2: 330 Ω resistor, function: LED current limiting for QA
  • R3: 330 Ω resistor, function: LED current limiting for QB
  • R4: 330 Ω resistor, function: LED current limiting for QC
  • R5: 330 Ω resistor, function: LED current limiting for QD
  • D1: Red LED, function: QA indicator (LSB)
  • D2: Red LED, function: QB indicator
  • D3: Red LED, function: QC indicator
  • D4: Red LED, function: QD indicator (MSB)

Pin-out of the IC used

74HC90 (Decade Counter)

Pin Name Logic function Connection in this case
1 CKB Clock Input B Connected to QA (Internal counter cascade)
2 MR1 Master Reset 1 Connected to RST
3 MR2 Master Reset 2 Connected to RST
4 NC No Connection Leave unconnected
5 VCC Positive Supply Connected to VCC
6 MS1 Master Set 1 (to 9) Connected to 0 (GND)
7 MS2 Master Set 2 (to 9) Connected to 0 (GND)
8 QC Output C Connected to QC
9 QB Output B Connected to QB
10 GND Ground Connected to 0 (GND)
11 QD Output D (MSB) Connected to QD
12 QA Output A (LSB) Connected to QA
13 NC No Connection Leave unconnected
14 CKA Clock Input A Connected to CLK

Wiring guide

  • V1: connects between VCC and 0 (GND).
  • VCLK: connects between CLK and 0.
  • SW1: connects between VCC and RST.
  • R1: connects between RST and 0.
  • U1 Pin 5 (VCC): connects to VCC.
  • U1 Pin 10 (GND): connects to 0.
  • U1 Pin 14 (CKA): connects to CLK.
  • U1 Pin 1 (CKB): connects to QA.
  • U1 Pin 2 (MR1): connects to RST.
  • U1 Pin 3 (MR2): connects to RST.
  • U1 Pin 6 (MS1): connects to 0.
  • U1 Pin 7 (MS2): connects to 0.
  • U1 Pin 12 (QA): connects to QA.
  • U1 Pin 9 (QB): connects to QB.
  • U1 Pin 8 (QC): connects to QC.
  • U1 Pin 11 (QD): connects to QD.
  • R2: connects between QA and node N_D1.
  • D1 (QA LED): connects between N_D1 (anode) and 0 (cathode).
  • R3: connects between QB and node N_D2.
  • D2 (QB LED): connects between N_D2 (anode) and 0 (cathode).
  • R4: connects between QC and node N_D3.
  • D3 (QC LED): connects between N_D3 (anode) and 0 (cathode).
  • R5: connects between QD and node N_D4.
  • D4 (QD LED): connects between N_D4 (anode) and 0 (cathode).

Conceptual block diagram

Conceptual block diagram — 74HC90 Decimal counter
Quick read: inputs → main block → output (actuator or measurement). This summarizes the ASCII schematic below.

Schematic

[ VCLK: 1Hz Clock ] ------------------------(CLK)--> [ U1: 74HC90 Decade Counter ] --(QA)--> [ R2: 330 Ω ] --> [ D1: Red LED (LSB) ] --> GND
                                                     [                           ]
[ SW1: Button (VCC) + R1: Pull-down (GND) ] -(RST)-> [ CKA: CLK                  ] --(QB)--> [ R3: 330 Ω ] --> [ D2: Red LED ] --------> GND
                                                     [ MR1, MR2: RST             ]
[ GND ] ------------------------------------(0 V)---> [ MS1, MS2: GND             ] --(QC)--> [ R4: 330 Ω ] --> [ D3: Red LED ] --------> GND
                                                     [ CKB: Connects to QA       ]
                                                     [                           ] --(QD)--> [ R5: 330 Ω ] --> [ D4: Red LED (MSB) ] --> GND
Electrical Schematic

Measurements and tests

  • Clock validation: Monitor the CLK node on an oscilloscope or transient plot to verify a consistent square wave.
  • Counting sequence: Plot QA, QB, QC, and QD simultaneously. Observe that QA toggles on every falling edge of CLK, and that the binary state progresses correctly from 0000 to 1001.
  • BCD Wrap-around: Watch the transition after 1001 (decimal 9). The very next clock pulse should automatically return all outputs (QAQD) back to 0000 (decimal 0) instead of proceeding to 1010 (decimal 10).
  • Manual Reset: While the counter is at any non-zero state (e.g., 0101), actuate SW1. Observe that the RST node spikes to 5 V, forcing QA, QB, QC, and QD to 0000 immediately, ignoring the CLK signal until the button is released.

SPICE netlist and simulation

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

* 0 to 9 BCD Decimal Counter
.width out=256

* Power Supply
V1 VCC 0 DC 5

* Clock Source (1 Hz square wave)
VCLK CLK 0 PULSE(0 5 0 0.01 0.01 0.49 1)

* Manual Reset Trigger (Push-button simulated with a switch)
S_SW1 VCC RST SW_CTRL 0 btn_sw
V_SW_CTRL SW_CTRL 0 PULSE(0 5 0.1 0.01 0.01 0.2 20)
.model btn_sw SW(VT=2.5 RON=1 ROFF=100MEG)

* RST Pull-down Resistor
R1 RST 0 10k

* U1: 74HC90 Decade Counter (Behavioral Subcircuit)
X_U1 CLK QA RST RST 0 0 QA QB QC QD VCC 0 IC_7490

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

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

* 0 to 9 BCD Decimal Counter
.width out=256

* Power Supply
V1 VCC 0 DC 5

* Clock Source (1 Hz square wave)
VCLK CLK 0 PULSE(0 5 0 0.01 0.01 0.49 1)

* Manual Reset Trigger (Push-button simulated with a switch)
S_SW1 VCC RST SW_CTRL 0 btn_sw
V_SW_CTRL SW_CTRL 0 PULSE(0 5 0.1 0.01 0.01 0.2 20)
.model btn_sw SW(VT=2.5 RON=1 ROFF=100MEG)

* RST Pull-down Resistor
R1 RST 0 10k

* U1: 74HC90 Decade Counter (Behavioral Subcircuit)
X_U1 CLK QA RST RST 0 0 QA QB QC QD VCC 0 IC_7490

* LEDs and Current Limiting Resistors
R2 QA N_D1 330
D1 N_D1 0 LED_RED

R3 QB N_D2 330
D2 N_D2 0 LED_RED

R4 QC N_D3 330
D3 N_D3 0 LED_RED

R5 QD N_D4 330
D4 N_D4 0 LED_RED

* Red LED Model
.model LED_RED D(IS=1e-19 N=1.6 RS=2.5)

* --- Subcircuits for 7490 Behavioral Model ---
.subckt IC_7490 CKA CKB MR1 MR2 MS1 MS2 QA QB QC QD VCC GND
* Dummy resistors to prevent floating pins if VCC/GND are unused internally
R_VCC VCC 0 100k
R_GND GND 0 1m

* Internal Reset/Set Logic
B_MR MR_int 0 V = (V(MR1)>2.5) * (V(MR2)>2.5) ? 5 : 0
B_MS MS_int 0 V = (V(MS1)>2.5) * (V(MS2)>2.5) ? 5 : 0
B_RST_bc RST_bc 0 V = ((V(MR_int)>2.5) + (V(MS_int)>2.5)) > 0.5 ? 5 : 0

* Divide-by-2 Section (FFa)
B_Da Da 0 V = V(QA)>2.5 ? 0 : 5
X_FFa CKA Da MR_int MS_int QA DFF_FALL

* Divide-by-5 Section (FFb, FFc, FFd)
B_Db Db 0 V = (V(QD)<2.5) * (V(QB)<2.5) ? 5 : 0
X_FFb CKB Db RST_bc 0 QB DFF_FALL

B_Dc Dc 0 V = ( (V(QB)>2.5)*(V(QC)<2.5) + (V(QB)<2.5)*(V(QC)>2.5) ) > 0.5 ? 5 : 0
X_FFc CKB Dc RST_bc 0 QC DFF_FALL

B_Dd Dd 0 V = (V(QB)>2.5) * (V(QC)>2.5) ? 5 : 0
X_FFd CKB Dd MR_int MS_int QD DFF_FALL
.ends

* Falling Edge Triggered D-Flip-Flop
.subckt DFF_FALL CLK D RST SET Q
B_CLK_B CLKB 0 V = V(CLK)>2.5 ? 0 : 5
X_Master CLK D RST SET QM DLATCH
X_Slave CLKB QM RST SET Q DLATCH
.ends

* Analog D-Latch with Reset and Set Priority
.subckt DLATCH EN D RST SET Q
B_Qnext Qnext 0 V = V(RST)>2.5 ? 0 : ( V(SET)>2.5 ? 5 : ( V(EN)>2.5 ? (V(D)>2.5 ? 5 : 0) : V(Q_int) ) )
R1 Qnext Q_int 100
C1 Q_int 0 10n
R2 Q_int 0 1G
E1 Q 0 Q_int 0 1
.ends
* ---------------------------------------------

* Simulation Commands
.op
.tran 0.01 12 0 1m
.print tran V(CLK) V(QA) V(QB) V(QC) V(QD) V(RST)
.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Analysis: The transient analysis spans 0 s to 12 s and captures the switching interval. Main ranges: v(qa) -9.44 mV -> 5.01 V; v(qb) -8.98 mV -> 5.01 V; v(qc) -8.98 mV -> 5.01 V.
Show raw data table (12301 rows)
Index   time            v(clk)          v(qa)           v(qb)           v(qc)           v(qd)           v(rst)
0	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
1	1.000000e-04	5.000000e-02	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
2	2.000000e-04	1.000000e-01	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
3	4.000000e-04	2.000000e-01	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
4	8.000000e-04	4.000000e-01	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
5	1.600000e-03	8.000000e-01	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
6	2.600000e-03	1.300000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
7	3.600000e-03	1.800000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
8	4.600000e-03	2.300000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
9	5.600000e-03	2.800000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
10	6.310643e-03	3.155321e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
11	6.959607e-03	3.479804e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
12	7.789270e-03	3.894635e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
13	8.789270e-03	4.394635e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
14	9.789270e-03	4.894635e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
15	1.000000e-02	5.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
16	1.010000e-02	5.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
17	1.030000e-02	5.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
18	1.070000e-02	5.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
19	1.150000e-02	5.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
20	1.250000e-02	5.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
21	1.350000e-02	5.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
22	1.450000e-02	5.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
23	1.550000e-02	5.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	4.999500e-04
... (12277 more rows) ...


Reference SPICE netlist (ngspice)

* 0 to 9 BCD Decimal Counter
.width out=256

* Power Supply
V1 VCC 0 DC 5

* Clock Source (1 Hz square wave)
VCLK CLK 0 PULSE(0 5 0 0.01 0.01 0.49 1)

* Manual Reset Trigger (Push-button simulated with a switch)
S_SW1 VCC RST SW_CTRL 0 btn_sw
V_SW_CTRL SW_CTRL 0 PULSE(0 5 0.1 0.01 0.01 0.2 20)
.model btn_sw SW(VT=2.5 RON=1 ROFF=100MEG)

* RST Pull-down Resistor
R1 RST 0 10k

* U1: 74HC90 Decade Counter (Behavioral Subcircuit)
X_U1 CLK QA RST RST 0 0 QA QB QC QD VCC 0 IC_7490

* LEDs and Current Limiting Resistors
R2 QA N_D1 330
D1 N_D1 0 LED_RED

R3 QB N_D2 330
D2 N_D2 0 LED_RED

R4 QC N_D3 330
D3 N_D3 0 LED_RED

R5 QD N_D4 330
D4 N_D4 0 LED_RED

* Red LED Model
.model LED_RED D(IS=1e-19 N=1.6 RS=2.5)

* --- Subcircuits for 7490 Behavioral Model ---
.subckt IC_7490 CKA CKB MR1 MR2 MS1 MS2 QA QB QC QD VCC GND
* Dummy resistors to prevent floating pins if VCC/GND are unused internally
R_VCC VCC 0 100k
R_GND GND 0 1m

* Internal Reset/Set Logic
B_MR MR_int 0 V = (V(MR1)>2.5) * (V(MR2)>2.5) ? 5 : 0
B_MS MS_int 0 V = (V(MS1)>2.5) * (V(MS2)>2.5) ? 5 : 0
B_RST_bc RST_bc 0 V = ((V(MR_int)>2.5) + (V(MS_int)>2.5)) > 0.5 ? 5 : 0

* Divide-by-2 Section (FFa)
B_Da Da 0 V = V(QA)>2.5 ? 0 : 5
X_FFa CKA Da MR_int MS_int QA DFF_FALL

* Divide-by-5 Section (FFb, FFc, FFd)
B_Db Db 0 V = (V(QD)2.5)*(V(QC)2.5) ) > 0.5 ? 5 : 0
X_FFc CKB Dc RST_bc 0 QC DFF_FALL

B_Dd Dd 0 V = (V(QB)>2.5) * (V(QC)>2.5) ? 5 : 0
X_FFd CKB Dd MR_int MS_int QD DFF_FALL
.ends

* Falling Edge Triggered D-Flip-Flop
.subckt DFF_FALL CLK D RST SET Q
B_CLK_B CLKB 0 V = V(CLK)>2.5 ? 0 : 5
X_Master CLK D RST SET QM DLATCH
X_Slave CLKB QM RST SET Q DLATCH
.ends

* Analog D-Latch with Reset and Set Priority
.subckt DLATCH EN D RST SET Q
B_Qnext Qnext 0 V = V(RST)>2.5 ? 0 : ( V(SET)>2.5 ? 5 : ( V(EN)>2.5 ? (V(D)>2.5 ? 5 : 0) : V(Q_int) ) )
R1 Qnext Q_int 100
C1 Q_int 0 10n
R2 Q_int 0 1G
E1 Q 0 Q_int 0 1
.ends
* ---------------------------------------------

* Simulation Commands
.op
.tran 0.01 12 0 1m
.print tran V(CLK) V(QA) V(QB) V(QC) V(QD) V(RST)
.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Analysis: The transient analysis spans 0 s to 12 s and captures the switching interval. Main ranges: v(qa) -9.44 mV -> 5.01 V; v(qb) -8.98 mV -> 5.01 V; v(qc) -8.98 mV -> 5.01 V.

Common mistakes and how to avoid them

  • Forgetting to connect QA to CKB: The 74HC90 is internally split into a divide-by-2 and a divide-by-5 section. If you do not bridge pin 12 (QA) to pin 1 (CKB), the IC will only count from 0 to 1 and stop, or will not generate the proper BCD sequence.
  • Leaving reset pins floating: CMOS logic inputs (like the 74HC series) must never be left disconnected. Leaving MS1, MS2, or the MR pins floating will cause the counter to randomly reset due to ambient electrical noise. Ensure they are tied firmly to 0 or managed via a pull-down resistor.
  • Swapping the output bits: Reading the LEDs in the wrong order is very common. Always remember that QA is the Least Significant Bit (LSB, toggles fastest) and QD is the Most Significant Bit (MSB, toggles slowest).


Troubleshooting

  • Symptom: All LEDs remain entirely off, and the counter never advances.
    • Cause: The Master Reset (MR1 and MR2) or Master Set (MS1 and MS2) pins might be receiving a logic HIGH.
    • Fix: Check that SW1 is not stuck closed, ensure R1 (pull-down) is properly connected to ground, and verify MS1/MS2 are wired directly to 0.
  • Symptom: The counter counts wildly or skips numbers unexpectedly.
    • Cause: The clock signal (CLK) lacks debouncing, or there is missing power supply decoupling.
    • Fix: If using a mechanical switch for a clock instead of a clean generator, add a hardware debounce circuit (RC + Schmitt trigger). Additionally, place a 100 nF capacitor directly between VCC and GND near the IC.
  • Symptom: The count goes up to 5 and resets (0, 1, 2, 3, 4, 0…).
    • Cause: The clock inputs are wired backwards. The clock is entering CKB and cascading into CKA.
    • Fix: Ensure the external clock goes exclusively to CKA (pin 14) and QA bridges to CKB (pin 1).

Possible improvements and extensions

  • Cascade for 0-99 counting: Add a second 74HC90 IC. Take the QD output of the first stage and feed it into the CKA input of the second stage to create a two-digit decimal counter.
  • 7-Segment Display integration: Remove the discrete LEDs and connect QA, QB, QC, and QD into a BCD-to-7-segment decoder IC (like the 74HC47 or CD4511) to display true decimal numerals on a digital display.

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: Which IC is used to build the decade BCD counter in this project?




Question 2: What is the decimal counting range of the BCD counter described in the article?




Question 3: What is the maximum binary value displayed by the LEDs before the counter automatically resets?




Question 4: Which LED indicator will toggle the fastest during the binary progression?




Question 5: What happens to the circuit when the manual reset button is pressed?




Question 6: What will the transient validation show in this circuit?




Question 7: This circuit helps in understanding frequency dividers of what specific type?




Question 8: Which LED indicator will toggle the slowest during the binary progression?




Question 9: Which of the following is a real-world application for this counter circuit mentioned in the text?




Question 10: Who is the primary target audience for this project?




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: 0-9 counter with TTL-compatible reset

0-9 counter with TTL-compatible reset prototype (Maker Style)

Level: Medium — Build a decimal counter that advances from 0 to 9 and resets automatically using a TTL-compatible AND gate.

Objective and use case

You will build a decimal counter based on a 74LS93 ripple counter and a 74HCT08 AND gate. The circuit counts from 0000 to 1001 and automatically resets when 1010 appears.

This is useful for:
– Simple event counters with a decimal display interface
– Clock divider stages for timing experiments
– Learning how asynchronous reset works in ripple counters
– Testing TTL-to-CMOS/HCT logic compatibility in mixed logic designs

Expected outcome:
QA, QB, QC, and QD show a binary count sequence from 0 to 9
RESET_NODE goes HIGH only when QB = 1 and QD = 1
– The counter clears immediately when state 1010 is reached
– LEDs on the four outputs visibly repeat the decimal cycle
– Logic supply remains at +5 V, with TTL-compatible levels between the 74LS93 and 74HCT08

Target audience and level: Students and technicians with basic digital electronics experience.

Materials

  • U1: 74LS93 4-bit ripple counter, function: binary count generation
  • U2: 74HCT08 quad 2-input AND gate, function: TTL-compatible reset detection
  • V1: 5 V DC supply, function: power for the logic circuit
  • X1: clock source 0-5 V square wave, function: CLK_IN signal
  • D1: red LED, function: QA indicator
  • D2: red LED, function: QB indicator
  • D3: red LED, function: QC indicator
  • D4: red LED, function: QD indicator
  • R1: 330 Ω resistor, function: current limiting for D1
  • R2: 330 Ω resistor, function: current limiting for D2
  • R3: 330 Ω resistor, function: current limiting for D3
  • R4: 330 Ω resistor, function: current limiting for D4
  • C1: 100 nF capacitor, function: local decoupling for U1
  • C2: 100 nF capacitor, function: local decoupling for U2

Pin-out of the IC used

74LS93

Pin Name Logic function Connection in this case
5 VCC +5 V supply VCC
10 GND Ground 0
14 CP0 Clock input A CLK_IN
1 CP1 Clock input B Connected to QA for cascade
2 R0(1) Asynchronous reset input RESET_NODE
3 R0(2) Asynchronous reset input RESET_NODE
12 QA LSB output QA, LED D1, and feedback to CP1
9 QB Counter output QB, LED D2, and reset detect input
8 QC Counter output QC, LED D3
11 QD MSB output QD, LED D4, and reset detect input

74HCT08

Pin Name Logic function Connection in this case
14 VCC +5 V supply VCC
7 GND Ground 0
1 1 A AND input A QB
2 1B AND input B QD
3 1Y AND output RESET_NODE

Wiring guide

  • V1 connects between VCC and 0.
  • C1 connects between VCC and 0, placed close to U1.
  • C2 connects between VCC and 0, placed close to U2.

  • U1 pin 5 connects to VCC.

  • U1 pin 10 connects to 0.
  • U1 pin 14 connects to CLK_IN.
  • U1 pin 1 connects to node QA.
  • U1 pin 2 connects to RESET_NODE.
  • U1 pin 3 connects to RESET_NODE.
  • U1 pin 12 connects to node QA.
  • U1 pin 9 connects to node QB.
  • U1 pin 8 connects to node QC.
  • U1 pin 11 connects to node QD.

  • U2 pin 14 connects to VCC.

  • U2 pin 7 connects to 0.
  • U2 pin 1 connects to node QB.
  • U2 pin 2 connects to node QD.
  • U2 pin 3 connects to node RESET_NODE.

  • R1 connects between QA and node LED1_A.

  • D1 connects between LED1_A and 0.
  • R2 connects between QB and node LED2_A.
  • D2 connects between LED2_A and 0.
  • R3 connects between QC and node LED3_A.
  • D3 connects between LED3_A and 0.
  • R4 connects between QD and node LED4_A.
  • D4 connects between LED4_A and 0.

Use the 74HCT08, not the 74HC08, because the reset gate is driven by 74LS93 TTL outputs and must accept TTL-compatible HIGH levels reliably.

Conceptual block diagram

Conceptual block diagram — CONTADOR 0-9 counter with reset
Quick read: inputs → main block → output (actuator or measurement). This summarizes the ASCII schematic below.

Schematic

Practical case: 0-9 counter with TTL-compatible reset (74LS93 + 74HCT08)

[ X1: CLK_IN 0-5 V square ] --> [ U1: 74LS93 4-bit Ripple Counter (CP0 pin14) ]
(Internal to U1: QA (pin12) --> CP1 (pin1) for divide-by-10 configuration)

U1 Q outputs to indicators (loads on the right):
[ U1: QA (pin12) ] --> [ R1: 330 Ω ] --> [ D1: Red LED ] --> GND
[ U1: QB (pin9)  ] --> [ R2: 330 Ω ] --> [ D2: Red LED ] --> GND
[ U1: QC (pin8)  ] --> [ R3: 330 Ω ] --> [ D3: Red LED ] --> GND
[ U1: QD (pin11) ] --> [ R4: 330 Ω ] --> [ D4: Red LED ] --> GND

Reset detection (separate branches; TTL-compatible gate):
[ Tap: U1.QB (pin9) ] -->
[ Tap: U1.QD (pin11) ] --> [ U2: 74HCT08 AND (pins 1,2→3) ] --(RESET_NODE)--> (to U1 Async Reset R0(1),R0(2) pins 2 & 3)

Power and decoupling (for completeness):
[ V1: +5 V ] --> [ U1: VCC pin5 ]          ; return GND --> (U1 GND pin10)
[ V1: +5 V ] --> [ U2: VCC pin14 ]         ; return GND --> (U2 GND pin7)
[ C1: 100 nF ] between U1 VCC and GND (place close to U1)
[ C2: 100 nF ] between U2 VCC and GND (place close to U2)
Electrical Schematic

Electrical diagram

Electrical diagram for case: Practical case: 0-9 counter with TTL-compatible reset
Generated from the validated SPICE netlist for this case.

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

Truth table

This table corresponds to the AND gate used for reset detection.

QB QD RESET_NODE
0 0 0
0 1 0
1 0 0
1 1 1

Measurements and tests

  1. Power-off continuity check
  2. Verify VCC is not shorted to 0.
  3. Confirm U1 reset pins 2 and 3 are tied together at RESET_NODE.
  4. Confirm U1 pin 1 is connected to QA.

  5. Power-on static check

  6. Apply +5 V.
  7. Check that U1 and U2 both receive correct supply voltage.
  8. With no clock applied, outputs may start in an unknown state; a brief manual reset to RESET_NODE = HIGH should force QA QB QC QD = 0000.

  9. Clock verification

  10. Measure CLK_IN with an oscilloscope.
  11. Use a slow frequency such as 1 Hz to 10 Hz for visual LED observation.
  12. Confirm the clock swings approximately from 0 V to 5 V.

  13. Counter sequence check

  14. Measure QA, QB, QC, and QD.
  15. Verify the sequence:
    • 0000
    • 0001
    • 0010
    • 0011
    • 0100
    • 0101
    • 0110
    • 0111
    • 1000
    • 1001
  16. The next attempted state is 1010, but it must reset immediately to 0000.

  17. Reset-node validation

  18. Measure RESET_NODE.
  19. It should remain LOW for counts 0000 through 1001.
  20. It should pulse HIGH when QB = 1 and QD = 1, which corresponds to detection of 1010.

  21. LED observation

  22. D1 must toggle at the highest visible rate.
  23. D2 toggles at half the QA rate.
  24. D3 and D4 toggle progressively slower.
  25. The visible pattern must repeat every 10 clock pulses.

SPICE netlist and simulation

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

* Practical case: Decade counter 0-9 with reset (Corrected)
.width out=256
* Fixed Impedance and Timing issues for 74LS93 ripple counter
* Ngspice compliant netlist

* --- COMPONENT MODELS ---
* Generic Red LED Model
.model DLED D(IS=1e-14 N=1.7 RS=10 BV=5 IBV=10u CJO=10p)

* --- LOGIC GATE SUBCIRCUITS (Behavioral with Low Impedance Output) ---
* IMPORTANT: Output Impedance reduced to 50 ohms to drive LEDs and avoid loading effects.
* Delays (C1=10p) maintained for convergence and latch feedback.

* Inverter (Standard Delay ~500ps)
.subckt INV A Y VCC GND
B1 Y_int 0 V = V(VCC) * (1 / (1 + exp(20 * (V(A) - 2.5))))
R1 Y_int Y 50
C1 Y 0 10p
.ends

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

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

🔒 Part of this section is premium. With the monthly membership (7-day free trial) 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: Decade counter 0-9 with reset (Corrected)
.width out=256
* Fixed Impedance and Timing issues for 74LS93 ripple counter
* Ngspice compliant netlist

* --- COMPONENT MODELS ---
* Generic Red LED Model
.model DLED D(IS=1e-14 N=1.7 RS=10 BV=5 IBV=10u CJO=10p)

* --- LOGIC GATE SUBCIRCUITS (Behavioral with Low Impedance Output) ---
* IMPORTANT: Output Impedance reduced to 50 ohms to drive LEDs and avoid loading effects.
* Delays (C1=10p) maintained for convergence and latch feedback.

* Inverter (Standard Delay ~500ps)
.subckt INV A Y VCC GND
B1 Y_int 0 V = V(VCC) * (1 / (1 + exp(20 * (V(A) - 2.5))))
R1 Y_int Y 50
C1 Y 0 10p
.ends

* Fast Inverter (Minimal Delay ~5ps) - Used for Clock Edge logic to prevent races
.subckt INV_FAST A Y VCC GND
B1 Y_int 0 V = V(VCC) * (1 / (1 + exp(20 * (V(A) - 2.5))))
R1 Y_int Y 50
C1 Y 0 0.1p
.ends

* 2-Input NAND
.subckt NAND2 A B Y VCC GND
B1 Y_int 0 V = V(VCC) * (1 - ( (1/(1+exp(-20*(V(A)-2.5)))) * (1/(1+exp(-20*(V(B)-2.5)))) ))
R1 Y_int Y 50
C1 Y 0 10p
.ends

* 3-Input NAND
.subckt NAND3 A B C Y VCC GND
B1 Y_int 0 V = V(VCC) * (1 - ( (1/(1+exp(-20*(V(A)-2.5)))) * (1/(1+exp(-20*(V(B)-2.5)))) * (1/(1+exp(-20*(V(C)-2.5)))) ))
R1 Y_int Y 50
C1 Y 0 10p
.ends

* 2-Input AND
.subckt AND2 A B Y VCC GND
B1 Y_int 0 V = V(VCC) * ( (1/(1+exp(-20*(V(A)-2.5)))) * (1/(1+exp(-20*(V(B)-2.5)))) )
R1 Y_int Y 50
C1 Y 0 10p
.ends

* --- FLIP-FLOP SUBCIRCUIT ---
* T-FlipFlop: Negative Edge Triggered with Active High Clear
* Uses INV_FAST for clock inversion to ensure Master-Slave non-overlap (Race Fix).
.subckt TFF_NEG_CLR CLK CLR Q QBAR VCC GND
* Invert Clear
XINV_CLR CLR CLR_BAR VCC GND INV

* Invert Clock FAST (Avoids race where both Master and Slave are transparent)
XINV_CLK CLK CLK_BAR VCC GND INV_FAST

* -- Master Latch (Tracks D=QBAR when CLK=1) --
XG1 QBAR CLK M_SET_BAR VCC GND NAND2
XG2 Q CLK CLR_BAR M_RST_BAR VCC GND NAND3
XL1 M_SET_BAR M_QBAR M_Q VCC GND NAND2
XL2 M_RST_BAR M_Q CLR_BAR M_QBAR VCC GND NAND3

* -- Slave Latch (Tracks Master when CLK=0 -> CLK_BAR=1) --
* Uses CLK_BAR which is delayed only slightly less than gates, ensuring clean handover.
XG3 M_Q CLK_BAR S_SET_BAR VCC GND NAND2
XG4 M_QBAR CLK_BAR S_RST_BAR VCC GND NAND2
XL3 S_SET_BAR QBAR Q VCC GND NAND2
XL4 S_RST_BAR Q CLR_BAR QBAR VCC GND NAND3
.ends

* --- IC SUBCIRCUITS ---

* U1: 74LS93 4-Bit Binary Counter
* Pinout mapping adjusted to match standard 14-pin DIP in netlist order:
* 1=IN_B, 2=R0(1), 3=R0(2), 5=VCC, 8=QC, 9=QB, 10=GND, 11=QD, 12=QA, 14=IN_A
.subckt 74LS93 IN_B R0_1 R0_2 VCC QC QB GND QD QA IN_A
* Internal Reset Logic: Reset if R0_1 AND R0_2 are High
XAND_RST R0_1 R0_2 RESET VCC GND AND2

* Section 1: 1-bit counter (Input A -> QA)
XFFA IN_A RESET QA QA_BAR VCC GND TFF_NEG_CLR

* Section 2: 3-bit ripple counter (Input B -> QB -> QC -> QD)
XFFB IN_B RESET QB QB_BAR VCC GND TFF_NEG_CLR
XFFC QB RESET QC QC_BAR VCC GND TFF_NEG_CLR
XFFD QC RESET QD QD_BAR VCC GND TFF_NEG_CLR
.ends

* U2: 74HCT08 Quad 2-Input AND Gate
* HCT input thresholds are TTL-compatible, so 74LS93 HIGH outputs
* reliably drive the reset-detect gate in a real classroom build.
* Pins: 1=1A, 2=1B, 3=1Y, 7=GND, 14=VCC
.subckt 74HCT08 1A 1B 1Y GND VCC
XG1 1A 1B 1Y VCC GND AND2
.ends

* --- MAIN CIRCUIT ---

* 1. Power Supply
V1 VCC 0 DC 5

* 2. Clock Signal (50kHz)
V2 CLK_IN 0 PULSE(0 5 1u 100n 100n 10u 20u)

* 3. U1: 74LS93 Counter
* Wiring Guide connections:
* Pin 1 (CKB) connects to QA_NODE (Cascade)
* Pin 12 (QA) connects to QA_NODE
* Pin 14 (CKA) connects to CLK_IN
* Pin 2, 3 connect to RESET_NODE
* Outputs to LEDs
XU1 QA_NODE RESET_NODE RESET_NODE VCC QC_NODE QB_NODE 0 QD_NODE QA_NODE CLK_IN 74LS93

* 4. U2: 74HCT08 Reset Logic
* Reset when Count=10 (Binary 1010 -> QD=1, QB=1)
* Inputs: QB_NODE, QD_NODE -> Output: RESET_NODE
XU2 QB_NODE QD_NODE RESET_NODE 0 VCC 74HCT08

* 5. LED Indicators (with Current Limiting Resistors)
* Bit 0 (QA)
R1 QA_NODE N_D1 330
D1 N_D1 0 DLED

* Bit 1 (QB)
R2 QB_NODE N_D2 330
D2 N_D2 0 DLED

* Bit 2 (QC)
R3 QC_NODE N_D3 330
D3 N_D3 0 DLED

* Bit 3 (QD)
R4 QD_NODE N_D4 330
D4 N_D4 0 DLED

* --- SIMULATION COMMANDS ---
.op
* Transient analysis: 500us to see counts 0-9 and reset
.tran 100n 500u

* Print essential nodes. CLK_IN first.
.print tran V(CLK_IN) V(QA_NODE) V(QB_NODE) V(QC_NODE) V(QD_NODE) V(RESET_NODE)

.end
* --- GPT review (BOM/Wiring/SPICE) ---
* circuit_ok=true
* simulation_summary: The simulation successfully demonstrates a 4-bit counting sequence. The counter increments on the falling edge of the clock. The reset logic triggers correctly when the count reaches 10 (Binary 1010: QD=High, QB=High), forcing the outputs back to 0 immediately, effectively creating a 0-9 decade counter.
* bom_vs_spice equivalences ignored:
*   - Clock source V2 modeled as a PULSE voltage source.
*   - LEDs (D1-D4) modeled as generic diodes with specific parameters (DLED).
*   - U1 (74LS93) modeled as a behavioral subcircuit using flip-flops and logic gates.
*   - U2 (74HCT08) modeled as a behavioral subcircuit using AND gates.
* overall_comment: The circuit is well-designed and the SPICE netlist accurately reflects the intended decade counter logic. The behavioral models for the 74LS93 and 74HCT08 are robust, including necessary delays to prevent race conditions. The simulation logs confirm the modulo-10 reset operation works as expected. This is a solid didactic example.
* --------------------------------------

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Analysis: The simulation successfully demonstrates a 4-bit counting sequence. The counter increments on the falling edge of the clock. The reset logic triggers correctly when the count reaches 10 (Binary 1010: QD=High, QB=High), forcing the outputs back to 0 immediately, effectively creating a 0-9 decade counter.
Show raw data table (6785 rows)
Index   time            v(clk_in)       v(qa_node)      v(qb_node)      v(qc_node)      v(qd_node)      v(reset_node)
0	0.000000e+00	0.000000e+00	-7.27413e-30	4.514570e+00	-7.27413e-30	-7.27411e-30	9.643749e-22
1	1.000000e-09	0.000000e+00	-6.24961e-30	4.514570e+00	-6.24960e-30	-6.24960e-30	9.643749e-22
2	2.000000e-09	0.000000e+00	-4.31599e-30	4.514570e+00	-4.31599e-30	-4.31599e-30	9.643749e-22
3	4.000000e-09	0.000000e+00	-8.63940e-32	4.514570e+00	-8.63867e-32	-8.63940e-32	9.643749e-22
4	8.000000e-09	0.000000e+00	6.051302e-30	4.514570e+00	6.051309e-30	6.051302e-30	9.643749e-22
5	1.600000e-08	0.000000e+00	8.619372e-30	4.514570e+00	8.619381e-30	8.619372e-30	9.643749e-22
6	3.200000e-08	0.000000e+00	4.420001e-30	4.514570e+00	4.420001e-30	4.419984e-30	9.643749e-22
7	6.400000e-08	0.000000e+00	-8.88725e-31	4.514570e+00	-8.88725e-31	-8.88708e-31	9.643749e-22
8	1.280000e-07	0.000000e+00	-1.16882e-30	4.514570e+00	-1.16881e-30	-1.16884e-30	9.643749e-22
9	2.280000e-07	0.000000e+00	-1.70113e-31	4.514570e+00	-1.70131e-31	-1.70113e-31	9.643749e-22
10	3.280000e-07	0.000000e+00	1.102262e-31	4.514570e+00	1.101893e-31	1.102078e-31	9.643749e-22
11	4.280000e-07	0.000000e+00	-2.09740e-32	4.514570e+00	-2.09440e-32	-2.09556e-32	9.643749e-22
12	5.280000e-07	0.000000e+00	3.730926e-32	4.514570e+00	3.729081e-32	3.729081e-32	9.643749e-22
13	6.280000e-07	0.000000e+00	-4.04764e-32	4.514570e+00	-4.04464e-32	-4.04395e-32	9.643749e-22
14	7.280000e-07	0.000000e+00	3.793658e-32	4.514570e+00	3.789968e-32	3.791813e-32	9.643749e-22
15	8.280000e-07	0.000000e+00	-3.71737e-32	4.514570e+00	-3.71437e-32	-3.71552e-32	9.643749e-22
16	9.280000e-07	0.000000e+00	3.658968e-32	4.514570e+00	3.657123e-32	3.658968e-32	9.643749e-22
17	1.000000e-06	0.000000e+00	-3.53679e-32	4.514570e+00	-3.53610e-32	-3.53496e-32	9.643749e-22
18	1.010000e-06	5.000000e-01	-2.79091e-33	4.514570e+00	-2.80820e-33	-2.79091e-33	9.643749e-22
19	1.030000e-06	1.500000e+00	1.602683e-33	4.514570e+00	1.585385e-33	1.602683e-33	9.643749e-22
20	1.048757e-06	2.437856e+00	4.312441e+00	4.514570e+00	-1.25584e-33	-1.27306e-33	9.643749e-22
21	1.062135e-06	3.106726e+00	4.691659e+00	4.514570e+00	1.096887e-33	1.103161e-33	9.643749e-22
22	1.071814e-06	3.590675e+00	4.366639e+00	4.514570e+00	-8.23695e-34	-8.33794e-34	9.643749e-22
23	1.080871e-06	4.043525e+00	4.636207e+00	4.514570e+00	6.872047e-34	7.032322e-34	9.643749e-22
... (6761 more rows) ...


Reference SPICE netlist (ngspice)

* Practical case: Decade counter 0-9 with reset (Corrected)
.width out=256
* Fixed Impedance and Timing issues for 74LS93 ripple counter
* Ngspice compliant netlist

* --- COMPONENT MODELS ---
* Generic Red LED Model
.model DLED D(IS=1e-14 N=1.7 RS=10 BV=5 IBV=10u CJO=10p)

* --- LOGIC GATE SUBCIRCUITS (Behavioral with Low Impedance Output) ---
* IMPORTANT: Output Impedance reduced to 50 ohms to drive LEDs and avoid loading effects.
* Delays (C1=10p) maintained for convergence and latch feedback.

* Inverter (Standard Delay ~500ps)
.subckt INV A Y VCC GND
B1 Y_int 0 V = V(VCC) * (1 / (1 + exp(20 * (V(A) - 2.5))))
R1 Y_int Y 50
C1 Y 0 10p
.ends

* Fast Inverter (Minimal Delay ~5ps) - Used for Clock Edge logic to prevent races
.subckt INV_FAST A Y VCC GND
B1 Y_int 0 V = V(VCC) * (1 / (1 + exp(20 * (V(A) - 2.5))))
R1 Y_int Y 50
C1 Y 0 0.1p
.ends

* 2-Input NAND
.subckt NAND2 A B Y VCC GND
B1 Y_int 0 V = V(VCC) * (1 - ( (1/(1+exp(-20*(V(A)-2.5)))) * (1/(1+exp(-20*(V(B)-2.5)))) ))
R1 Y_int Y 50
C1 Y 0 10p
.ends

* 3-Input NAND
.subckt NAND3 A B C Y VCC GND
B1 Y_int 0 V = V(VCC) * (1 - ( (1/(1+exp(-20*(V(A)-2.5)))) * (1/(1+exp(-20*(V(B)-2.5)))) * (1/(1+exp(-20*(V(C)-2.5)))) ))
R1 Y_int Y 50
C1 Y 0 10p
.ends

* 2-Input AND
.subckt AND2 A B Y VCC GND
B1 Y_int 0 V = V(VCC) * ( (1/(1+exp(-20*(V(A)-2.5)))) * (1/(1+exp(-20*(V(B)-2.5)))) )
R1 Y_int Y 50
C1 Y 0 10p
.ends

* --- FLIP-FLOP SUBCIRCUIT ---
* T-FlipFlop: Negative Edge Triggered with Active High Clear
* Uses INV_FAST for clock inversion to ensure Master-Slave non-overlap (Race Fix).
.subckt TFF_NEG_CLR CLK CLR Q QBAR VCC GND
* Invert Clear
XINV_CLR CLR CLR_BAR VCC GND INV

* Invert Clock FAST (Avoids race where both Master and Slave are transparent)
XINV_CLK CLK CLK_BAR VCC GND INV_FAST

* -- Master Latch (Tracks D=QBAR when CLK=1) --
XG1 QBAR CLK M_SET_BAR VCC GND NAND2
XG2 Q CLK CLR_BAR M_RST_BAR VCC GND NAND3
XL1 M_SET_BAR M_QBAR M_Q VCC GND NAND2
XL2 M_RST_BAR M_Q CLR_BAR M_QBAR VCC GND NAND3

* -- Slave Latch (Tracks Master when CLK=0 -> CLK_BAR=1) --
* Uses CLK_BAR which is delayed only slightly less than gates, ensuring clean handover.
XG3 M_Q CLK_BAR S_SET_BAR VCC GND NAND2
XG4 M_QBAR CLK_BAR S_RST_BAR VCC GND NAND2
XL3 S_SET_BAR QBAR Q VCC GND NAND2
XL4 S_RST_BAR Q CLR_BAR QBAR VCC GND NAND3
.ends

* --- IC SUBCIRCUITS ---

* U1: 74LS93 4-Bit Binary Counter
* Pinout mapping adjusted to match standard 14-pin DIP in netlist order:
* 1=IN_B, 2=R0(1), 3=R0(2), 5=VCC, 8=QC, 9=QB, 10=GND, 11=QD, 12=QA, 14=IN_A
.subckt 74LS93 IN_B R0_1 R0_2 VCC QC QB GND QD QA IN_A
* Internal Reset Logic: Reset if R0_1 AND R0_2 are High
XAND_RST R0_1 R0_2 RESET VCC GND AND2

* Section 1: 1-bit counter (Input A -> QA)
XFFA IN_A RESET QA QA_BAR VCC GND TFF_NEG_CLR

* Section 2: 3-bit ripple counter (Input B -> QB -> QC -> QD)
XFFB IN_B RESET QB QB_BAR VCC GND TFF_NEG_CLR
XFFC QB RESET QC QC_BAR VCC GND TFF_NEG_CLR
XFFD QC RESET QD QD_BAR VCC GND TFF_NEG_CLR
.ends

* U2: 74HCT08 Quad 2-Input AND Gate
* HCT input thresholds are TTL-compatible, so 74LS93 HIGH outputs
* reliably drive the reset-detect gate in a real classroom build.
* Pins: 1=1A, 2=1B, 3=1Y, 7=GND, 14=VCC
.subckt 74HCT08 1A 1B 1Y GND VCC
XG1 1A 1B 1Y VCC GND AND2
.ends

* --- MAIN CIRCUIT ---

* 1. Power Supply
V1 VCC 0 DC 5

* 2. Clock Signal (50kHz)
V2 CLK_IN 0 PULSE(0 5 1u 100n 100n 10u 20u)

* 3. U1: 74LS93 Counter
* Wiring Guide connections:
* Pin 1 (CKB) connects to QA_NODE (Cascade)
* Pin 12 (QA) connects to QA_NODE
* Pin 14 (CKA) connects to CLK_IN
* Pin 2, 3 connect to RESET_NODE
* Outputs to LEDs
XU1 QA_NODE RESET_NODE RESET_NODE VCC QC_NODE QB_NODE 0 QD_NODE QA_NODE CLK_IN 74LS93

* 4. U2: 74HCT08 Reset Logic
* Reset when Count=10 (Binary 1010 -> QD=1, QB=1)
* Inputs: QB_NODE, QD_NODE -> Output: RESET_NODE
XU2 QB_NODE QD_NODE RESET_NODE 0 VCC 74HCT08

* 5. LED Indicators (with Current Limiting Resistors)
* Bit 0 (QA)
R1 QA_NODE N_D1 330
D1 N_D1 0 DLED

* Bit 1 (QB)
R2 QB_NODE N_D2 330
D2 N_D2 0 DLED

* Bit 2 (QC)
R3 QC_NODE N_D3 330
D3 N_D3 0 DLED

* Bit 3 (QD)
R4 QD_NODE N_D4 330
D4 N_D4 0 DLED

* --- SIMULATION COMMANDS ---
.op
* Transient analysis: 500us to see counts 0-9 and reset
.tran 100n 500u

* Print essential nodes. CLK_IN first.
.print tran V(CLK_IN) V(QA_NODE) V(QB_NODE) V(QC_NODE) V(QD_NODE) V(RESET_NODE)

.end
* --- GPT review (BOM/Wiring/SPICE) ---
* circuit_ok=true
* simulation_summary: The simulation successfully demonstrates a 4-bit counting sequence. The counter increments on the falling edge of the clock. The reset logic triggers correctly when the count reaches 10 (Binary 1010: QD=High, QB=High), forcing the outputs back to 0 immediately, effectively creating a 0-9 decade counter.
* bom_vs_spice equivalences ignored:
*   - Clock source V2 modeled as a PULSE voltage source.
*   - LEDs (D1-D4) modeled as generic diodes with specific parameters (DLED).
*   - U1 (74LS93) modeled as a behavioral subcircuit using flip-flops and logic gates.
*   - U2 (74HCT08) modeled as a behavioral subcircuit using AND gates.
* overall_comment: The circuit is well-designed and the SPICE netlist accurately reflects the intended decade counter logic. The behavioral models for the 74LS93 and 74HCT08 are robust, including necessary delays to prevent race conditions. The simulation logs confirm the modulo-10 reset operation works as expected. This is a solid didactic example.
* --------------------------------------

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Analysis: The simulation successfully demonstrates a 4-bit counting sequence. The counter increments on the falling edge of the clock. The reset logic triggers correctly when the count reaches 10 (Binary 1010: QD=High, QB=High), forcing the outputs back to 0 immediately, effectively creating a 0-9 decade counter.

Common mistakes and how to avoid them

  1. Using 74HC08 instead of 74HCT08
  2. Problem: the 74LS93 HIGH level may not meet standard HC input thresholds reliably.
  3. Solution: use 74HCT08 for TTL-compatible input levels.

  4. Forgetting the QA to CP1 connection

  5. Problem: the 74LS93 will not count correctly through the intended 4-bit sequence.
  6. Solution: connect U1 pin 12 (QA) directly to U1 pin 1 (CP1).

  7. Reset inputs not tied together

  8. Problem: the counter may not clear when 1010 occurs.
  9. Solution: connect both R0(1) and R0(2) to the same RESET_NODE.

Troubleshooting

  • Symptom: The count goes beyond 9.
  • Cause: QB or QD is not correctly connected to the AND gate.
  • Fix: verify U2 pin 1 = QB, U2 pin 2 = QD, and U2 pin 3 = RESET_NODE.

  • Symptom: The circuit never counts.

  • Cause: RESET_NODE is stuck HIGH.
  • Fix: check for miswiring, shorts, or swapped AND gate pins.

  • Symptom: LEDs behave randomly at power-up.

  • Cause: ripple counters can power up in an undefined state.
  • Fix: apply a short reset pulse at startup.

  • Symptom: Reset is unreliable.

  • Cause: wrong logic family used for the reset gate.
  • Fix: replace any 74HC08 with 74HCT08.

  • Symptom: Only the first stage toggles.

  • Cause: missing cascade connection from QA to CP1.
  • Fix: reconnect U1 pin 12 to U1 pin 1.

Possible improvements and extensions

  • Add a BCD-to-7-segment decoder and display so the count is shown directly as digits 0 to 9.
  • Replace the clock source with a debounced push-button for manual stepping and observation of each state.

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 main purpose of adding the 74HCT08 to the 74LS93 counter circuit?




Question 2: Which count sequence should the outputs QA, QB, QC, and QD display before repeating?




Question 3: At which binary state should the counter reset automatically?




Question 4: When does RESET_NODE go HIGH in this design?




Question 5: What supply voltage is specified for the logic circuit?




Question 6: Why is the 74HCT08 suitable in this mixed-logic circuit?




Question 7: What is the role of the 74LS93 in the circuit?




Question 8: What is the function of the four LEDs connected to QA, QB, QC, and QD?




Question 9: What type of reset behavior is being demonstrated in this counter?




Question 10: Which application is mentioned as a use case for this decimal counter?




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: Conveyor belt object counter

Conveyor belt object counter prototype (Maker Style)

Level: Medium – Build an optical object counter with decimal outputs and an automatic batch reset.

Objective and use case

In this practical case, you will build a sequential optical counting circuit using a Light Dependent Resistor (LDR), a 74HC04 inverter for signal conditioning, and a CD4017BE decade counter. The circuit detects objects breaking a light beam, counts them sequentially using LED indicators, and automatically resets after a batch of 5 items.

This circuit is highly relevant in real-world scenarios:
Packaging lines: Automatically grouping products into predetermined batch sizes (e.g., 5 items per box).
Industrial automation: Tracking the movement of discrete parts along a conveyor belt.
Safety interlocks: Monitoring limit switches or optical barriers to ensure an operation cycle is fully completed.

Expected outcome:
– The LDR voltage divider will swing from HIGH (illuminated) to LOW (beam blocked).
– The 74HC04 inverter will generate a clean, rising clock edge (VB) upon each detection.
– The CD4017BE counter will advance its active logic HIGH signal across outputs Q0 to Q4, lighting up LEDs in sequence.
– When the 6th object is detected (count of 5), output Q5 will trigger the reset pin, instantaneously clearing the count back to 0.

Target audience: Electronics students learning sequential logic, decimal counters, and basic sensor integration.

Materials

  • V1: 5 V DC supply
  • RLDR1: Light Dependent Resistor (LDR), function: optical sensing
  • R1: 10 kΩ resistor, function: voltage divider pull-down for LDR
  • U1: 74HC04, function: logic inverter and clock edge sharpener
  • U2: CD4017BE, function: decade counter with decoded outputs
  • D1: red LED, function: count 0 indicator
  • D2: red LED, function: count 1 indicator
  • D3: red LED, function: count 2 indicator
  • D4: red LED, function: count 3 indicator
  • D5: red LED, function: count 4 indicator
  • R2: 330 Ω resistor, function: LED D1 current limiting
  • R3: 330 Ω resistor, function: LED D2 current limiting
  • R4: 330 Ω resistor, function: LED D3 current limiting
  • R5: 330 Ω resistor, function: LED D4 current limiting
  • R6: 330 Ω resistor, function: LED D5 current limiting
  • C1: 100 nF capacitor, function: U1 decoupling
  • C2: 100 nF capacitor, function: U2 decoupling

Pin-out of the IC used

74HC04 (Hex Inverter)

Pin Name Logic function Connection in this case
1 1A Input Connects to the LDR divider (VA)
2 1Y Output Connects to the U2 clock input (VB)
7 GND Ground Connects to 0
14 VCC Power Connects to VCC

CD4017BE (Decade Counter / Divider)

Pin Name Logic function Connection in this case
14 CLK Clock input Connects to the inverted sensor signal (VB)
13 CKE Clock enable Connects to 0 (active low)
15 RST Reset Connects to Q5 (VC) for automatic reset
3 Q0 Output 0 Connects to the D1 branch (V_Q0)
2 Q1 Output 1 Connects to the D2 branch (V_Q1)
4 Q2 Output 2 Connects to the D3 branch (V_Q2)
7 Q3 Output 3 Connects to the D4 branch (V_Q3)
10 Q4 Output 4 Connects to the D5 branch (V_Q4)
1 Q5 Output 5 Connects to reset (VC)
8 VSS Ground Connects to 0
16 VDD Power Connects to VCC

Note: Pins 5, 6, 9, 11 and 12 are unused decoded outputs and carry-out pins; leave them floating in this case.

Wiring guide

  • V1 connects between VCC and 0.
  • RLDR1 connects between VCC and VA.
  • R1 connects between VA and 0.
  • U1 pin 14 connects to VCC.
  • U1 pin 7 connects to 0.
  • U1 pin 1 connects to VA.
  • U1 pin 2 connects to VB.
  • U2 pin 16 connects to VCC.
  • U2 pin 8 connects to 0.
  • U2 pin 13 connects to 0.
  • U2 pin 14 connects to VB.
  • U2 pin 1 connects to VC.
  • U2 pin 15 connects to VC.
  • U2 pin 3 connects to V_Q0.
  • U2 pin 2 connects to V_Q1.
  • U2 pin 4 connects to V_Q2.
  • U2 pin 7 connects to V_Q3.
  • U2 pin 10 connects to V_Q4.
  • R2 connects between V_Q0 and V_D1.
  • D1 connects between V_D1 and 0.
  • R3 connects between V_Q1 and V_D2.
  • D2 connects between V_D2 and 0.
  • R4 connects between V_Q2 and V_D3.
  • D3 connects between V_D3 and 0.
  • R5 connects between V_Q3 and V_D4.
  • D4 connects between V_D4 and 0.
  • R6 connects between V_Q4 and V_D5.
  • D5 connects between V_D5 and 0.
  • C1 connects between VCC and 0.
  • C2 connects between VCC and 0.

Conceptual block diagram

Conceptual block diagram — 74HC04 Decimal counter
Quick read: inputs → main block → output (actuator or measurement). This summarizes the ASCII schematic below.

Schematic

[ U2: CD4017BE Decade Counter ]
                                                             |                             |
VCC --> [ RLDR1: LDR ] --(VA)--> [ U1: 74HC04 Inverter ] --(VB)--> CLK (Pin 14)            |
                           |                                 |                  Q0 (Pin 3)-|--(V_Q0)--> [ R2: 330 ] --> [ D1: Red LED ] --> GND
                           +---> [ R1: 10k ] --> GND         |                  Q1 (Pin 2)-|--(V_Q1)--> [ R3: 330 ] --> [ D2: Red LED ] --> GND
                                                             |                  Q2 (Pin 4)-|--(V_Q2)--> [ R4: 330 ] --> [ D3: Red LED ] --> GND
                                                 +--(VC)---------> RST (Pin 15) Q3 (Pin 7)-|--(V_Q3)--> [ R5: 330 ] --> [ D4: Red LED ] --> GND
                                                 |           |                  Q4 (Pin 10)|--(V_Q4)--> [ R6: 330 ] --> [ D5: Red LED ] --> GND
                                                 +---------------< Q5 (Pin 1)              |
                                                             |                             |
                                                 GND ------------> EN (Pin 13)             |
                                                             [-----------------------------]

* Power & Decoupling Notes:
  VCC --> [ C1: 100nF ] --> GND  (U1 Decoupling)
  VCC --> [ C2: 100nF ] --> GND  (U2 Decoupling)
  U1 Power: Pin 14 (VCC), Pin 7 (GND)
  U2 Power: Pin 16 (VCC), Pin 8 (GND)
Electrical Schematic

Electrical diagram

Electrical diagram for case: Conveyor belt object counter
Generated from the validated SPICE netlist for this case.

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

Measurements and tests

  1. Sensor Calibration: Measure node VA with a multimeter. Ensure it rests at >4.0 V when the light source shines on the LDR, and drops to <1.0 V when an object blocks the beam. Adjust R1 if your LDR has different resistance characteristics.
  2. Clock Edge Verification: Connect an oscilloscope to node VB. Pass an object through the beam and confirm a sharp, clean transition from 0 V to 5 V.
  3. Sequential Counting Check: Monitor nodes V_Q0 through V_Q4. Verify that each output successively jumps to ~5 V upon each clock pulse, lighting up D1 through D5 one by one.
  4. Auto-Reset Validation: Using an oscilloscope, monitor VC (Reset). When the 6th object passes, capture the brief microsecond high pulse on VC that clears the counter back to D1.

SPICE netlist and simulation

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

* Conveyor belt object counter
.width out=256

* --- Digital Subcircuits ---

* Analog Behavioral D-Flip-Flop with Asynchronous Reset
.subckt DFF D CLK RST Q
B_M M_int 0 V = V(RST)>2.5 ? 0 : (V(CLK)>2.5 ? (V(M_state)>2.5 ? 5 : 0) : (V(D)>2.5 ? 5 : 0))
R_M M_int M_state 100
C_M M_state 0 1n

B_S S_int 0 V = V(RST)>2.5 ? 0 : (V(CLK)>2.5 ? (V(M_state)>2.5 ? 5 : 0) : (V(S_state)>2.5 ? 5 : 0))
R_S S_int S_state 100
C_S S_state 0 1n

B_Q Q_int 0 V = V(S_state)>2.5 ? 5 : 0
R_Q Q_int Q 100
C_Q Q 0 1n
.ends

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

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

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

* Conveyor belt object counter
.width out=256

* --- Digital Subcircuits ---

* Analog Behavioral D-Flip-Flop with Asynchronous Reset
.subckt DFF D CLK RST Q
B_M M_int 0 V = V(RST)>2.5 ? 0 : (V(CLK)>2.5 ? (V(M_state)>2.5 ? 5 : 0) : (V(D)>2.5 ? 5 : 0))
R_M M_int M_state 100
C_M M_state 0 1n

B_S S_int 0 V = V(RST)>2.5 ? 0 : (V(CLK)>2.5 ? (V(M_state)>2.5 ? 5 : 0) : (V(S_state)>2.5 ? 5 : 0))
R_S S_int S_state 100
C_S S_state 0 1n

B_Q Q_int 0 V = V(S_state)>2.5 ? 5 : 0
R_Q Q_int Q 100
C_Q Q 0 1n
.ends

* CD4017BE Decade Counter (5-stage Johnson Counter with decoded outputs)
* Pins: 1:Q5(VC), 2:Q1, 3:Q0, 4:Q2, 7:Q3, 8:GND, 10:Q4, 13:EN, 14:CLK, 15:RST, 16:VCC
.subckt CD4017 1 2 3 4 7 8 10 13 14 15 16
B_CLK_INT CLK_INT 0 V = (V(14)>2.5) * (V(13)<2.5) * 5
R_CLK CLK_INT CLK_F 100
C_CLK CLK_F 0 1n

XF1 D1 CLK_F 15 F1 DFF
XF2 F1 CLK_F 15 F2 DFF
XF3 F2 CLK_F 15 F3 DFF
XF4 F3 CLK_F 15 F4 DFF
XF5 F4 CLK_F 15 F5 DFF

B_D1_int D1_int 0 V = V(F5)>2.5 ? 0 : 5
R_D1 D1_int D1 100
C_D1 D1 0 1n

B_Q0_int Q0_int 0 V = (V(F1)<2.5) * (V(F5)<2.5) * 5
R_Q0 Q0_int 3 100
C_Q0 3 0 1n

B_Q1_int Q1_int 0 V = (V(F1)>2.5) * (V(F2)<2.5) * 5
R_Q1 Q1_int 2 100
C_Q1 2 0 1n

B_Q2_int Q2_int 0 V = (V(F2)>2.5) * (V(F3)<2.5) * 5
R_Q2 Q2_int 4 100
C_Q2 4 0 1n

B_Q3_int Q3_int 0 V = (V(F3)>2.5) * (V(F4)<2.5) * 5
R_Q3 Q3_int 7 100
C_Q3 7 0 1n

B_Q4_int Q4_int 0 V = (V(F4)>2.5) * (V(F5)<2.5) * 5
R_Q4 Q4_int 10 100
C_Q4 10 0 1n

* Q5 output is used for the modulo-5 reset via VC, so it uses a slightly larger delay 
* to guarantee the reset pulse is wide enough to clear all DFFs.
B_Q5_int Q5_int 0 V = (V(F5)>2.5) * (V(F1)>2.5) * 5
R_Q5 Q5_int 1 100
C_Q5 1 0 10n

* Dummy loads to prevent warnings on power pins
R_GND 8 0 1
R_VCC 16 0 1Meg
.ends

* 74HC04 Hex Inverter (single gate modeled for pins 1, 2)
* Pins: 1:A, 2:Y, 7:GND, 14:VCC
.subckt 74HC04 1 2 7 14
B_Y_int Y_int 0 V = V(1)>2.5 ? 0 : 5
R_Y Y_int 2 100
C_Y 2 0 1n
R_GND 7 0 1
R_VCC 14 0 1Meg
.ends

* --- Main Circuit ---

* Power Supply
V1 VCC 0 DC 5

* Optical Sensing (LDR and pull-down divider)
* Conveyor beam is normally ON (light=1), LDR is 1k. 
* When object passes, light is blocked (light=0), LDR becomes 100k.
V_LIGHT N_LIGHT 0 PULSE(1 0 0.1 0.05 0.05 0.2 0.5)
R_LIGHT N_LIGHT 0 1Meg 
RLDR1 VCC VA R='V(N_LIGHT) > 0.5 ? 1k : 100k'
R1 VA 0 10k

* Edge sharpener and logic inverter
XU1 VA VB 0 VCC 74HC04

* Decade Counter
XU2 VC V_Q1 V_Q0 V_Q2 V_Q3 0 V_Q4 0 VB VC VCC CD4017

* LED Output Indicators
.model RED_LED D(IS=1e-18 N=1.8 RS=10)

R2 V_Q0 V_D1 330
D1 V_D1 0 RED_LED

R3 V_Q1 V_D2 330
D2 V_D2 0 RED_LED

R4 V_Q2 V_D3 330
D3 V_D3 0 RED_LED

R5 V_Q3 V_D4 330
D4 V_D4 0 RED_LED

R6 V_Q4 V_D5 330
D5 V_D5 0 RED_LED

* Decoupling Capacitors
C1 VCC 0 100n
C2 VCC 0 100n

* Dummy IN/OUT assignments for strict output requirements
R_IN VA IN 1
R_IN_GND IN 0 100Meg
R_OUT V_Q4 OUT 1
R_OUT_GND OUT 0 100Meg

* --- Simulation Commands ---
.op
.tran 1m 3.0
.print tran V(IN) V(OUT) V(VA) V(V_Q0) V(V_Q1) V(V_Q2) V(V_Q3) V(V_Q4)

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Analysis: The simulation shows the input signal (VA) toggling between ~4.5V and ~0.45V, representing the LDR state changes. The outputs V_Q0 to V_Q4 sequentially pulse high to ~4.25V, confirming the decade counter is advancing correctly with each input pulse.
Show raw data table (3128 rows)
Index   time            v(in)           v(out)          v(va)           v(v_q0)         v(v_q1)         v(v_q2)         v(v_q3)         v(v_q4)
0	0.000000e+00	4.545413e+00	7.813983e-36	4.545413e+00	7.814080e-36	4.250409e+00	7.814080e-36	7.814080e-36	7.813983e-36
1	1.000000e-05	4.545413e+00	7.736609e-38	4.545413e+00	7.736713e-38	4.250409e+00	7.736713e-38	7.736713e-38	7.736609e-38
2	2.000000e-05	4.545413e+00	7.660001e-40	4.545413e+00	7.660112e-40	4.250409e+00	7.660112e-40	7.660112e-40	7.660001e-40
3	4.000000e-05	4.545413e+00	-7.50832e-40	4.545413e+00	-7.50843e-40	4.250409e+00	-7.50843e-40	-7.50843e-40	-7.50832e-40
4	8.000000e-05	4.545413e+00	7.433609e-40	4.545413e+00	7.433716e-40	4.250409e+00	7.433716e-40	7.433716e-40	7.433609e-40
5	1.600000e-04	4.545413e+00	-7.39653e-40	4.545413e+00	-7.39664e-40	4.250409e+00	-7.39664e-40	-7.39664e-40	-7.39653e-40
6	3.200000e-04	4.545413e+00	7.378065e-40	4.545413e+00	7.378171e-40	4.250409e+00	7.378171e-40	7.378171e-40	7.378065e-40
7	6.400000e-04	4.545413e+00	-7.36885e-40	4.545413e+00	-7.36895e-40	4.250409e+00	-7.36895e-40	-7.36895e-40	-7.36885e-40
8	1.280000e-03	4.545413e+00	7.364244e-40	4.545413e+00	7.364350e-40	4.250409e+00	7.364350e-40	7.364350e-40	7.364244e-40
9	2.280000e-03	4.545413e+00	-7.36130e-40	4.545413e+00	-7.36141e-40	4.250409e+00	-7.36141e-40	-7.36141e-40	-7.36130e-40
10	3.280000e-03	4.545413e+00	7.358355e-40	4.545413e+00	7.358461e-40	4.250409e+00	7.358461e-40	7.358461e-40	7.358355e-40
11	4.280000e-03	4.545413e+00	-7.35541e-40	4.545413e+00	-7.35552e-40	4.250409e+00	-7.35552e-40	-7.35552e-40	-7.35541e-40
12	5.280000e-03	4.545413e+00	7.352471e-40	4.545413e+00	7.352577e-40	4.250409e+00	7.352577e-40	7.352577e-40	7.352471e-40
13	6.280000e-03	4.545413e+00	-7.34953e-40	4.545413e+00	-7.34964e-40	4.250409e+00	-7.34964e-40	-7.34964e-40	-7.34953e-40
14	7.280000e-03	4.545413e+00	7.346591e-40	4.545413e+00	7.346697e-40	4.250409e+00	7.346697e-40	7.346697e-40	7.346591e-40
15	8.280000e-03	4.545413e+00	-7.34365e-40	4.545413e+00	-7.34376e-40	4.250409e+00	-7.34376e-40	-7.34376e-40	-7.34365e-40
16	9.280000e-03	4.545413e+00	7.340716e-40	4.545413e+00	7.340822e-40	4.250409e+00	7.340822e-40	7.340822e-40	7.340716e-40
17	1.028000e-02	4.545413e+00	-7.33778e-40	4.545413e+00	-7.33789e-40	4.250409e+00	-7.33789e-40	-7.33789e-40	-7.33778e-40
18	1.128000e-02	4.545413e+00	7.334846e-40	4.545413e+00	7.334952e-40	4.250409e+00	7.334952e-40	7.334952e-40	7.334846e-40
19	1.228000e-02	4.545413e+00	-7.33191e-40	4.545413e+00	-7.33202e-40	4.250409e+00	-7.33202e-40	-7.33202e-40	-7.33191e-40
20	1.328000e-02	4.545413e+00	7.328981e-40	4.545413e+00	7.329086e-40	4.250409e+00	7.329086e-40	7.329086e-40	7.328981e-40
21	1.428000e-02	4.545413e+00	-7.32605e-40	4.545413e+00	-7.32616e-40	4.250409e+00	-7.32616e-40	-7.32616e-40	-7.32605e-40
22	1.528000e-02	4.545413e+00	7.323120e-40	4.545413e+00	7.323225e-40	4.250409e+00	7.323225e-40	7.323225e-40	7.323120e-40
23	1.628000e-02	4.545413e+00	-7.32019e-40	4.545413e+00	-7.32030e-40	4.250409e+00	-7.32030e-40	-7.32030e-40	-7.32019e-40
... (3104 more rows) ...

Common mistakes and how to avoid them

  1. Leaving Clock Enable floating: Pin 13 (CKE) on the CD4017BE is active low. If left unconnected, ambient electrical noise will disable the clock input irregularly. Always tie it directly to Ground (0).
  2. Missing LED current limiters: Connecting LEDs directly to the CD4017BE outputs will draw too much current, potentially burning out the decoded output stages of the IC. Always use individual resistors (e.g., 330 Ω) for each LED.
  3. Slow sensor transitions: The 74HC04 inverter buffers the signal, but slowly moving objects on a conveyor belt might still cause the logic threshold to linger, causing multiple rapid clock pulses (contact bounce equivalent). If objects move very slowly, replace the 74HC04 with a Schmitt trigger inverter (like the 74HC14) for severe hysteresis.

Troubleshooting

  • Symptom: The counter skips numbers or counts randomly.
  • Cause: Electrical noise on the LDR line or mechanical vibrations affecting the light source.
  • Fix: Add a small 10 nF capacitor between VA and 0 to filter out high-frequency optical or electrical jitter.
  • Symptom: Circuit stays permanently on LED D1 (Count 0) and never advances.
  • Cause: The Reset pin (15) is stuck HIGH, or Clock Enable (13) is stuck HIGH.
  • Fix: Verify the connection between Q5 and Reset. Ensure Pin 13 is firmly grounded.
  • Symptom: LEDs are extremely dim.
  • Cause: The current limiting resistors are too large, or the power supply cannot deliver enough current.
  • Fix: Check that R2-R6 are exactly 330 Ω, not 330 kΩ. Confirm the VCC supply is maintaining a steady 5 V.

Possible improvements and extensions

  1. Numerical Display: Replace the 10-LED output logic by substituting the CD4017BE with a CD4026BE, allowing you to directly drive a 7-segment numerical display for a true digit read-out.
  2. Monostable Debouncing: Insert a 555 timer configured as a monostable multivibrator between the sensor inverter (VB) and the counter’s clock input. This guarantees a single, fixed-duration clock pulse per object, entirely eliminating false double-counts regardless of object shape or 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 function of the LDR in this circuit?




Question 2: Which component is used for signal conditioning and generating a clean clock edge?




Question 3: What happens to the LDR voltage divider when the light beam is blocked?




Question 4: What is the role of the CD4017BE in this project?




Question 5: After how many items does the circuit automatically reset the batch?




Question 6: What happens when the 6th object is detected by the circuit?




Question 7: What type of clock edge does the 74HC04 inverter generate upon each detection?




Question 8: What type of signal does the CD4017BE advance across its outputs (Q0 to Q4) during counting?




Question 9: Which of the following is listed as a real-world use case for this circuit?




Question 10: What does the circuit use to indicate the sequential count?




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 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 monthly membership (7-day free trial) 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 monthly membership (7-day free trial) 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) ...


Reference 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)
* 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.

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 monthly membership (7-day free trial) 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 monthly membership (7-day free trial) 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) ...


Reference 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

* 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).

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: