Practical case: Vehicle access control with barrier

Vehicle access control with barrier prototype (Maker Style)

Level: Medium — Design a safety logic circuit that lifts a barrier only when vehicle presence and valid ticket verification occur simultaneously.

Objective and use case

In this practical case, you will build a digital control circuit using a 74HC08 AND gate to simulate the logic of an automated parking barrier. The barrier (represented by an LED) will only activate when a vehicle presence sensor and a ticket validation system trigger simultaneously.

Why it is useful:
* Parking lots: Ensures the gate does not open for pedestrians or if a ticket is invalid.
* Toll booths: Synchronizes payment confirmation with physical vehicle presence.
* Industrial safety: Prevents machinery operation unless a guard is in place and a start command is issued.
* Secure access: Requires dual authentication factors in physical security systems.

Expected outcome:
* State 0 (Rest): LED remains OFF when no buttons are pressed (0 V output).
* State 1 (Partial): LED remains OFF if only the vehicle is detected or only the ticket is validated.
* State 2 (Active): LED turns ON (approx. 5 V / High logic) ONLY when both inputs are active simultaneously.
* Logic Verification: Confirmation of the standard Boolean AND operation ($Y = A \cdot B$).

Target audience and level: Electronics students and hobbyists / Medium.

Materials

  • V1: 5 V DC power supply, function: Main circuit power
  • U1: 74HC08, function: Quad 2-Input AND Gate IC
  • S1: Push-button (NO), function: Simulates «Vehicle Presence Sensor»
  • S2: Push-button (NO), function: Simulates «Ticket Validation Signal»
  • R1: 10 kΩ resistor, function: Pull-down for Vehicle input
  • R2: 10 kΩ resistor, function: Pull-down for Ticket input
  • R3: 330 Ω resistor, function: LED current limiting
  • D1: Green LED, function: Simulates «Barrier Motor/Open Signal»
  • Breadboard and jumper wires

Pin-out of the IC used

Chip: 74HC08 (Quad 2-Input AND Gate)

Pin Name Logic function Connection in this case
1 1A Input A Connected to Vehicle Sensor (S1)
2 1B Input B Connected to Ticket Validator (S2)
3 1Y Output Connected to Barrier Indicator (LED)
7 GND Ground Connected to Supply Ground (0 V)
14 VCC Power Supply Connected to +5 V Supply

Note: Pins 4, 5, 6, 8, 9, 10, 11, 12, and 13 are unused in this specific circuit.

Wiring guide

  • Power Supply:
    • V1 (+) connects to node VCC.
    • V1 (-) connects to node 0 (GND).
  • IC Power:
    • U1 Pin 14 connects to node VCC.
    • U1 Pin 7 connects to node 0.
  • Input Stage (Vehicle Sensor):
    • S1 connects between node VCC and node VEHICLE_IN.
    • R1 connects between node VEHICLE_IN and node 0 (active-high configuration).
    • U1 Pin 1 connects to node VEHICLE_IN.
  • Input Stage (Ticket Validator):
    • S2 connects between node VCC and node TICKET_IN.
    • R2 connects between node TICKET_IN and node 0 (active-high configuration).
    • U1 Pin 2 connects to node TICKET_IN.
  • Output Stage (Barrier Actuator):
    • U1 Pin 3 connects to node LOGIC_OUT.
    • R3 connects between node LOGIC_OUT and node LED_ANODE.
    • D1 (Anode) connects to node LED_ANODE.
    • D1 (Cathode) connects to node 0.

Conceptual block diagram

Conceptual block diagram — 74HC08 AND gate

Schematic

[ INPUT SENSORS ]                     [ LOGIC PROCESSING ]                  [ ACTUATOR OUTPUT ]

 [ VCC ]
    |
 [ S1: Vehicle ]
    |
    +----(Node: VEHICLE_IN)----(Pin 1)-->+----------------------+
    |                                    |                      |
 [ R1: 10k ]                             |      U1: 74HC08      |
    |                                    |      (AND Gate)      |
 [ GND ]                                 |                      |--(Pin 3)--> [ R3: 330 ] --> [ D1: Green LED ] --> [ GND ]
                                         |  (Pin 14: VCC)       |
 [ VCC ]                                 |  (Pin 7:  GND)       |
    |                                    |                      |
 [ S2: Ticket ]                          |                      |
    |                                    |                      |
    +----(Node: TICKET_IN)-----(Pin 2)-->+----------------------+
    |
 [ R2: 10k ]
    |
 [ GND ]
Schematic (ASCII)

Electrical diagram

Electrical diagram for vehicle access control with barrier
Generated from the validated SPICE netlist for this case.

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

Truth table

The 74HC08 follows the standard AND logic verification:

Vehicle Detected (S1) Ticket Validated (S2) Output Voltage (Pin 3) Barrier State (LED)
Low (0) Low (0) ~0 V Closed (OFF)
Low (0) High (1) ~0 V Closed (OFF)
High (1) Low (0) ~0 V Closed (OFF)
High (1) High (1) ~5 V Open (ON)

Measurements and tests

  1. Idle Check: Ensure neither S1 nor S2 is pressed. Measure voltage at U1 Pin 1 and Pin 2 relative to GND. It should read 0 V (Logic Low). The LED must be OFF.
  2. Single Input Test: Press S1 (Vehicle) only. Measure voltage at Pin 1 (5 V) and Pin 3 (0 V). LED must remain OFF. Repeat for S2 (Ticket).
  3. Activation Test: Press both S1 and S2 simultaneously. Measure voltage at U1 Pin 3. It should read close to 5 V (Logic High).
  4. Load Check: Observe the LED turning ON brightly when both buttons are held. This confirms the barrier would lift.

SPICE netlist and simulation

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

* TITLE: Practical case: Vehicle access control with barrier
* Ngspice Netlist
* Implements a 74HC08 AND gate circuit with push-button inputs and LED output

* --- Component Models ---
* Switch Model: Voltage Controlled Switch for Push-buttons
* Vt=2.5V (Threshold), Ron=1 ohm (Closed), Roff=100Meg (Open)
.model SW_PUSH SW(Vt=2.5 Ron=1 Roff=100Meg)

* LED Model: Generic Green LED
.model D_GREEN D(Is=1e-22 Rs=5 N=1.5 Cjo=10p BV=5)

* --- Power Supply ---
* V1: 5V DC Main Power Supply
V1 VCC 0 DC 5

* --- Dynamic Stimuli (User Button Presses) ---
* These sources actuate the switches S1 and S2 to simulate user interaction.
* They are not part of the physical circuit but provide the mechanical "push".
* Sequence designed to test Truth Table: 00 -> 10 -> 01 -> 11
* Time unit: microseconds (us)

* S1 Actuator (Vehicle Sensor): Toggles every 200us (starts at 100us)
V_ACT_S1 S1_CTRL 0 PULSE(0 5 100u 1u 1u 100u 200u)

* S2 Actuator (Ticket Validator): Toggles every 400us (starts at 200us)
V_ACT_S2 S2_CTRL 0 PULSE(0 5 200u 1u 1u 200u 400u)

* --- Input Stage: Vehicle Sensor ---
* S1: Push-button connecting VCC to VEHICLE_IN when pressed
* ... (truncated in public view) ...

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

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

* TITLE: Practical case: Vehicle access control with barrier
* Ngspice Netlist
* Implements a 74HC08 AND gate circuit with push-button inputs and LED output

* --- Component Models ---
* Switch Model: Voltage Controlled Switch for Push-buttons
* Vt=2.5V (Threshold), Ron=1 ohm (Closed), Roff=100Meg (Open)
.model SW_PUSH SW(Vt=2.5 Ron=1 Roff=100Meg)

* LED Model: Generic Green LED
.model D_GREEN D(Is=1e-22 Rs=5 N=1.5 Cjo=10p BV=5)

* --- Power Supply ---
* V1: 5V DC Main Power Supply
V1 VCC 0 DC 5

* --- Dynamic Stimuli (User Button Presses) ---
* These sources actuate the switches S1 and S2 to simulate user interaction.
* They are not part of the physical circuit but provide the mechanical "push".
* Sequence designed to test Truth Table: 00 -> 10 -> 01 -> 11
* Time unit: microseconds (us)

* S1 Actuator (Vehicle Sensor): Toggles every 200us (starts at 100us)
V_ACT_S1 S1_CTRL 0 PULSE(0 5 100u 1u 1u 100u 200u)

* S2 Actuator (Ticket Validator): Toggles every 400us (starts at 200us)
V_ACT_S2 S2_CTRL 0 PULSE(0 5 200u 1u 1u 200u 400u)

* --- Input Stage: Vehicle Sensor ---
* S1: Push-button connecting VCC to VEHICLE_IN when pressed
S1 VCC VEHICLE_IN S1_CTRL 0 SW_PUSH
* R1: 10k Pull-down resistor for Vehicle input
R1 VEHICLE_IN 0 10k

* --- Input Stage: Ticket Validator ---
* S2: Push-button connecting VCC to TICKET_IN when pressed
S2 VCC TICKET_IN S2_CTRL 0 SW_PUSH
* R2: 10k Pull-down resistor for Ticket input
R2 TICKET_IN 0 10k

* --- Logic Stage: U1 (74HC08 Quad 2-Input AND Gate) ---
* Subcircuit representing one gate of the 74HC08 IC
* Pins mapped: 1(A), 2(B), 3(Y), 7(GND), 14(VCC)
.subckt 74HC08_GATE PIN1 PIN2 PIN3 PIN7 PIN14
    * Behavioral AND logic using continuous sigmoid functions for convergence
    * Y = VCC if (A > 2.5V) AND (B > 2.5V)
    B_LOGIC PIN3 PIN7 V = V(PIN14) * (1 / (1 + exp(-50*(V(PIN1)-2.5)))) * (1 / (1 + exp(-50*(V(PIN2)-2.5))))
.ends

* Instantiate U1 connected according to Wiring Guide
* Pin 1->VEHICLE_IN, Pin 2->TICKET_IN, Pin 3->LOGIC_OUT, Pin 7->0, Pin 14->VCC
XU1 VEHICLE_IN TICKET_IN LOGIC_OUT 0 VCC 74HC08_GATE

* --- Output Stage: Barrier Actuator ---
* R3: 330 ohm current limiting resistor
R3 LOGIC_OUT LED_ANODE 330
* D1: Green LED (Anode to R3, Cathode to GND)
D1 LED_ANODE 0 D_GREEN

* --- Simulation Directives ---
* Transient analysis for 500us to capture full sequence
.tran 1u 500u
.op

* Print signals to verify logic: 
* Expect LOGIC_OUT to be High (~5V) only when both Inputs are High (300us-400us)
.print tran V(VEHICLE_IN) V(TICKET_IN) V(LOGIC_OUT) V(LED_ANODE)

