Arduino Circuits

Two-Button AND Logic

A simple AND-gate application that lights an LED only when two buttons are pressed at the same time.

November 22, 20264 min read
Two-Button AND Logic — Arduino circuit built on a breadboard, showing components and connections
Two-Button AND Logic circuit breadboard layout, components and jumper connections.

Interactive circuit guide

Run the simulation, follow the build steps one by one and try it in our real app.

Real screenshot of our circuit simulator Stopped
Open in our app →

Step-by-step build

What is it for?

In this circuit, two buttons are connected to two separate digital input pins. Each input point is pulled to the 5-volt rail through a 10-kilohm resistor; when a button is pressed, the corresponding pin is connected to ground. The red LED is fed from a third output pin through a 220-ohm series resistor. The software continuously checks whether both buttons are pressed and lights the LED only when both are pressed together. This is a software AND gate: if either input is floating, the output stays LOW. The project teaches reading multiple inputs at once, the logical AND operation and the use of safe pull-up resistors together.

Parts list

The following components are used to build this project:

  • Arduino Uno — Reads the two inputs and applies the AND logic.
  • Button — Produces two separate input signals (×2).
  • 10kΩ Resistor — Keeps each input at HIGH level while released (×2).
  • Red LED — Shows the logic result.
  • 220Ω Resistor — Limits the current through the LED.
  • Ground — Common reference for the two buttons and the LED.

Step-by-step build

  1. Place the board and put the two buttons on the lower row.Use two separate rows to keep the buttons apart.
  2. Connect one end of each button to the common ground rail.Both buttons can share the same ground line.
  3. Connect the other ends of the buttons to two separate input pins.Choose a different pin for each input.
  4. Pull each input node to the 5-volt rail through its own 10-kohm resistor.Without the resistors the inputs would float.
  5. Connect the red LED to a third output pin with a 220-ohm resistor.Take the LED cathode to common ground.
  6. Upload the code; the LED lights up only when both buttons are pressed.The logic expression must use AND.

How it works

Thanks to its own 10-kilohm pull-up resistor, each button keeps the input pin at HIGH (logic 1) when not pressed. When a button is pressed, the pin is connected to ground and LOW (logic 0) is read. The software reads both inputs and applies a logical AND operation: the output pin is set HIGH and the LED lights only when both inputs are LOW at the same time. If either input is floating, the output stays LOW. This behaviour is the software equivalent of a hardware AND gate. Separate pull-up resistors prevent the two inputs from affecting each other, while the common ground keeps the buttons and the LED at the same reference level.

The two buttons sit side by side on the lower rows. Each button's input node goes to the 5-volt rail through its own 10-kohm resistor, and the other end goes to the common ground rail. The red LED and the 220-ohm resistor are on the upper row, on a separate output pin. The ground rail returns to the board with one GND wire.

What you will learn

  • Reads two digital inputs at the same time.
  • Applies the logical AND operation in code.
  • Explains why each input needs its own pull-up resistor.
  • Interprets active-low inputs correctly.

Tips

  • If the LED lights with one button, the code may be using OR instead of AND.
  • If two inputs share a resistor, the buttons affect each other.
  • If the inputs still read HIGH when pressed, check the ground connection.

Try it yourself

  • Press each button separately and verify that the LED stays off.
  • Press both buttons together and observe that the LED lights up.
  • Change the logic from AND to OR and compare the behaviour.

Getting the parts

Frequently asked questions

What does this circuit do?

A simple AND-gate application that lights an LED only when two buttons are pressed at the same time.

How does the circuit work?

Thanks to its own 10-kilohm pull-up resistor, each button keeps the input pin at HIGH (logic 1) when not pressed. When a button is pressed, the pin is connected to ground and LOW (logic 0) is read. The software reads both inputs and applies a logical AND operation: the output pin is set HIGH and the LED lights only when both inputs are LOW at the same time. If either input is floating, the output stays LOW. This behaviour is the software equivalent of a hardware AND gate. Separate pull-up resistors prevent the two inputs from affecting each other, while the common ground keeps the buttons and the LED at the same reference level.

What is the expected result?

The red LED lights up only when both buttons are pressed at the same time.

You may also like

Try the circuit in the simulator

Open the diagram in your browser, inspect the connections and follow the steps.