Build it step by step
0 of 8 doneDraw the truth table
Write it on paper first.
Derive the equations
One per output bit.
Power the breadboard
5 V and GND rails from the Uno.
Place the three chips
Add power pins 14 and 7 on each.
Wire the A2 section
Three gates on U1, test with keys 4 to 7.
Wire A1 and A0
Same pattern on U2 and U3.
Wire the VALID flag
Gate 4 of each chip.
Add the LEDs and test every key
Check the table.
How do you build a keypad encoder with gates?
Turn eight buttons into a 3-bit binary code and a key-pressed flag using only twelve OR gates on three 74HC32 chips. You need 74HC32 quad OR gate × 3, Tactile push button 6 mm × 8, Resistor 10 kΩ × 8, LED 5 mm red × 4, Resistor 330 Ω × 4, Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and Arduino Uno R3. It takes 8 steps and about 120 minutes.
- Level
- Intermediate
- Time
- About 120 min
- Parts
- 8
Parts list
- Integrated CircuitsBuy
- SwitchesBuy
- PassivesBuyResistor 10 kΩ × 8
- SemiconductorsBuyLED 5 mm red × 4
- PassivesBuyResistor 330 Ω × 4
- PrototypingBuy
- PrototypingBuy
- Development BoardsBuyArduino Uno R3 × 1
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Arduino Uno 5V and GND | Breadboard power rails | Supply for all chips (74HC32 allows 2 to 6 V) |
| Each 74HC32 pin 14 and pin 7 | 5 V rail and GND rail | Power every chip |
| Buttons I0 to I7 | Each button from the 5 V rail to its own input node, with a 10 k from that node to GND | Active-high inputs |
| U1 gate 1 (pins 1,2 to 3) | I4 and I5 in, output to pin 9 | First half of A2 |
| U1 gate 2 (pins 4,5 to 6) | I6 and I7 in, output to pin 10 | Second half of A2 |
| U1 gate 3 (pins 9,10 to 8) | Pin 8 is A2 | MSB of the code |
| U2 gates 1 and 2 | I2 or I3, and I6 or I7, combined by gate 3 pin 8 | A1 (same wiring pattern as U1) |
| U3 gates 1 and 2 | I1 or I3, and I5 or I7, combined by gate 3 pin 8 | A0 (same wiring pattern) |
| U1 gate 4 (pins 12,13 to 11) | A2 and A1 in | Part of the valid flag |
| U2 gate 4 (pins 12,13 to 11) | A0 and I0 in | Part of the valid flag |
| U3 gate 4 (pins 12,13 to 11) | U1 pin 11 and U2 pin 11 in | Pin 11 is the VALID output |
| A2, A1, A0, VALID | Each through a 330 Ω to an LED to GND | Display the code |
Code
A priority-free encoder is just OR gates: each output bit is the OR of every key whose number has that bit set to one. Key 5 is binary 101, so it feeds A2 and A0. Key 0 is 000 and feeds nothing, which is why the VALID output exists: without it you could not tell key 0 from no key. A 74HC32 holds four two-input OR gates, so a four-input OR takes three gates, two in the first layer and one to join them. All twelve gates across three chips are used. Power it from the 5 V pin of an Uno over USB. No input is left floating because every key node has a pull-down resistor. Press two keys at once and the codes OR together, for example keys 1 and 2 give 3. That is the reason real encoders such as the 74HC148 add priority logic so the highest key wins; try replacing this circuit with a 74HC148 and compare. Build it on the breadboard one output at a time and test with a multimeter or the LEDs before adding the next.
Truth table for the encoder (inputs are active high, 1 means pressed) Key A2 A1 A0 Valid I0 0 0 0 1 (needs the valid flag, otherwise it looks like "nothing pressed") I1 0 0 1 1 I2 0 1 0 1 I3 0 1 1 1 I4 1 0 0 1 I5 1 0 1 1 I6 1 1 0 1 I7 1 1 1 1 none 0 0 0 0 Boolean equations (each OR gate has two inputs, so chain them) A2 = I4 + I5 + I6 + I7 = (I4 + I5) + (I6 + I7) A1 = I2 + I3 + I6 + I7 = (I2 + I3) + (I6 + I7) A0 = I1 + I3 + I5 + I7 = (I1 + I3) + (I5 + I7) VALID = I0 + A2 + A1 + A0 = (A2 + A1) + (A0 + I0) Gate count: three for each of A2, A1, A0 (nine) plus three for VALID (twelve) = exactly three 74HC32 chips. 74HC32 pinout (top view, notch up): Gate 1: 1A 1B 1Y are pins 1,2,3 | Gate 2: 2A 2B 2Y are pins 4,5,6 | GND is pin 7 3Y 3A 3B are 8,9,10 | 4Y 4A 4B are 11,12,13 | VCC is 14
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Press no key | All four LEDs off |
| Press key 0 | Only VALID lights |
| Press key 5 | A2, A0 and VALID light |
| Press key 7 | All four light |
| Press keys 1 and 2 together | Output shows 3, the OR of both |
If it does not work
Random LED flicker
An input is floating; check each 10 k pull-down.
Everything lights
Input node touching the 5 V rail, or a missing GND on a chip.
One output stuck
Check the gate pins against the pinout and the chain between layers.
Chip gets warm
Supply wired backwards; unplug at once and check pin 14 and pin 7.
Key 0 shows nothing
Expected on A outputs; VALID must light.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the keypad encoder with gates?
74HC32 quad OR gate × 3, Tactile push button 6 mm × 8, Resistor 10 kΩ × 8, LED 5 mm red × 4, Resistor 330 Ω × 4, Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and Arduino Uno R3.
How long does the keypad encoder with gates take to build?
About 120 minutes for a intermediate maker, in 8 steps.
How do I know the keypad encoder with gates works?
Press no key: All four LEDs off. Press key 0: Only VALID lights. Press key 5: A2, A0 and VALID light.
Random LED flicker: what should I check?
An input is floating; check each 10 k pull-down.
Everything lights: what should I check?
Input node touching the 5 V rail, or a missing GND on a chip.
One output stuck: what should I check?
Check the gate pins against the pinout and the chain between layers.
Chip gets warm: what should I check?
Supply wired backwards; unplug at once and check pin 14 and pin 7.