.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Show raw data table (1254 rows)
Index   time            v(vehicle_in)   v(ticket_in)    v(logic_out)
0	0.000000e+00	4.999500e-04	4.999500e-04	1.403014e-108
1	1.000000e-08	4.999500e-04	4.999500e-04	1.403014e-108
2	2.000000e-08	4.999500e-04	4.999500e-04	1.403014e-108
3	4.000000e-08	4.999500e-04	4.999500e-04	1.403014e-108
4	8.000000e-08	4.999500e-04	4.999500e-04	1.403014e-108
5	1.600000e-07	4.999500e-04	4.999500e-04	1.403014e-108
6	3.200000e-07	4.999500e-04	4.999500e-04	1.403014e-108
7	6.400000e-07	4.999500e-04	4.999500e-04	1.403014e-108
8	1.280000e-06	4.999500e-04	4.999500e-04	1.403014e-108
9	2.280000e-06	4.999500e-04	4.999500e-04	1.403014e-108
10	3.280000e-06	4.999500e-04	4.999500e-04	1.403014e-108
11	4.280000e-06	4.999500e-04	4.999500e-04	1.403014e-108
12	5.280000e-06	4.999500e-04	4.999500e-04	1.403014e-108
13	6.280000e-06	4.999500e-04	4.999500e-04	1.403014e-108
14	7.280000e-06	4.999500e-04	4.999500e-04	1.403014e-108
15	8.280000e-06	4.999500e-04	4.999500e-04	1.403014e-108
16	9.280000e-06	4.999500e-04	4.999500e-04	1.403014e-108
17	1.028000e-05	4.999500e-04	4.999500e-04	1.403014e-108
18	1.128000e-05	4.999500e-04	4.999500e-04	1.403014e-108
19	1.228000e-05	4.999500e-04	4.999500e-04	1.403014e-108
20	1.328000e-05	4.999500e-04	4.999500e-04	1.403014e-108
21	1.428000e-05	4.999500e-04	4.999500e-04	1.403014e-108
22	1.528000e-05	4.999500e-04	4.999500e-04	1.403014e-108
23	1.628000e-05	4.999500e-04	4.999500e-04	1.403014e-108
... (1230 more rows) ...

Common mistakes and how to avoid them

  1. Floating Inputs: Failing to include resistors R1 and R2 causes the inputs to «float,» leading to erratic LED flickering even when buttons are not pressed. Always use pull-down resistors with 74HC series logic.
  2. Missing Power Connections: Forgetting to connect Pin 14 (VCC) and Pin 7 (GND) is a classic error. Logic chips will not function without power, even if inputs are wired correctly.
  3. LED Without Resistor: Connecting the LED directly to the logic output (Pin 3) without R3 can damage the LED or the 74HC08 output stage due to excessive current.

Troubleshooting

  • Symptom: The LED is always ON, even when buttons are released.
    • Cause: Missing pull-down resistors or inputs connected directly to VCC.
    • Fix: Ensure R1 and R2 are installed correctly between the inputs and GND.
  • Symptom: The LED does not light up when both buttons are pressed.
    • Cause: LED polarity reversed or IC not powered.
    • Fix: Check D1 orientation (flat side is cathode/GND) and measure 5 V across Pins 14 and 7.
  • Symptom: LED is very dim when active.
    • Cause: Current limiting resistor (R3) value is too high.
    • Fix: Ensure R3 is 330 Ω (orange-orange-brown). If it is 10 kΩ or higher, the LED will be barely visible.

Possible improvements and extensions

  1. Emergency Stop: Introduce a third input using a 3-input AND gate (74HC11) or cascading another 74HC08 gate, connected to a «Stop» switch that overrides the open command.
  2. Motor Driver Interface: Replace the LED with an NPN transistor (e.g., 2N2222) and a relay to drive a real DC motor or solenoid, simulating a heavy-duty barrier mechanism.

More Practical Cases on Prometeo.blog

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

Go to Amazon

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

Quick Quiz

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




Question 2: Which specific logic gate IC is utilized to control the barrier's logic?




Question 3: Under which specific condition will the LED (representing the barrier) turn ON?




Question 4: What is the role of the pull-down resistors (typically 10 kΩ) connected to the inputs?




Question 5: What voltage level corresponds to the 'Active' state (State 2) where the LED is ON?




Question 6: Which Boolean logic expression represents the operation of this circuit?




Question 7: Which component is typically used in this simulation to represent the 'Vehicle Presence Sensor'?




Question 8: How does this logic apply to industrial safety scenarios?




Question 9: What is the status of the LED during 'State 1 (Partial)'?




Question 10: What is the purpose of the current-limiting resistor (e.g., 330 Ω) connected to the LED?




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: Conditional automatic irrigation system

Conditional automatic irrigation system prototype (Maker Style)

Level: Basic – Build a logic circuit to activate a pump only when soil is dry and water is available.

Objective and use case

In this practical case, you will build a safety interlock circuit using a 74HC08 AND gate. The circuit simulates a smart irrigation controller that decides whether to turn on a water pump based on two environmental conditions.

Why this is useful:
* Equipment Protection: Prevents pumps from running «dry» (without water input), which often causes mechanical failure.
* Resource Conservation: Ensures water is only dispensed when the soil actually needs moisture.
* Industrial Logic: Demonstrates the fundamental «safety interlock» concept used in heavy machinery (e.g., machine runs ONLY if guard is closed AND operator presses button).
* Digital Logic Basics: Provides a clear physical representation of the Boolean AND function ($Y = A \cdot B$).

Expected outcome:
* The Output LED (Pump) turns ON only when Switch A (Soil Sensor) is HIGH AND Switch B (Tank Sensor) is HIGH.
* If the Tank is Empty (Switch B = LOW), the pump remains OFF even if the soil is dry.
* Logic 0: Voltage $\approx$ 0 V. Logic 1: Voltage $\approx$ 5 V.

Target audience: Electronic students and hobbyists at a basic level.

Materials

  • U1: 74HC08, function: Quad 2-Input AND Gate IC.
  • S1: SPST Switch, function: Soil Moisture Sensor simulation (Closed = Dry/Logic 1).
  • S2: SPST Switch, function: Water Tank Level simulation (Closed = Water Present/Logic 1).
  • R1: 10 kΩ resistor, function: pull-down for Input A.
  • R2: 10 kΩ resistor, function: pull-down for Input B.
  • R3: 330 Ω resistor, function: LED current limiting.
  • D1: Green LED, function: Water Pump active indicator.
  • V1: 5 V DC supply, function: Main power source.

Pin-out of the IC: 74HC08

The 74HC08 contains four independent AND gates. We will use only one of them for this experiment.

Pin Name Logic Function Connection in this case
1 1A Input A Connected to S1 (Soil Status)
2 1B Input B Connected to S2 (Tank Status)
3 1Y Output Y Connected to LED (Pump indicator)
7 GND Ground Connected to Power Supply Ground (0V)
14 VCC Power Supply Connected to +5V Source

Wiring guide

Follow these connections carefully. The node names correspond to the function of the wire in the circuit.

  • V1 connects between node VCC and node 0 (GND).
  • U1 (Pin 14) connects to node VCC.
  • U1 (Pin 7) connects to node 0 (GND).
  • S1 connects between node VCC and node SOIL_Status.
  • R1 connects between node SOIL_Status and node 0 (GND) (Keeps input Low when switch is open).
  • S2 connects between node VCC and node TANK_Status.
  • R2 connects between node TANK_Status and node 0 (GND) (Keeps input Low when switch is open).
  • U1 (Pin 1, Input A) connects to node SOIL_Status.
  • U1 (Pin 2, Input B) connects to node TANK_Status.
  • U1 (Pin 3, Output Y) connects to node PUMP_Cmd.
  • R3 connects between node PUMP_Cmd and node LED_Anode.
  • D1 connects between node LED_Anode (Anode) and node 0 (GND) (Cathode).

Conceptual block diagram

Conceptual block diagram — 74HC08 AND gate

Schematic

[ INPUTS ]                                  [ LOGIC ]                             [ OUTPUT ]

[ S1: Soil Sensor ]
[ (Switch to VCC) ] --(Node: SOIL_Status)-->+---------------------+
[ (R1: 10k to GND)]                         |      U1: 74HC08     |
                                            |      (AND Gate)     |
                                            |                     |--(Node: PUMP_Cmd)--> [ R3: 330 Ohm ] --> [ D1: Green LED ] --> GND
                                            |   Pin 1 (Input A)   |                      (Current Lim.)      (Pump Active)
                                            |                     |
                                            |   Pin 2 (Input B)   |
[ S2: Tank Level  ] --(Node: TANK_Status)-->|                     |
[ (Switch to VCC) ]                         +---------------------+
[ (R2: 10k to GND)]
Schematic (ASCII)

Electrical diagram

Electrical diagram for conditional automatic irrigation system
Generated from the validated SPICE netlist for this case.

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

Truth table

This table defines the logic states.
0 = Switch Open / 0V / Wet Soil / Empty Tank / Pump OFF
1 = Switch Closed / 5V / Dry Soil / Full Tank / Pump ON

Soil Status (A) Tank Status (B) Output Pump (Y) Real-world State
0 0 0 Soil wet, Tank empty -> Standby
0 1 0 Soil wet, Tank full -> Standby
1 0 0 Soil dry, Tank empty -> Safety Cutoff (Protect Pump)
1 1 1 Soil dry, Tank full -> Irrigation Active

Measurements and tests

Validate your circuit using a multimeter set to DC Voltage (20V range).

  1. Standby Check: Ensure both S1 and S2 are Open (OFF). Measure voltage at Pin 3 of U1.
    • Expected: ~0 V. D1 is OFF.
  2. Dry Run Protection Test: Close S1 (Soil is Dry) but leave S2 Open (Tank Empty).
    • Expected: Pin 1 reads 5 V, Pin 2 reads 0 V. Output Pin 3 must remain at 0 V. D1 is OFF.
  3. No Demand Test: Open S1 (Soil Wet) and Close S2 (Tank Full).
    • Expected: Pin 1 reads 0 V, Pin 2 reads 5 V. Output Pin 3 must remain at 0 V. D1 is OFF.
  4. Active Irrigation Test: Close both S1 and S2.
    • Expected: Pin 1 reads 5 V, Pin 2 reads 5 V. Output Pin 3 should read ~5 V (Logic High). D1 lights up Green.

SPICE netlist and simulation

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

* Title: Practical case: Conditional automatic irrigation system

* -----------------------------------------------------------------------------
* POWER SUPPLY
* -----------------------------------------------------------------------------
* V1: 5V DC supply, function: Main power source.
V1 VCC 0 DC 5

* -----------------------------------------------------------------------------
* STIMULI GENERATION (Simulating User Interaction)
* -----------------------------------------------------------------------------
* These voltage sources drive the control pins of the ideal switches (S1, S2)
* to simulate the physical sensors changing state over time.
* They are not part of the BOM but are necessary for dynamic simulation.

* Control signal for S1 (Soil Sensor): Period 200us
* Logic: 0 -> 1 -> 0 -> 1
V_CTRL_S1 N_CTRL_S1 0 PULSE(0 5 10u 1u 1u 100u 200u)

* Control signal for S2 (Tank Sensor): Period 400us
* Logic: 0 -> 0 -> 1 -> 1
V_CTRL_S2 N_CTRL_S2 0 PULSE(0 5 10u 1u 1u 200u 400u)

