Gate lab
Two buttons drive an AND, an XOR and a NOT, so the truth table lights up as you press. There is no microcontroller in it: the simulator solves the 13 parts as a circuit, so it runs the moment you press Run, and nothing needs compiling.
Teaching? Assign it to your class in one click.
Beginner About 15 minutes to build and run. Runs in your browser. Free, and no account needed.
Build it as the Logic Lab Kit: the parts in numbered bags and a booklet that checks every step. Retails for about $8.60, free on Mokxi.
What you'll learn
- AND, XOR and NOT gates and their truth tables
- Pull-down resistors for button inputs
- Why a floating input is not a zero
- Driving an LED from a gate output
- Difficulty: Beginner
- Time: About 15 minutes
- Parts: 15
How it works
Two pushbuttons feed three logic gates. Pressing a button sends 5 V to that button's gate inputs. Button A goes to an AND gate, an XOR gate and an inverter. Button B goes to the AND and XOR gates.
Each gate output drives an LED through a 220 ohm resistor: green for AND, yellow for XOR and blue for NOT A. Hold A, B or both and the lamps follow the truth table. AND lights only with both pressed, XOR lights with exactly one, and NOT A is lit while A is released.
Two 10k resistors pull the inputs to ground when the buttons are open. A button can only connect, not disconnect, so without them a released input would float.
Parts list
15 parts, plus the jumper wires. They retail for about $5.75; on Mokxi they're free.
- 1 × Full-size breadboard
- 1 × Power, 5 V
- 2 × PushbuttonIn Starter Kit, Christmas Lights Kit, Logic Lab Kit.
- 2 × Resistor, 10k ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 2 × Logic gateIn Logic Lab Kit.
- 1 × InverterIn Logic Lab Kit.
- 3 × Resistor, 220 ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 1 × LED, greenIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
- 1 × LED, yellowIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
- 1 × LED, blueIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| Pushbutton (1) pin 2a | 5 V |
| Pushbutton (2) pin 2a | 5 V |
| Resistor, 10k Ω (1) pin 1 | Ground |
| Resistor, 10k Ω (2) pin 1 | Ground |
| LED, green pin C | Ground |
| LED, yellow pin C | Ground |
| LED, blue pin C | Ground |
| Resistor, 10k Ω (1) pin 2 | Pushbutton (1) pin 1a |
| Logic gate (1) pin A | Pushbutton (1) pin 1a |
| Logic gate (2) pin A | Pushbutton (1) pin 1a |
| Inverter pin A | Pushbutton (1) pin 1a |
| Resistor, 10k Ω (2) pin 2 | Pushbutton (2) pin 1a |
| Logic gate (1) pin B | Pushbutton (2) pin 1a |
| Logic gate (2) pin B | Pushbutton (2) pin 1a |
| Resistor, 220 Ω (1) pin 1 | Logic gate (1) pin Y |
| Resistor, 220 Ω (2) pin 1 | Logic gate (2) pin Y |
| Resistor, 220 Ω (3) pin 1 | Inverter pin Y |
| LED, green pin A | Resistor, 220 Ω (1) pin 2 |
| LED, yellow pin A | Resistor, 220 Ω (2) pin 2 |
| LED, blue pin A | Resistor, 220 Ω (3) pin 2 |
The notes that come with it
There is no microcontroller in this one, so nothing is compiled: the simulator solves the circuit itself. The file in the editor is the notes that come with it.
// A logic lab: AND, XOR and NOT, wired by hand.
//
// Hold button A, button B, or both, and read the three LEDs:
//
// A B AND XOR NOT A
// 0 0 0 0 1
// 1 0 0 1 0
// 0 1 0 1 1
// 1 1 1 0 0
//
// The two 10 k resistors are pull-downs. A button can only connect a net to
// something; it cannot disconnect it. Without the pull-down the gate input
// would be left floating the moment you let go, and a floating CMOS input is
// not a zero. It is whatever the last charge on it happened to be.
//
// The gates here are the ideal kind: no supply pins, a few nanoseconds of
// propagation delay, and a push-pull 5 V output. The 74HC chips in the other
// examples are the real thing, with a supply you have to wire and a delay you
// can measure.
Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- A lamp flickers or changes by itself. This project
The input is floating. Make sure each 10k pull-down goes from the gate input net to ground. - The blue lamp is lit when nothing is pressed. This project
That is correct. NOT A is high while button A is released. - The input reads random HIGH and LOW when the button is not pressed. Pushbutton
A floating pin picks up noise. Add a 10 k pull-down or pull-up resistor, or use INPUT_PULLUP and wire the button between the pin and GND. Then pressed reads LOW. - The button seems always pressed, or never changes. Pushbutton
A 4-leg tactile switch has legs joined in pairs. Place it across the breadboard center gap so the pairs sit on different rows. Wired along one side, the legs are already connected. - The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure. - A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground. - The output sits at a random level. Logic gate
Never leave a gate input floating. Tie unused inputs to the supply or ground, or add pull-up or pull-down resistors to the inputs. - The truth table seems wrong. Logic gate
Check which gate type you chose. NAND, NOR and XOR invert or differ from AND and OR. Test each input combination with LEDs at the output.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.