Arduino AND Gate Truth Table: Wiring, Code and Simulator
To build this Arduino AND Gate Truth Table project you need an Arduino Uno and an AND gate, a 220 Ω resistor and a green LED. Pins 2 and 3 drive an AND gate; pin 4 reads its output and an LED shows it. Make the 6 connections in the wiring table, upload the Arduino C++ code, and watch the truth table print. Swap the AND for an OR or XOR gate and compare.
Open this circuit in the free Arduino Uno simulator
Parts list
| Qty | Part | What it does |
|---|---|---|
| 1 | Arduino Uno | the microcontroller board |
| 1 | AND Gate | OUT is HIGH when all inputs are HIGH. Set 2–8 inputs in the inspector. |
| 1 | 220 Ω resistor | Limits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down. |
| 1 | green LED | Lights when A (anode, the bent leg) is high and C (cathode) is low. Use a resistor. |
Wiring
| # | From | To |
|---|---|---|
| 1 | Arduino Uno pin 2 | AND Gate A |
| 2 | Arduino Uno pin 3 | AND Gate B |
| 3 | Arduino Uno pin 4 | AND Gate OUT |
| 4 | AND Gate OUT | 220 Ω resistor leg 1 |
| 5 | 220 Ω resistor leg 2 | green LED anode (A, long leg) |
| 6 | Arduino Uno GND | green LED cathode (C, short leg) |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
- Add the parts. Add an AND gate, a 220 Ω resistor and a green LED from the parts palette.
- Wire 1. Connect Arduino Uno pin 2 to AND Gate A.
- Wire 2. Connect Arduino Uno pin 3 to AND Gate B.
- Wire 3. Connect Arduino Uno pin 4 to AND Gate OUT.
- Wire 4. Connect AND Gate OUT to 220 Ω resistor leg 1.
- Wire 5. Connect 220 Ω resistor leg 2 to green LED anode (A, long leg).
- Wire 6. Connect Arduino Uno GND to green LED cathode (C, short leg).
- Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
- Run it. Press Run. Watch the truth table print. Swap the AND for an OR or XOR gate and compare.
Arduino C++ code
// Logic gates: pins 2 and 3 feed an AND gate; pin 4 reads its output back.
// The sketch walks the truth table and prints what the gate answers.
void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, INPUT);
Serial.begin(9600);
Serial.println("A B | A AND B");
}
void loop() {
for (int a = 0; a <= 1; a++) {
for (int b = 0; b <= 1; b++) {
digitalWrite(2, a);
digitalWrite(3, b);
delay(5);
Serial.print(a);
Serial.print(" ");
Serial.print(b);
Serial.print(" | ");
Serial.println(digitalRead(4));
delay(600);
}
}
Serial.println("---");
}
What to try
Watch the truth table print. Swap the AND for an OR or XOR gate and compare.
Frequently asked questions
How do I wire the AND Gate Truth Table project on an Arduino Uno?
Make 6 connections: Arduino Uno pin 2 to AND Gate A; Arduino Uno pin 3 to AND Gate B; Arduino Uno pin 4 to AND Gate OUT; AND Gate OUT to 220 Ω resistor leg 1; 220 Ω resistor leg 2 to green LED anode (A, long leg); Arduino Uno GND to green LED cathode (C, short leg).
What parts do I need for this Arduino project?
An Arduino Uno and an AND gate, a 220 Ω resistor and a green LED.
Can I simulate this Arduino project online for free?
Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.
What does the code do?
Pins 2 and 3 drive an AND gate; pin 4 reads its output and an LED shows it.
More Arduino Uno projects
- Arduino LED Blink: Wiring, Code and Simulator
- Arduino LDR Light Sensor: Wiring, Code and Simulator
- Arduino NTC Thermistor Thermometer: Wiring, Code and Simulator
- Arduino PWM to Analog RC Filter: Wiring, Code and Simulator
- Arduino Capacitance Meter: Wiring, Code and Simulator
- Arduino DC Motor PWM Speed Control with MOSFET: Wiring, Code and Simulator