* -----------------------------------------------------------------------------
* INPUT STAGE (Sensors and Pull-downs)
* -----------------------------------------------------------------------------
* S1: SPST Switch, function: Soil Moisture Sensor simulation.
* Wiring: Connects between node VCC and node SOIL_Status.
* Logic: Closed (Controlled by V_CTRL_S1 High) = Dry/Logic 1.
S1 VCC SOIL_Status N_CTRL_S1 0 SW_IDEAL
* ... (truncated in public view) ...

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

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

* Title: Practical case: Conditional automatic irrigation system

* -----------------------------------------------------------------------------
* POWER SUPPLY
* -----------------------------------------------------------------------------
* V1: 5V DC supply, function: Main power source.
V1 VCC 0 DC 5

* -----------------------------------------------------------------------------
* STIMULI GENERATION (Simulating User Interaction)
* -----------------------------------------------------------------------------
* These voltage sources drive the control pins of the ideal switches (S1, S2)
* to simulate the physical sensors changing state over time.
* They are not part of the BOM but are necessary for dynamic simulation.

* Control signal for S1 (Soil Sensor): Period 200us
* Logic: 0 -> 1 -> 0 -> 1
V_CTRL_S1 N_CTRL_S1 0 PULSE(0 5 10u 1u 1u 100u 200u)

* Control signal for S2 (Tank Sensor): Period 400us
* Logic: 0 -> 0 -> 1 -> 1
V_CTRL_S2 N_CTRL_S2 0 PULSE(0 5 10u 1u 1u 200u 400u)

* -----------------------------------------------------------------------------
* INPUT STAGE (Sensors and Pull-downs)
* -----------------------------------------------------------------------------
* S1: SPST Switch, function: Soil Moisture Sensor simulation.
* Wiring: Connects between node VCC and node SOIL_Status.
* Logic: Closed (Controlled by V_CTRL_S1 High) = Dry/Logic 1.
S1 VCC SOIL_Status N_CTRL_S1 0 SW_IDEAL

* R1: 10 kΩ resistor, function: pull-down for Input A.
* Wiring: Connects between node SOIL_Status and node 0 (GND).
R1 SOIL_Status 0 10k

* S2: SPST Switch, function: Water Tank Level simulation.
* Wiring: Connects between node VCC and node TANK_Status.
* Logic: Closed (Controlled by V_CTRL_S2 High) = Water Present/Logic 1.
S2 VCC TANK_Status N_CTRL_S2 0 SW_IDEAL

* R2: 10 kΩ resistor, function: pull-down for Input B.
* Wiring: Connects between node TANK_Status and node 0 (GND).
R2 TANK_Status 0 10k

* -----------------------------------------------------------------------------
* LOGIC STAGE (74HC08 Quad 2-Input AND Gate)
* -----------------------------------------------------------------------------
* U1: 74HC08
* Wiring Guide:
* - Pin 1 (Input A) -> SOIL_Status
* - Pin 2 (Input B) -> TANK_Status
* - Pin 3 (Output Y) -> PUMP_Cmd
* - Pin 7 -> GND (0)
* - Pin 14 -> VCC
* Implemented as a subcircuit to strictly expose pins as nodes.
XU1 SOIL_Status TANK_Status PUMP_Cmd 0 VCC 74HC08_Behavioral

* -----------------------------------------------------------------------------
* OUTPUT STAGE (Indicator)
* -----------------------------------------------------------------------------
* R3: 330 Ω resistor, function: LED current limiting.
* Wiring: Connects between node PUMP_Cmd and node LED_Anode.
R3 PUMP_Cmd LED_Anode 330

* D1: Green LED, function: Water Pump active indicator.
* Wiring: Connects between node LED_Anode (Anode) and node 0 (GND).
D1 LED_Anode 0 LED_Green

* -----------------------------------------------------------------------------
* MODELS & SUBCIRCUITS
* -----------------------------------------------------------------------------
* Switch Model: Low On-Resistance, High Off-Resistance, Threshold 2.5V
.model SW_IDEAL SW(Vt=2.5 Ron=0.1 Roff=100Meg)

* LED Model: Generic Green LED approximation
.model LED_Green D(IS=1e-22 N=1.5 RS=5 BV=5 IBV=10u)

* 74HC08 Subcircuit (Behavioral Implementation)
* Pinout: 1=A, 2=B, 3=Y, 7=GND, 14=VCC
.subckt 74HC08_Behavioral 1 2 3 7 14
* Logic Y = A AND B
* Implementation: Continuous sigmoid function for robust convergence.
* Output voltage swings to V(14) (VCC) when both inputs > 2.5V.
B_AND 3 7 V = V(14,7) * (1 / (1 + exp(-40 * (V(1,7) - 2.5)))) * (1 / (1 + exp(-40 * (V(2,7) - 2.5))))
.ends

* -----------------------------------------------------------------------------
* ANALYSIS COMMANDS
* -----------------------------------------------------------------------------
* Transient analysis: 500us duration to capture all logic states (00, 10, 01, 11)
.tran 1u 500u

* Print critical nodes for verification
.print tran V(SOIL_Status) V(TANK_Status) V(PUMP_Cmd) V(LED_Anode)

* Calculate DC operating point
.op

.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Show raw data table (1202 rows)
Index   time            v(soil_status)  v(tank_status)  v(pump_cmd)
0	0.000000e+00	4.999500e-04	4.999500e-04	7.201843e-87
1	1.000000e-08	4.999500e-04	4.999500e-04	7.201843e-87
2	2.000000e-08	4.999500e-04	4.999500e-04	7.201843e-87
3	4.000000e-08	4.999500e-04	4.999500e-04	7.201843e-87
4	8.000000e-08	4.999500e-04	4.999500e-04	7.201843e-87
5	1.600000e-07	4.999500e-04	4.999500e-04	7.201843e-87
6	3.200000e-07	4.999500e-04	4.999500e-04	7.201843e-87
7	6.400000e-07	4.999500e-04	4.999500e-04	7.201843e-87
8	1.280000e-06	4.999500e-04	4.999500e-04	7.201843e-87
9	2.280000e-06	4.999500e-04	4.999500e-04	7.201843e-87
10	3.280000e-06	4.999500e-04	4.999500e-04	7.201843e-87
11	4.280000e-06	4.999500e-04	4.999500e-04	7.201843e-87
12	5.280000e-06	4.999500e-04	4.999500e-04	7.201843e-87
13	6.280000e-06	4.999500e-04	4.999500e-04	7.201843e-87
14	7.280000e-06	4.999500e-04	4.999500e-04	7.201843e-87
15	8.280000e-06	4.999500e-04	4.999500e-04	7.201843e-87
16	9.280000e-06	4.999500e-04	4.999500e-04	7.201843e-87
17	1.000000e-05	4.999500e-04	4.999500e-04	7.201843e-87
18	1.010000e-05	4.999500e-04	4.999500e-04	7.201843e-87
19	1.026000e-05	4.999500e-04	4.999500e-04	7.201843e-87
20	1.030750e-05	4.999500e-04	4.999500e-04	7.201843e-87
21	1.039062e-05	4.999500e-04	4.999500e-04	7.201843e-87
22	1.041363e-05	4.999500e-04	4.999500e-04	7.201843e-87
23	1.045390e-05	4.999500e-04	4.999500e-04	7.201843e-87
... (1178 more rows) ...

Common mistakes and how to avoid them

  • Floating Inputs: Forgetting R1 or R2 causes the inputs to «float,» making the LED flicker or turn on randomly when switches are open. Solution: Always verify pull-down resistors are connected to Ground.
  • LED Orientation: Placing the LED backwards prevents it from lighting up even when logic is correct. Solution: Ensure the longer leg (Anode) faces the resistor and the IC.
  • Confusing Chips: Using a 74HC32 (OR gate) instead of 74HC08 (AND gate). Solution: Read the text printed on the top of the IC before insertion. If it behaves like «Pump on if EITHER condition is met,» you have the wrong chip.

Troubleshooting

  • Symptom: LED is always ON, regardless of switches.
    • Cause: Inputs might be shorted directly to VCC, or the IC is damaged.
    • Fix: Check wiring at Pin 1 and 2. Ensure R1 and R2 go to Ground, not VCC.
  • Symptom: LED is very dim when active.
    • Cause: R3 value is too high.
    • Fix: Replace R3 with a value between 220 Ω and 470 Ω.
  • Symptom: Circuit works inversely (LED off when switches are closed).
    • Cause: You might be using a NAND gate (like 74HC00) or connected the LED to VCC instead of Ground (sourcing vs sinking).
    • Fix: Verify part number is 74HC08 and LED Cathode is at Ground.

Possible improvements and extensions

  1. High Power Interface: Replace the LED with an NPN transistor (e.g., 2N2222) and a relay to control a real 12V water pump.
  2. Manual Override: Add a third switch connected to an OR gate after the AND gate output, allowing a user to force the pump ON regardless of sensors.

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




Question 2: What real-world device does the circuit simulate?




Question 3: Under what specific condition will the Output LED (Pump) turn ON?




Question 4: What is the main purpose of the 'safety interlock' concept demonstrated here?




Question 5: What does Switch A (Soil Sensor) represent in the logic of this project?




Question 6: What is the function of the 10 kΩ resistors (R1 and R2) connected to the switches?




Question 7: If the Water Tank is Empty (Switch B = LOW), what is the state of the pump?




Question 8: What voltage level corresponds to Logic 1 in this circuit?




Question 9: What does the Output LED visually indicate when it is lit?




Question 10: Which Boolean algebraic expression represents the logic of this circuit?




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

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

Follow me:


Practical case: Dual sensor alarm activation

Dual sensor alarm activation prototype (Maker Style)

Level: Basic. Implement a logic circuit where an alarm sounds only if two distinct sensors are activated simultaneously.

Objective and use case

In this tutorial, you will build a security logic circuit using a 74HC08 (AND gate) integrated circuit. The circuit processes signals from two independent switches (simulating a door and a window sensor) and activates an output LED only when both switches are closed at the same time.

Why it is useful:
* Safety Interlocks: Ensures machinery operates only when an operator presses two buttons simultaneously, keeping both hands away from danger.
* Security Systems: Triggers a specific high-priority alarm only when multiple zones are breached simultaneously.
* Data Validation: Logic gates are fundamental for validating that two necessary conditions (e.g., «System Ready» AND «Start Command») are met before executing an action.

Expected outcome:
* Input A (Low) + Input B (Low): LED remains OFF (0 V output).
* Input A (High) + Input B (Low): LED remains OFF (0 V output).
* Input A (Low) + Input B (High): LED remains OFF (0 V output).
* Input A (High) + Input B (High): LED turns ON (~5 V output).
* Target audience: Electronics students and hobbyists getting started with digital logic.

Materials

  • V1: 5 V DC supply, function: Main power source.
  • S1: SPST Switch, function: Sensor A (Door).
  • S2: SPST Switch, function: Sensor B (Window).
  • R1: 10 kΩ resistor, function: Pull-down for Sensor A (prevents floating state).
  • R2: 10 kΩ resistor, function: Pull-down for Sensor B.
  • U1: 74HC08 Quad 2-Input AND Gate, function: Logic decision core.
  • R3: 330 Ω resistor, function: LED current limiting.
  • D1: Red LED, function: Alarm visual indicator.

Pin-out of the IC used

Selected Chip: 74HC08 (Quad 2-Input AND Gate).
Note: This chip contains four independent gates. We will use only one.

Pin Name Logic function Connection in this case
1 1A Input A Connect to Node SENSOR_A
2 1B Input B Connect to Node SENSOR_B
3 1Y Output Connect to Node ALARM_OUT
7 GND Ground Connect to Node 0 (GND)
14 VCC Power Supply Connect to Node VCC (+5 V)

Wiring guide

Construct the circuit following these connections using specific node names:

  • V1: Connect positive terminal to node VCC and negative terminal to node 0.
  • U1 Power: Connect Pin 14 to VCC and Pin 7 to 0.
  • S1: Connect one side to VCC and the other side to node SENSOR_A.
  • R1: Connect between node SENSOR_A and node 0.
  • S2: Connect one side to VCC and the other side to node SENSOR_B.
  • R2: Connect between node SENSOR_B and node 0.
  • U1 Logic:
    • Connect Pin 1 to node SENSOR_A.
    • Connect Pin 2 to node SENSOR_B.
    • Connect Pin 3 to node ALARM_OUT.
  • Output Stage:
    • R3: Connect between node ALARM_OUT and node LED_ANODE.
    • D1: Connect Anode to node LED_ANODE and Cathode to node 0.

Conceptual block diagram

Conceptual block diagram — 74HC08 AND gate

Schematic

[ INPUT SENSORS ]                          [ LOGIC CORE ]                       [ OUTPUT ALARM ]

                                                   +--------------+
    [ VCC ] --> [ S1: Door ] --(SENSOR_A)--------->| Pin 1        |
                                   |               |              |
                                   +-> [ R1: 10k ] |              |
                                          |        |  U1: 74HC08  |
                                       [ GND ]     |  (AND Gate)  |--(ALARM_OUT)--> [ R3: 330 Ω ] --> [ D1: LED ] --> [ GND ]
                                                   |              |
                                                   |              |
    [ VCC ] --> [ S2: Window ] --(SENSOR_B)------->| Pin 2        |
                                   |               |              |
                                   +-> [ R2: 10k ] | Power:       |
                                          |        | 14(VCC), 7(0)|
                                       [ GND ]     +--------------+
Schematic (ASCII)

Electrical diagram

Electrical diagram for dual sensor alarm activation
Generated from the validated SPICE netlist for this case.

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

Truth table

The 74HC08 output is High (1) only if both inputs are High (1).

Sensor A (S1) Sensor B (S2) Output (Pin 3) LED State
0 (Open) 0 (Open) 0 (Low) OFF
0 (Open) 1 (Closed) 0 (Low) OFF
1 (Closed) 0 (Open) 0 (Low) OFF
1 (Closed) 1 (Closed) 1 (High) ON

Measurements and tests

  1. Power Verification: Measure voltage between VCC and 0. It should be stable at 5 V.
  2. Idle State: Ensure both S1 and S2 are open. Measure voltage at Pin 1 and Pin 2 of U1. Both should be 0 V (Logic 0). The LED should be OFF.
  3. Single Trigger Test: Close S1 only. Pin 1 should read 5 V, Pin 2 should read 0 V. Measure Pin 3 (Output); it should remain 0 V. Repeat for S2 only.
  4. Alarm Activation: Close both S1 and S2. Measure Pin 1 and Pin 2; both must be 5 V. Measure Pin 3; it should jump to ~5 V (Logic 1).
  5. Output Current: Check that D1 lights up brightly. The voltage drop across R3 should be approximately 3 V (depending on LED color).

SPICE netlist and simulation

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

* Title: Practical case: Dual sensor alarm activation

* ==============================================================================
* Models
* ==============================================================================
* Generic Red LED Model
* IS: Saturation current, N: Emission coefficient, RS: Series resistance
.model DLED D(IS=1e-14 N=1.5 RS=5 BV=5 IBV=10u CJO=10p TT=10n)

* Voltage Controlled Switch Model (for S1, S2)
* Simulates a physical SPST switch
* Vt: Threshold voltage (2.5V), Ron: On resistance (1 ohm), Roff: Off resistance (100Meg)
.model SW_SENSOR SW(Vt=2.5 Ron=1 Roff=100Meg)

* ==============================================================================
* Subcircuits
* ==============================================================================
* U1: 74HC08 Quad 2-Input AND Gate (Single Gate Implementation)
* Pins: 1=A, 2=B, 3=Y, 7=GND, 14=VCC
.subckt 74HC08_GATE 1 2 3 7 14
* Behavioral implementation using continuous sigmoid functions for convergence robustness.
* Logic: V_out = VCC * sigmoid(A) * sigmoid(B)
* The slope factor (50) ensures a sharp transition near the 2.5V threshold.
B_LOGIC 3 7 V = V(14) * (1 / (1 + exp(-50 * (V(1) - 2.5)))) * (1 / (1 + exp(-50 * (V(2) - 2.5))))
.ends

* ==============================================================================
* Main Circuit
* ==============================================================================

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

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

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

* Title: Practical case: Dual sensor alarm activation

* ==============================================================================
* Models
* ==============================================================================
* Generic Red LED Model
* IS: Saturation current, N: Emission coefficient, RS: Series resistance
.model DLED D(IS=1e-14 N=1.5 RS=5 BV=5 IBV=10u CJO=10p TT=10n)

* Voltage Controlled Switch Model (for S1, S2)
* Simulates a physical SPST switch
* Vt: Threshold voltage (2.5V), Ron: On resistance (1 ohm), Roff: Off resistance (100Meg)
.model SW_SENSOR SW(Vt=2.5 Ron=1 Roff=100Meg)

* ==============================================================================
* Subcircuits
* ==============================================================================
* U1: 74HC08 Quad 2-Input AND Gate (Single Gate Implementation)
* Pins: 1=A, 2=B, 3=Y, 7=GND, 14=VCC
.subckt 74HC08_GATE 1 2 3 7 14
* Behavioral implementation using continuous sigmoid functions for convergence robustness.
* Logic: V_out = VCC * sigmoid(A) * sigmoid(B)
* The slope factor (50) ensures a sharp transition near the 2.5V threshold.
B_LOGIC 3 7 V = V(14) * (1 / (1 + exp(-50 * (V(1) - 2.5)))) * (1 / (1 + exp(-50 * (V(2) - 2.5))))
.ends

* ==============================================================================
* Main Circuit
* ==============================================================================

* --- Power Supply ---
* V1: 5 V DC supply (Main Power)
V1 VCC 0 DC 5

* --- Actuation Control Signals (Simulation Stimuli) ---
* These voltage sources act as the "hand" pressing the switches.
* They define the timing for the Truth Table test.
* ACT_A: Period 200us (High 0-100us)
V_ACT_A ACT_A 0 PULSE(0 5 0 1u 1u 100u 200u)
* ACT_B: Period 400us (High 0-200us)
V_ACT_B ACT_B 0 PULSE(0 5 0 1u 1u 200u 400u)

* --- Input A: Door Sensor ---
* S1: SPST Switch. Connects VCC to SENSOR_A when ACT_A is High (>2.5V).
S1 VCC SENSOR_A ACT_A 0 SW_SENSOR
* R1: 10 kΩ resistor. Pull-down for Sensor A.
R1 SENSOR_A 0 10k

* --- Input B: Window Sensor ---
* S2: SPST Switch. Connects VCC to SENSOR_B when ACT_B is High (>2.5V).
S2 VCC SENSOR_B ACT_B 0 SW_SENSOR
* R2: 10 kΩ resistor. Pull-down for Sensor B.
R2 SENSOR_B 0 10k

* --- Logic Core: U1 (74HC08) ---
* Instantiating the logic gate subcircuit.
* Mapping: Pin 1->SENSOR_A, Pin 2->SENSOR_B, Pin 3->ALARM_OUT, Pin 7->0, Pin 14->VCC
XU1 SENSOR_A SENSOR_B ALARM_OUT 0 VCC 74HC08_GATE

* --- Output Stage ---
* R3: 330 Ω resistor (Current limiting)
R3 ALARM_OUT LED_ANODE 330
* D1: Red LED (Visual indicator)
D1 LED_ANODE 0 DLED

* ==============================================================================
* Analysis Directives
* ==============================================================================
* Transient analysis: Step 1us, Stop 500us
* This duration covers all combinations of the input pulses (00, 01, 10, 11).
.tran 1u 500u

* Print required nodes for log output
.print tran V(SENSOR_A) V(SENSOR_B) V(ALARM_OUT) V(LED_ANODE)

* Calculate DC operating point
.op

.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Show raw data table (1294 rows)
Index   time            v(sensor_a)     v(sensor_b)     v(alarm_out)
0	0.000000e+00	4.999500e-04	4.999500e-04	1.403014e-108
1	1.000000e-08	4.999500e-04	4.999500e-04	1.403014e-108
2	2.000000e-08	4.999500e-04	4.999500e-04	1.403014e-108
3	4.000000e-08	4.999500e-04	4.999500e-04	1.403014e-108
4	8.000000e-08	4.999500e-04	4.999500e-04	1.403014e-108
5	1.600000e-07	4.999500e-04	4.999500e-04	1.403014e-108
6	3.200000e-07	4.999500e-04	4.999500e-04	1.403014e-108
7	3.562500e-07	4.999500e-04	4.999500e-04	1.403014e-108
8	4.196875e-07	4.999500e-04	4.999500e-04	1.403014e-108
9	4.372461e-07	4.999500e-04	4.999500e-04	1.403014e-108
10	4.679736e-07	4.999500e-04	4.999500e-04	1.403014e-108
11	4.795524e-07	4.999500e-04	4.999500e-04	1.403014e-108
12	4.902290e-07	4.999500e-04	4.999500e-04	1.403014e-108
13	5.023412e-07	4.999500e+00	4.999500e+00	5.000000e+00
14	5.138119e-07	4.999500e+00	4.999500e+00	5.000000e+00
15	5.256739e-07	4.999500e+00	4.999500e+00	5.000000e+00
16	5.378128e-07	4.999500e+00	4.999500e+00	5.000000e+00
17	5.539238e-07	4.999500e+00	4.999500e+00	5.000000e+00
18	5.828205e-07	4.999500e+00	4.999500e+00	5.000000e+00
19	6.384927e-07	4.999500e+00	4.999500e+00	5.000000e+00
20	7.166884e-07	4.999500e+00	4.999500e+00	5.000000e+00
21	8.730798e-07	4.999500e+00	4.999500e+00	5.000000e+00
22	1.000000e-06	4.999500e+00	4.999500e+00	5.000000e+00
23	1.031278e-06	4.999500e+00	4.999500e+00	5.000000e+00
... (1270 more rows) ...

Common mistakes and how to avoid them

  1. Floating Inputs: Omitting R1 or R2 causes the inputs to «float» when switches are open. The 74HC08 may pick up noise and trigger erratically. Solution: Always use pull-down resistors (10 kΩ) connected to ground.
  2. Missing Power to IC: Students often wire the logic pins but forget Pins 14 (VCC) and 7 (GND). Solution: Always wire power rails first.
  3. No Current Limiting: Connecting the LED directly to the IC output without R3 will damage the LED or the 74HC08. Solution: Ensure a 220 Ω to 470 Ω resistor is in series with the LED.

Troubleshooting

  • LED never turns ON:
    • Check if the LED polarity is correct (Anode to resistor, Cathode to ground).
    • Verify the 74HC08 has power on Pin 14.
    • Ensure both switches are making good contact.
  • LED acts erratically or turns ON when switches are OFF:
    • Check for missing pull-down resistors R1 and R2.
    • Verify that you are using a 74HC08 (AND) and not a 74HC32 (OR) or 74HC00 (NAND).
  • LED is very dim:
    • R3 value might be too high (e.g., 100 kΩ instead of 330 Ω).
    • Source voltage V1 might be too low (< 3 V).

Possible improvements and extensions

  1. Audible Alarm: Connect a 5 V active buzzer in parallel with the LED (and its resistor) or use a transistor driver to sound a noise when the alarm triggers.
  2. Memory Latch: Feed the output into a Set-Reset (SR) Latch or Flip-Flop so that once the alarm is triggered, it stays ON even if the sensors are closed again, requiring a manual reset button.

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 integrated circuit is used as the core logic component in this tutorial?




Question 2: What condition must be met for the output LED to turn ON?




Question 3: What is the primary purpose of using an AND gate in a safety interlock system?




Question 4: If Input A is Low and Input B is High, what is the expected state of the LED?




Question 5: What does the tutorial list as a use case for 'Data Validation'?




Question 6: What is the voltage output when the LED is OFF according to the expected outcome?




Question 7: Which components are used to simulate the door and window sensors?




Question 8: How does the circuit behave if both Input A and Input B are Low?




Question 9: What is the difficulty level of this logic circuit implementation?




Question 10: In the context of security systems, when does this circuit trigger a high-priority alarm?




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: Lighting control from two points

Lighting control from two points prototype (Maker Style)

Level: Basic. Build a circuit where a pilot light can be activated from two independent switches using digital logic.

Objective and use case

In this project, you will build a digital control circuit using a 74HC32 OR gate to power an LED indicator when either of two push buttons is actuated. This demonstrates the fundamental logic function where an output is true if at least one input is true.

Why it is useful:
* Home Automation: Simulates a hallway light system where multiple switches can turn on a light.
* Security Systems: Represents an alarm trigger zone where any single sensor (door or window) triggers the siren.
* Automotive: Functions like interior dome lights that turn on if the driver’s side OR passenger’s side door is opened.
* Industrial Safety: Acts as an emergency stop system where pressing any button on a production line halts the machine.

Expected outcome:
* LED State: The LED remains OFF (Logic 0) only when both buttons are released.
* Single Press: Pressing Button A turns the LED ON (Logic 1).
* Single Press: Pressing Button B turns the LED ON (Logic 1).
* Simultaneous Press: Pressing both buttons keeps the LED ON (Logic 1).
* Target Audience: Students and hobbyists learning basic digital logic gates.

Materials

  • V1: 5 V DC supply
  • U1: 74HC32 (Quad 2-Input OR Gate IC)
  • S1: Momentary Push Button (NO – Normally Open), function: Input A
  • S2: Momentary Push Button (NO – Normally Open), function: Input B
  • R1: 10 kΩ resistor, function: Pull-down for Input A
  • R2: 10 kΩ resistor, function: Pull-down for Input B
  • R3: 330 Ω resistor, function: LED current limiting
  • D1: Red LED, function: Logic output indicator

Pin-out of the IC used

Chip: 74HC32 (Quad 2-Input OR Gate)

Pin Name Logic Function Connection in this case
1 1A Input A Connected to S1 and R1
2 1B Input B Connected to S2 and R2
3 1Y Output Connected to R3 (LED driver)
7 GND Ground Connected to 0V
14 VCC Power Supply Connected to +5V

Wiring guide

This guide defines the connections using specific node names to ensure a clean circuit assembly.

  • Power Nodes:

    • VCC: Connect positive terminal of V1 to U1 Pin 14.
    • 0 (GND): Connect negative terminal of V1 to U1 Pin 7.
  • Input A Logic (NODE_A):

    • Connect S1 between VCC and NODE_A.
    • Connect R1 between NODE_A and 0 (GND).
    • Connect U1 Pin 1 to NODE_A.
  • Input B Logic (NODE_B):

    • Connect S2 between VCC and NODE_B.
    • Connect R2 between NODE_B and 0 (GND).
    • Connect U1 Pin 2 to NODE_B.
  • Output Logic (NODE_Y):

    • Connect U1 Pin 3 to one end of R3.
    • Connect the other end of R3 to the anode (long leg) of D1.
    • Connect the cathode (short leg) of D1 to 0 (GND).

Conceptual block diagram

Conceptual block diagram — 74HC32 OR gate

Schematic

[ INPUTS ]                                  [ LOGIC ]                                [ OUTPUT ]

[ VCC ]--> [ S1 (NO) ] --+--(NODE_A)----------->+-------------+
                         |  (Pin 1)             |             |
                    [ R1 (10k) ]                |  U1: 74HC32 |
                         v                      |  (OR Gate)  |--(NODE_Y)--> [ R3 (330) ] --> [ D1 (LED) ] --> [ GND ]
                      [ GND ]                   |  (Pin 3)    |
                                                |             |
[ VCC ]--> [ S2 (NO) ] --+--(NODE_B)----------->+-------------+
                         |  (Pin 2)
                    [ R2 (10k) ]
                         v
                      [ GND ]
Schematic (ASCII)

Electrical diagram

Electrical diagram for case: Practical case: Lighting control from two points
Generated from the validated SPICE netlist for this case.

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

Truth table

The 74HC32 follows the standard OR logic table:

Input A (S1) Input B (S2) Output Y (LED) State Description
0 (Released) 0 (Released) 0 (OFF) No active signal
0 (Released) 1 (Pressed) 1 (ON) Activated by B
1 (Pressed) 0 (Released) 1 (ON) Activated by A
1 (Pressed) 1 (Pressed) 1 (ON) Activated by both

Measurements and tests

  1. Idle Check: Before pressing anything, measure the voltage at NODE_A and NODE_B relative to GND. It should be close to 0V (Logic 0) due to the pull-down resistors. The LED should be off.
  2. Input A Test: Press S1. Measure voltage at NODE_A; it should rise to 5V. Verify D1 lights up.
  3. Input B Test: Press S2. Measure voltage at NODE_B; it should rise to 5V. Verify D1 lights up.
  4. Combined Test: Press both buttons simultaneously. The LED should remain lit without flickering.

SPICE netlist and simulation

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

* Practical case: Lighting control from two points

* --- Power Supply ---
* V1: 5V DC Supply connected to VCC and GND (0)
V1 VCC 0 DC 5

* --- Input A ---
* S1: Momentary Push Button (NO)
* Modeled as a voltage-controlled switch (S1) driven by a pulse source (V_ACT_A)
* to simulate the physical user action of pressing the button.
V_ACT_A ACT_A 0 PULSE(0 5 50u 1u 1u 100u 200u)
S1 VCC NODE_A ACT_A 0 SW_BTN

* R1: 10k Pull-down resistor for Input A
R1 NODE_A 0 10k

* --- Input B ---
* S2: Momentary Push Button (NO)
* Modeled as a voltage-controlled switch (S2) driven by a pulse source (V_ACT_B)
V_ACT_B ACT_B 0 PULSE(0 5 50u 1u 1u 200u 400u)
S2 VCC NODE_B ACT_B 0 SW_BTN

* R2: 10k Pull-down resistor for Input B
R2 NODE_B 0 10k

* --- Logic IC U1: 74HC32 (Quad 2-Input OR Gate) ---
* Wiring Guide: Pin 1 to NODE_A, Pin 2 to NODE_B, Pin 3 to NODE_Y
* Pin 7 to GND (0), Pin 14 to VCC
XU1 NODE_A NODE_B NODE_Y 0 VCC 74HC32

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

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

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

* Practical case: Lighting control from two points

* --- Power Supply ---
* V1: 5V DC Supply connected to VCC and GND (0)
V1 VCC 0 DC 5

* --- Input A ---
* S1: Momentary Push Button (NO)
* Modeled as a voltage-controlled switch (S1) driven by a pulse source (V_ACT_A)
* to simulate the physical user action of pressing the button.
V_ACT_A ACT_A 0 PULSE(0 5 50u 1u 1u 100u 200u)
S1 VCC NODE_A ACT_A 0 SW_BTN

* R1: 10k Pull-down resistor for Input A
R1 NODE_A 0 10k

* --- Input B ---
* S2: Momentary Push Button (NO)
* Modeled as a voltage-controlled switch (S2) driven by a pulse source (V_ACT_B)
V_ACT_B ACT_B 0 PULSE(0 5 50u 1u 1u 200u 400u)
S2 VCC NODE_B ACT_B 0 SW_BTN

* R2: 10k Pull-down resistor for Input B
R2 NODE_B 0 10k

* --- Logic IC U1: 74HC32 (Quad 2-Input OR Gate) ---
* Wiring Guide: Pin 1 to NODE_A, Pin 2 to NODE_B, Pin 3 to NODE_Y
* Pin 7 to GND (0), Pin 14 to VCC
XU1 NODE_A NODE_B NODE_Y 0 VCC 74HC32

* --- Output Stage ---
* R3: 330 Ohm LED current limiting resistor
R3 NODE_Y NODE_LED 330

* D1: Red LED Logic output indicator
D1 NODE_LED 0 LED_RED

* --- Models and Subcircuits ---

* Switch Model (Normally Open)
* Vt=2.5V: Threshold voltage for switching
* Ron=0.1: Low resistance when closed
* Roff=10Meg: High resistance when open
.model SW_BTN SW(Vt=2.5 Ron=0.1 Roff=10Meg)

* LED Model (Generic Red LED)
.model LED_RED D(IS=1e-22 N=1.5 RS=5 BV=5 IBV=10u CJO=10p)

* 74HC32 Behavioral Subcircuit
* Implements robust continuous logic to avoid convergence issues
.subckt 74HC32 1 2 3 7 14
* Pin Definitions: 1=InputA, 2=InputB, 3=OutputY, 7=GND, 14=VCC
* Logic: Y = A OR B
* Implemented using Sigmoid function S(x) = 1 / (1 + exp(-k*(x-threshold)))
* OR(A,B) is equivalent to 1 - (NOT_A * NOT_B)
* V(14) scales the output to the supply rail
B_OR 3 7 V = V(14) * (1 - ( (1/(1+exp(-20*(V(1)-2.5)))) * (1/(1+exp(-20*(V(2)-2.5)))) ))
.ends

* --- Simulation Directives ---
* Transient analysis for 600us to capture all logic states of the pulses
.tran 1u 600u

* Print required voltages for analysis
.print tran V(NODE_A) V(NODE_B) V(NODE_Y) V(NODE_LED)

* Calculate DC operating point
.op

.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Show raw data table (1562 rows)
Index   time            v(node_a)       v(node_b)       v(node_y)
0	0.000000e+00	4.995005e-03	4.995005e-03	5.000000e+00
1	1.000000e-08	4.995005e-03	4.995005e-03	5.000000e+00
2	2.000000e-08	4.995005e-03	4.995005e-03	5.000000e+00
3	4.000000e-08	4.995005e-03	4.995005e-03	5.000000e+00
4	8.000000e-08	4.995005e-03	4.995005e-03	5.000000e+00
5	1.600000e-07	4.995005e-03	4.995005e-03	5.000000e+00
6	3.200000e-07	4.995005e-03	4.995005e-03	5.000000e+00
7	6.400000e-07	4.995005e-03	4.995005e-03	5.000000e+00
8	1.280000e-06	4.995005e-03	4.995005e-03	5.000000e+00
9	2.280000e-06	4.995005e-03	4.995005e-03	5.000000e+00
10	3.280000e-06	4.995005e-03	4.995005e-03	5.000000e+00
11	4.280000e-06	4.995005e-03	4.995005e-03	5.000000e+00
12	5.280000e-06	4.995005e-03	4.995005e-03	5.000000e+00
13	6.280000e-06	4.995005e-03	4.995005e-03	5.000000e+00
14	7.280000e-06	4.995005e-03	4.995005e-03	5.000000e+00
15	8.280000e-06	4.995005e-03	4.995005e-03	5.000000e+00
16	9.280000e-06	4.995005e-03	4.995005e-03	5.000000e+00
17	1.028000e-05	4.995005e-03	4.995005e-03	5.000000e+00
18	1.128000e-05	4.995005e-03	4.995005e-03	5.000000e+00
19	1.228000e-05	4.995005e-03	4.995005e-03	5.000000e+00
20	1.328000e-05	4.995005e-03	4.995005e-03	5.000000e+00
21	1.428000e-05	4.995005e-03	4.995005e-03	5.000000e+00
22	1.528000e-05	4.995005e-03	4.995005e-03	5.000000e+00
23	1.628000e-05	4.995005e-03	4.995005e-03	5.000000e+00
... (1538 more rows) ...

Common mistakes and how to avoid them

  1. Leaving Inputs Floating: Failing to install pull-down resistors (R1, R2) causes the inputs to «float,» often leading to the LED flickering or staying on permanently due to static noise. Always tie unused inputs to GND or VCC.
  2. Missing Power to Chip: Forgetting to connect Pin 14 to +5V and Pin 7 to GND. The logic gates inside the chip cannot function without power.
  3. LED Orientation: Inserting the LED backwards (anode to ground). The LED will act as an open circuit and will never turn on.

Troubleshooting

  • LED is always ON:
    • Check if R1 or R2 is missing or disconnected.
    • Verify you are using a Normally Open (NO) button, not a Normally Closed (NC) one.
  • LED does not turn ON when buttons are pressed:
    • Check U1 power connections (Pins 7 and 14).
    • Ensure the LED is oriented correctly (Flat side/short leg to GND).
  • LED is very dim:
    • R3 value might be too high (e.g., using 10 kΩ instead of 330 Ω).
    • Supply voltage V1 might be too low.

Possible improvements and extensions

  1. Three-Point Control: Cascade a second OR gate (using the remaining gates on the 74HC32 chip) to add a third switch, allowing control from three locations.
  2. Latch Circuit: Add a feedback loop or use an SR latch so that pressing a button once turns the light on and keeps it on until a «Reset» button is pressed (simulating an alarm memory).

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 project?




Question 2: Which specific logic gate IC is used in this project?




Question 3: What is the state of the LED when both buttons are released?




Question 4: How does the circuit behave if both Button A and Button B are pressed simultaneously?




Question 5: Which automotive application is cited as an example of this logic function?




Question 6: In an industrial safety context, how is this logic applied?




Question 7: What fundamental logic function does this circuit demonstrate?




Question 8: How does this circuit relate to home automation?




Question 9: What happens to the LED if only Button A is pressed?




Question 10: Which security system application is mentioned for this circuit?




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

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

Follow me:


Practical case: Dual Sensor Alarm System

Dual Sensor Alarm System prototype (Maker Style)

Level: Basic — Implement a logic circuit that triggers an alarm if either of two sensors detects an intrusion.

Objective and use case

In this practical case, you will build a digital logic circuit using a 74HC32 (OR gate) integrated circuit. The circuit monitors two switches representing door sensors; if either switch is activated (logic HIGH), the output LED (alarm) turns on.

Why it is useful:
* Home Security: Simulates a system where opening either the front door or the back door triggers the siren.
* Automotive Safety: Functions like the dashboard «door open» light, which illuminates if any passenger door is not fully closed.
* Industrial Controls: Acts as a simplified fault monitor where multiple error signals can trigger a single warning light.

Expected outcome:
* Standby State: When both switches are open (0 V input), the LED remains OFF.
* Active State 1: When Switch A is closed (5 V input), the LED turns ON.
* Active State 2: When Switch B is closed (5 V input), the LED turns ON.
* Dual Active State: When both switches are closed, the LED remains ON.
* Target Audience: Electronics students and hobbyists learning basic digital logic gates.

Materials

  • V1: 5 V DC power supply or battery pack
  • U1: 74HC32 Quad 2-input OR gate IC
  • S1: SPST toggle switch or push-button, function: Front Door Sensor (Input A)
  • S2: SPST toggle switch or push-button, function: Back Door Sensor (Input B)
  • R1: 10 kΩ resistor, function: pull-down for Input A
  • R2: 10 kΩ resistor, function: pull-down for Input B
  • R3: 330 Ω resistor, function: LED current limiting
  • D1: Red LED, function: Alarm indicator
  • Breadboard and hook-up wires

Pin-out of the IC used

Selected Chip: 74HC32 (Quad 2-input OR gate)

Pin Name Logic function Connection in this case
1 1A Input A (Gate 1) Connected to S1 and R1
2 1B Input B (Gate 1) Connected to S2 and R2
3 1Y Output (Gate 1) Connected to R3 (LED driver)
7 GND Ground Connected to 0 (Negative rail)
14 VCC Positive Supply Connected to 5 V rail

Wiring guide

Construct the circuit on the breadboard following these connections. The node names (e.g., IN_A, VCC) indicate electrical junctions.

  • Power Supply:
    • V1: Positive terminal to node VCC.
    • V1: Negative terminal to node 0 (GND).
  • IC Power:
    • U1 (Pin 14): Connect to VCC.
    • U1 (Pin 7): Connect to 0.
  • Sensor A (Front Door):
    • S1: Connect between VCC and node IN_A.
    • R1: Connect between node IN_A and 0 (Functions as a pull-down resistor to ensure logic 0 when switch is open).
    • U1 (Pin 1): Connect to node IN_A.
  • Sensor B (Back Door):
    • S2: Connect between VCC and node IN_B.
    • R2: Connect between node IN_B and 0 (Functions as a pull-down resistor).
    • U1 (Pin 2): Connect to node IN_B.
  • Output Stage:
    • U1 (Pin 3): Connect to node SIG_OUT.
    • R3: Connect between node SIG_OUT and node LED_ANODE.
    • D1: Anode to node LED_ANODE, Cathode to 0.

Conceptual block diagram

Conceptual block diagram — 74HC32 OR gate

Schematic

[ INPUT SENSORS ]                        [ LOGIC PROCESSING ]                  [ OUTPUT ALARM ]

[ VCC ] --> [ S1: Front Door ] --+--(IN_A)--> [ Pin 1 ] --+
                                 |                        |
                           [ R1: 10k ]                    |
                                 |                        v
                               [ GND ]             +-------------+
                                                   |  U1: 74HC32 |
                                                   |  (OR Gate)  | --(Pin 3)--> [ R3: 330 ] --> [ D1: LED ] --> GND
                                                   +-------------+
                               [ GND ]                    ^
                                 |                        |
                           [ R2: 10k ]                    |
                                 |                        |
[ VCC ] --> [ S2: Back Door  ] --+--(IN_B)--> [ Pin 2 ] --+
Schematic (ASCII)

Electrical diagram

Electrical diagram for case: Practical case: Dual Sensor Alarm System
Generated from the validated SPICE netlist for this case.

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

Truth table

The 74HC32 behaves according to the standard OR logic:

Sensor A (S1) Sensor B (S2) Pin 1 (Volts) Pin 2 (Volts) Output Pin 3 (Volts) LED State
Open Open 0 V 0 V 0 V (LOW) OFF
Open Closed 0 V 5 V 5 V (HIGH) ON
Closed Open 5 V 0 V 5 V (HIGH) ON
Closed Closed 5 V 5 V 5 V (HIGH) ON

Measurements and tests

  1. Supply Check: Before inserting the IC, power up the rails and measure the voltage between VCC and 0. It should read approximately 5 V.
  2. Input Verification:
    • Keep U1 inserted. Measure voltage at Pin 1 relative to GND. It should be 0 V.
    • Press S1. The voltage at Pin 1 should jump to ~5 V.
    • Repeat for S2 and Pin 2.
  3. Logic Logic Test:
    • Ensure both switches are open. Measure Pin 3 (Output); it should be close to 0 V.
    • Close S1 only. Measure Pin 3; it should be close to 5 V. The LED should light up.
    • Close S2 only. Measure Pin 3; it should be close to 5 V. The LED should light up.

SPICE netlist and simulation

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

* Practical case: Dual Sensor Alarm System
* Corrected SPICE Netlist based on BOM and Wiring Guide

* ==============================================================================
* POWER SUPPLY
* ==============================================================================
* V1: 5V DC Supply
* Wiring: Positive to VCC, Negative to 0 (GND)
V1 VCC 0 DC 5

* ==============================================================================
* INPUT SENSORS
* ==============================================================================
* Sensor A: Front Door (S1, R1)
* Wiring: S1 connects VCC to IN_A. R1 connects IN_A to 0 (Pull-down).
* Simulation: S1 is modeled as a voltage-controlled switch driven by a control pulse
* to simulate a button press sequence.
V_CTRL_A CTRL_A 0 PULSE(0 5 10u 1u 1u 100u 200u)
S1 VCC IN_A CTRL_A 0 SW_GEN
R1 IN_A 0 10k

* Sensor B: Back Door (S2, R2)
* Wiring: S2 connects VCC to IN_B. R2 connects IN_B to 0 (Pull-down).
* Simulation: S2 control pulse is offset to test all truth table combinations.
V_CTRL_B CTRL_B 0 PULSE(0 5 10u 1u 1u 200u 400u)
S2 VCC IN_B CTRL_B 0 SW_GEN
R2 IN_B 0 10k

* ==============================================================================
* LOGIC IC: U1 (74HC32)
* ... (truncated in public view) ...

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

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

* Practical case: Dual Sensor Alarm System
* Corrected SPICE Netlist based on BOM and Wiring Guide

* ==============================================================================
* POWER SUPPLY
* ==============================================================================
* V1: 5V DC Supply
* Wiring: Positive to VCC, Negative to 0 (GND)
V1 VCC 0 DC 5

* ==============================================================================
* INPUT SENSORS
* ==============================================================================
* Sensor A: Front Door (S1, R1)
* Wiring: S1 connects VCC to IN_A. R1 connects IN_A to 0 (Pull-down).
* Simulation: S1 is modeled as a voltage-controlled switch driven by a control pulse
* to simulate a button press sequence.
V_CTRL_A CTRL_A 0 PULSE(0 5 10u 1u 1u 100u 200u)
S1 VCC IN_A CTRL_A 0 SW_GEN
R1 IN_A 0 10k

* Sensor B: Back Door (S2, R2)
* Wiring: S2 connects VCC to IN_B. R2 connects IN_B to 0 (Pull-down).
* Simulation: S2 control pulse is offset to test all truth table combinations.
V_CTRL_B CTRL_B 0 PULSE(0 5 10u 1u 1u 200u 400u)
S2 VCC IN_B CTRL_B 0 SW_GEN
R2 IN_B 0 10k

* ==============================================================================
* LOGIC IC: U1 (74HC32)
* ==============================================================================
* Wiring: Pin 1=IN_A, Pin 2=IN_B, Pin 3=SIG_OUT, Pin 7=0, Pin 14=VCC
* Uses a subcircuit to model the OR gate logic
XU1 IN_A IN_B SIG_OUT 0 VCC 74HC32

* ==============================================================================
* OUTPUT STAGE
* ==============================================================================
* Wiring: SIG_OUT -> R3 -> LED_ANODE -> D1 -> 0
R3 SIG_OUT LED_ANODE 330
D1 LED_ANODE 0 LED_RED

* ==============================================================================
* MODELS & SUBCIRCUITS
* ==============================================================================

* Model for Switch (Idealized Push-Button)
.model SW_GEN SW(Vt=2.5 Ron=0.1 Roff=10Meg)

* Model for Red LED
.model LED_RED D(IS=1u N=3 RS=5)

* Subcircuit for 74HC32 (Quad 2-Input OR Gate)
* Implements OR logic: Y = A OR B
* Mathematical implementation using De Morgan's Law for continuous signals:
* Y = 1 - ( (1-A) * (1-B) )  (normalized 0-1 logic)
.subckt 74HC32 A B Y GND_PIN VCC_PIN
    * Sigmoid function to normalize inputs: 1/(1+exp(-20*(V(in)-2.5)))
    * Logic formula: V(Y) = V(VCC) * (1 - ( (1-Sig(A)) * (1-Sig(B)) ))
    B_OR Y GND_PIN V = V(VCC_PIN) * (1 - ( (1 - 1/(1+exp(-20*(V(A)-2.5)))) * (1 - 1/(1+exp(-20*(V(B)-2.5)))) ))
.ends

* ==============================================================================
* ANALYSIS
* ==============================================================================
* Transient analysis to verify truth table (00, 10, 01, 11)
.tran 1u 500u

* Monitor Input and Output Voltages
.print tran V(IN_A) V(IN_B) V(SIG_OUT) V(LED_ANODE)

* Compute DC Operating Point
.op

.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Show raw data table (1202 rows)
Index   time            v(in_a)         v(in_b)         v(sig_out)
0	0.000000e+00	4.995005e-03	4.995005e-03	5.000000e+00
1	1.000000e-08	4.995005e-03	4.995005e-03	5.000000e+00
2	2.000000e-08	4.995005e-03	4.995005e-03	5.000000e+00
3	4.000000e-08	4.995005e-03	4.995005e-03	5.000000e+00
4	8.000000e-08	4.995005e-03	4.995005e-03	5.000000e+00
5	1.600000e-07	4.995005e-03	4.995005e-03	5.000000e+00
6	3.200000e-07	4.995005e-03	4.995005e-03	5.000000e+00
7	6.400000e-07	4.995005e-03	4.995005e-03	5.000000e+00
8	1.280000e-06	4.995005e-03	4.995005e-03	5.000000e+00
9	2.280000e-06	4.995005e-03	4.995005e-03	5.000000e+00
10	3.280000e-06	4.995005e-03	4.995005e-03	5.000000e+00
11	4.280000e-06	4.995005e-03	4.995005e-03	5.000000e+00
12	5.280000e-06	4.995005e-03	4.995005e-03	5.000000e+00
13	6.280000e-06	4.995005e-03	4.995005e-03	5.000000e+00
14	7.280000e-06	4.995005e-03	4.995005e-03	5.000000e+00
15	8.280000e-06	4.995005e-03	4.995005e-03	5.000000e+00
16	9.280000e-06	4.995005e-03	4.995005e-03	5.000000e+00
17	1.000000e-05	4.995005e-03	4.995005e-03	5.000000e+00
18	1.010000e-05	4.995005e-03	4.995005e-03	5.000000e+00
19	1.026000e-05	4.995005e-03	4.995005e-03	5.000000e+00
20	1.030750e-05	4.995005e-03	4.995005e-03	5.000000e+00
21	1.039062e-05	4.995005e-03	4.995005e-03	5.000000e+00
22	1.041363e-05	4.995005e-03	4.995005e-03	5.000000e+00
23	1.045390e-05	4.995005e-03	4.995005e-03	5.000000e+00
... (1178 more rows) ...

Common mistakes and how to avoid them

  1. Floating Inputs: Forgetting R1 or R2 (pull-down resistors).
    • Solution: Logic gates behave unpredictably if inputs are not connected to a definite voltage. Always use pull-down resistors (to ground) or pull-up resistors (to VCC) for mechanical switches.
  2. Missing LED Resistor: Connecting the LED directly to the IC output.
    • Solution: Always include R3 (330 Ω) to limit current. Without it, you may damage the LED or the 74HC32 output stage.
  3. Incorrect IC Orientation: Inserting the 74HC32 backwards.
    • Solution: Locate the notch or dot on the IC package. The notch indicates the end with Pin 1 and Pin 14.

Troubleshooting

  • LED is always ON:
    • Check if R1 or R2 is disconnected (floating inputs often drift HIGH).
    • Verify S1 or S2 are not wired as «normally closed» by mistake.
    • Check for short circuits between VCC and Pin 1/Pin 2.
  • LED never turns ON:
    • Check if the IC is powered (Pin 14 at 5V, Pin 7 at GND).
    • Verify LED polarity (Anode must face the resistor/IC, Cathode to GND).
  • LED is very dim:
    • The value of R3 might be too high (e.g., using 10 kΩ instead of 330 Ω).
    • Power supply voltage might be too low (< 3 V).

Possible improvements and extensions

  1. Latched Alarm: Add a flip-flop or create a latch circuit so the alarm stays ON even after the intruder closes the door (S1/S2 open again), requiring a manual reset.
  2. Audible Alert: Connect an active buzzer in parallel with the LED (driven by a transistor if the current requirement exceeds 20mA) to add sound to the visual alarm.

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 integrated circuit is specified in the text to build the logic circuit?




Question 2: What specific logic function does the 74HC32 IC perform in this circuit?




Question 3: According to the expected outcome, what is the state of the LED when both switches are open (0 V input)?




Question 4: What is the function of the 10 kΩ resistors (R1 and R2) typically found in this type of circuit setup?




Question 5: If Switch A is closed (5 V input) and Switch B is open, what happens to the LED?




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




Question 7: What is the primary purpose of the 330 Ω resistor (R3) connected to the output?




Question 8: What is the expected outcome if both Switch A and Switch B are closed simultaneously?




Question 9: Based on the input levels mentioned (5 V input), what is the appropriate power supply voltage for this circuit?




Question 10: Who is explicitly mentioned as the target audience for 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: Safe Hydraulic Press Control

Safe Hydraulic Press Control prototype (Maker Style)

Level: Basic — Implement a safety logic circuit requiring two simultaneous inputs to activate a load.

Objective and use case

In this practical case, you will build a digital logic circuit that enforces a «two-hand control» safety mechanism. The load (simulated by an LED) will only activate when two separate pushbuttons are pressed simultaneously, preventing accidental operation.

Why it is useful:
* Industrial Safety: Prevents operators from injuring their hands in hydraulic presses or cutting machines by forcing them to use both hands to start the cycle.
* Dual Authorization: Similar logic is used in security systems where two keys or signals are required to authorize an action (e.g., bank vaults).
* Interlock Systems: Ensures multiple conditions (e.g., Door Closed AND Start Button Pressed) are met before a machine runs.

Expected outcome:
* Rest State: The output LED remains OFF when no buttons or only one button is pressed.
* Active State: The output LED turns ON strictly when both buttons are held down.
* Logic Level: The output voltage at the gate pin reads High ($\approx$ 5 V) only during simultaneous activation.
* Visual Feedback: Immediate response from the LED indicating the «Safe to Operate» condition.

Target audience: Students and hobbyists learning basic digital logic and safety interlocks.

Materials

  • U1: 74HC08, function: Quad 2-input AND gate IC.
  • V1: 5 V DC supply, function: Main power source.
  • SW1: Normally Open (NO) Pushbutton, function: Left-hand safety trigger.
  • SW2: Normally Open (NO) Pushbutton, function: Right-hand safety trigger.
  • R1: 10 kΩ resistor, function: Pull-down resistor for Input A.
  • R2: 10 kΩ resistor, function: Pull-down resistor for Input B.
  • R3: 330 Ω resistor, function: Current limiting for output LED.
  • D1: Green LED, function: Indicator for «Motor Active» (Load).

Pin-out of the 74HC08

The 74HC08 contains four independent AND gates. We will use the first gate.

Pin Name Logic function Connection in this case
1 1A Input A Connected to Node A (SW1)
2 1B Input B Connected to Node B (SW2)
3 1Y Output Connected to Node Y (to LED driver)
7 GND Ground Connected to Node 0
14 VCC Supply Voltage Connected to Node VCC (+5V)

Wiring guide

Construct the circuit using the following node connections. Ensure the power supply is off while wiring.

  • Power Nodes:

    • Connect V1 positive terminal to Node VCC.
    • Connect V1 negative terminal to Node 0 (GND).
    • Connect U1 Pin 14 to VCC.
    • Connect U1 Pin 7 to 0.
  • Input A Logic (Left Hand):

    • Connect one side of SW1 to VCC.
    • Connect the other side of SW1 to Node A.
    • Connect R1 between Node A and Node 0 (Pull-down).
    • Connect U1 Pin 1 to Node A.
  • Input B Logic (Right Hand):

    • Connect one side of SW2 to VCC.
    • Connect the other side of SW2 to Node B.
    • Connect R2 between Node B and Node 0 (Pull-down).
    • Connect U1 Pin 2 to Node B.
  • Output Logic (Load):

    • Connect U1 Pin 3 to Node Y.
    • Connect R3 between Node Y and Node LED_ANODE.
    • Connect D1 Anode to Node LED_ANODE.
    • Connect D1 Cathode to Node 0.

Conceptual block diagram

Conceptual block diagram — 74HC08 Quad AND gate

Schematic

Practical case: Safe Hydraulic Press Control

      [ INPUTS / SENSORS ]                  [ LOGIC PROCESSING ]                  [ OUTPUT / ACTUATOR ]

                                            +------------------+
(VCC) --> [ SW1: Left Hand ] --(Node A)---> |      Pin 1       |
               (NO Push)          |         |                  |
                                  v         |    U1: 74HC08    |
                              [ R1: 10k ]   |    (AND Gate)    |
                              (Pull-Down)   |                  | --(Node Y)--> [ R3: 330 ] --> [ D1: Green LED ] --> (GND)
                                  |         |      Pin 3       |               (Limit)         (Motor Active)
                                (GND)       |                  |
                                            |                  |
(VCC) --> [ SW2: Right Hand ]--(Node B)---> |      Pin 2       |
               (NO Push)          |         +------------------+
                                  v
                              [ R2: 10k ]
                              (Pull-Down)
                                  |
                                (GND)

Note: U1 Power Connections (Pin 14 to VCC, Pin 7 to GND) are implied for IC operation.
Schematic (ASCII)

Electrical diagram

Electrical diagram for safe hydraulic press control
Generated from the validated SPICE netlist for this case.

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

Truth table

This circuit implements the Boolean function $Y = A \cdot B$.

SW1 (Input A) SW2 (Input B) Output Y (Logic) LED Status System State
Open (0) Open (0) Low (0) OFF Safe / Stop
Open (0) Closed (1) Low (0) OFF Safe / Stop
Closed (1) Open (0) Low (0) OFF Safe / Stop
Closed (1) Closed (1) High (1) ON Active / Run

Measurements and tests

  1. Preparation: Set your multimeter to DC Voltage mode. Power on the V1 source (5 V).
  2. Idle Check: With no buttons pressed, measure the voltage at Node Y. It should be $\approx$ 0 V. The LED is OFF.
  3. Single Button Test: Press and hold SW1 only. Measure voltage at Node A ($\approx$ 5 V) and Node Y ($\approx$ 0 V). The LED remains OFF.
  4. Single Button Test: Press and hold SW2 only. Measure voltage at Node B ($\approx$ 5 V) and Node Y ($\approx$ 0 V). The LED remains OFF.
  5. Simultaneous Activation: Press both SW1 and SW2. Measure voltage at Node Y. It should read $\approx$ 3.5 V to 4.5 V (depending on the specific HC/LS logic family load and VCC). The LED turns ON.

SPICE netlist and simulation

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

* Practical case: Safe Hydraulic Press Control

.title Safe Hydraulic Press Control

*******************************************************************************
* Component Models
*******************************************************************************

* Pushbutton Switch Model (Ideal Voltage Controlled Switch)
* Simulates the mechanical contact closing when control voltage is high (> 2.5V)
.model SW_PUSH SW(Vt=2.5 Vh=0.1 Ron=0.01 Roff=10Meg)

* LED Model (Green)
* Standard Green LED parameters
.model LED_GREEN D(IS=1e-22 RS=10 N=2 BV=5 IBV=10u CJO=10p TT=10n)

* 74HC08 Quad 2-input AND Gate (Behavioral Model for Simulation)
* Implements one gate of the IC. 
* Pins: 1=InputA, 2=InputB, 3=OutputY, 7=GND, 14=VCC
.subckt 74HC08_GATE 1 2 3 7 14
    * Behavioral Voltage Source using continuous Sigmoid function for convergence
    * Y = VCC * (Sigmoid(A) * Sigmoid(B))
    * Threshold centered at 2.5V with steep slope (k=50)
    B1 3 7 V = V(14) * (1 / (1 + exp(-50 * (V(1) - 2.5)))) * (1 / (1 + exp(-50 * (V(2) - 2.5))))
.ends

*******************************************************************************
* Main Power Supply
*******************************************************************************
* V1: 5V DC supply connected to Node VCC and Node 0 (GND)
* ... (truncated in public view) ...

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

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

* Practical case: Safe Hydraulic Press Control

.title Safe Hydraulic Press Control

*******************************************************************************
* Component Models
*******************************************************************************

* Pushbutton Switch Model (Ideal Voltage Controlled Switch)
* Simulates the mechanical contact closing when control voltage is high (> 2.5V)
.model SW_PUSH SW(Vt=2.5 Vh=0.1 Ron=0.01 Roff=10Meg)

* LED Model (Green)
* Standard Green LED parameters
.model LED_GREEN D(IS=1e-22 RS=10 N=2 BV=5 IBV=10u CJO=10p TT=10n)

* 74HC08 Quad 2-input AND Gate (Behavioral Model for Simulation)
* Implements one gate of the IC. 
* Pins: 1=InputA, 2=InputB, 3=OutputY, 7=GND, 14=VCC
.subckt 74HC08_GATE 1 2 3 7 14
    * Behavioral Voltage Source using continuous Sigmoid function for convergence
    * Y = VCC * (Sigmoid(A) * Sigmoid(B))
    * Threshold centered at 2.5V with steep slope (k=50)
    B1 3 7 V = V(14) * (1 / (1 + exp(-50 * (V(1) - 2.5)))) * (1 / (1 + exp(-50 * (V(2) - 2.5))))
.ends

*******************************************************************************
* Main Power Supply
*******************************************************************************
* V1: 5V DC supply connected to Node VCC and Node 0 (GND)
V1 VCC 0 DC 5

*******************************************************************************
* Input A Logic (Left Hand)
*******************************************************************************
* V_ACT_LEFT: Virtual actuator (Finger) for Left Button
* Generates a pulse: ON for 50us, OFF for 50us (Period 100us)
V_ACT_LEFT CTRL_LEFT 0 PULSE(0 5 0 1u 1u 50u 100u)

* SW1: Left Safety Trigger
* Connects VCC to Node_A when CTRL_LEFT is High
S1 VCC Node_A CTRL_LEFT 0 SW_PUSH

* R1: 10k Pull-down resistor for Input A
R1 Node_A 0 10k

*******************************************************************************
* Input B Logic (Right Hand)
*******************************************************************************
* V_ACT_RIGHT: Virtual actuator (Finger) for Right Button
* Generates a pulse: ON for 100us, OFF for 100us (Period 200us)
* Timing creates overlap with Left button to test AND logic (1+1, 0+1, 1+0, 0+0)
V_ACT_RIGHT CTRL_RIGHT 0 PULSE(0 5 0 1u 1u 100u 200u)

* SW2: Right Safety Trigger
* Connects VCC to Node_B when CTRL_RIGHT is High
S2 VCC Node_B CTRL_RIGHT 0 SW_PUSH

* R2: 10k Pull-down resistor for Input B
R2 Node_B 0 10k

*******************************************************************************
* Logic Processing (U1: 74HC08)
*******************************************************************************
* U1: AND Gate processing Left (A) and Right (B) inputs
* Connections: Pin1=Node_A, Pin2=Node_B, Pin3=Node_Y, Pin7=0(GND), Pin14=VCC
XU1 Node_A Node_B Node_Y 0 VCC 74HC08_GATE

*******************************************************************************
* Output Logic (Load)
*******************************************************************************
* R3: Current limiting resistor (330 Ohm)
R3 Node_Y Node_LED_ANODE 330

* D1: Green LED Indicator (Motor Active)
* Anode to R3, Cathode to GND
D1 Node_LED_ANODE 0 LED_GREEN

*******************************************************************************
* Simulation Commands
*******************************************************************************
* Transient analysis for 250us to cover full truth table sequence
.tran 1u 250u

* Print directives for logging signal states
.print tran V(Node_A) V(Node_B) V(Node_Y) V(Node_LED_ANODE)

.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Show raw data table (786 rows)
Index   time            v(node_a)       v(node_b)       v(node_y)
0	0.000000e+00	4.995005e-03	4.995005e-03	2.199277e-108
1	1.000000e-08	4.995005e-03	4.995005e-03	2.199277e-108
2	2.000000e-08	4.995005e-03	4.995005e-03	2.199277e-108
3	4.000000e-08	4.995005e-03	4.995005e-03	2.199277e-108
4	8.000000e-08	4.995005e-03	4.995005e-03	2.199277e-108
5	1.600000e-07	4.995005e-03	4.995005e-03	2.199277e-108
6	3.200000e-07	4.995005e-03	4.995005e-03	2.199277e-108
7	3.600000e-07	4.995005e-03	4.995005e-03	2.199277e-108
8	4.300000e-07	4.995005e-03	4.995005e-03	2.199277e-108
9	4.493750e-07	4.995005e-03	4.995005e-03	2.199277e-108
10	4.832812e-07	4.995005e-03	4.995005e-03	2.199277e-108
11	5.162979e-07	4.999995e+00	4.999995e+00	5.000000e+00
12	5.474468e-07	4.999995e+00	4.999995e+00	5.000000e+00
13	5.779894e-07	4.999995e+00	4.999995e+00	5.000000e+00
14	6.039341e-07	4.999995e+00	4.999995e+00	5.000000e+00
15	6.320124e-07	4.999995e+00	4.999995e+00	5.000000e+00
16	6.881690e-07	4.999995e+00	4.999995e+00	5.000000e+00
17	8.004820e-07	4.999995e+00	4.999995e+00	5.000000e+00
18	1.000000e-06	4.999995e+00	4.999995e+00	5.000000e+00
19	1.022463e-06	4.999995e+00	4.999995e+00	5.000000e+00
20	1.067388e-06	4.999995e+00	4.999995e+00	5.000000e+00
21	1.157238e-06	4.999995e+00	4.999995e+00	5.000000e+00
22	1.336939e-06	4.999995e+00	4.999995e+00	5.000000e+00
23	1.696341e-06	4.999995e+00	4.999995e+00	5.000000e+00
... (762 more rows) ...

Common mistakes and how to avoid them

  1. Floating Inputs: Forgetting R1 or R2 causes the inputs to «float» when buttons are open, leading to erratic LED flickering or false triggering. Solution: Ensure pull-down resistors connect the inputs to ground.
  2. Confusing 7408 with 7400: The 7408 is an AND gate; the 7400 is a NAND gate. If the LED is ON when buttons are not pressed, you likely used the wrong chip. Solution: Check the markings on the IC package.
  3. LED Polarity: The LED does not light up even when Logic Y is High. Solution: Ensure the longer leg (Anode) faces the resistor/IC and the shorter leg (Cathode) faces Ground.

Troubleshooting

  • Symptom: LED is always ON, regardless of buttons.
    • Cause: Input pins shorted to VCC or incorrect IC (e.g., OR gate 74HC32 used by mistake).
    • Fix: Check wiring at Pins 1 and 2; verify IC part number.
  • Symptom: LED is very dim when both buttons are pressed.
    • Cause: R3 value is too high or VCC is too low.
    • Fix: Ensure R3 is around 220 Ω to 330 Ω; check V1 is 5 V.
  • Symptom: Circuit works for one button but ignores the other.
    • Cause: Broken switch or disconnected jumper wire on one input.
    • Fix: Use a multimeter to verify continuity across SW1 and SW2 when pressed.

Possible improvements and extensions

  1. Power Interface: Replace the LED with an NPN transistor (like 2N2222) and a relay to control a real high-voltage motor.
  2. Master Enable Switch: Add a third switch connected to a third input (using a 3-input AND gate like 74HC11) to act as a «Key Switch» that must be active before the two hand buttons work.

More Practical Cases on Prometeo.blog

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

Go to Amazon

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

Quick Quiz

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




Question 2: Which logic operation is fundamentally required to implement this safety mechanism?




Question 3: What component is used to simulate the load in this practical case?




Question 4: Under what specific condition will the output LED turn ON?




Question 5: What is the expected output voltage at the gate pin during simultaneous activation?




Question 6: Why is this type of circuit useful for industrial safety?




Question 7: What is the state of the output LED when only one button is pressed?




Question 8: Besides industrial safety, what other application is mentioned for this logic?




Question 9: What does an 'Interlock System' ensure according to the text?




Question 10: In the context of the 'Rest State', what happens when no buttons are pressed?




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

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

Follow me: