
Interactive circuit guide
Run the simulation, follow the build steps one by one and try it in our real app.
Stopped
Step-by-step build
What is it for?
In this project, the button is connected to an input pin that uses the internal pull-up resistor, with no external resistor needed, and its other end goes to ground. Two LEDs are fed from two separate output pins through their own 220-ohm series resistors. On every button press, the software increments a counter and displays the binary digits of that value on the LEDs: the first LED represents the low bit and the second LED the high bit. The numbers 0, 1, 2 and 3 can therefore be followed through the on-off combinations of the two LEDs. State change detection is used to capture button presses. This circuit teaches counter logic, the binary number system and input state detection together.
Parts list
The following components are used to build this project:
- Arduino Uno — Counts button presses and drives the binary display.
- Button — Trigger input that increments the counter.
- Red LED — Shows the low bit of the binary number.
- Green LED — Shows the high bit of the binary number.
- 220Ω Resistor — One separate current limiter for each LED (×2).
- Ground — Common reference for the button and the LEDs.
Step-by-step build
- Place the board and put the button on the lower row.One end of the button will go to the input pin, the other to ground.
- Place the two LEDs and their 220-ohm resistors on the upper rows.Each LED must have its own resistor.
- Connect the resistors to two separate output pins.Name the pins low bit and high bit in the code.
- Meet the LED cathodes and the button's ground end on the common rail.A single GND line is enough.
- Connect the ground rail to the board's GND pin.A common reference is required for the internal pull-up.
- Upload the code; with each press the LED combination shows 0, 1, 2, 3 in order.Detect the press with a state change.
How it works
The input pin is held connected to the supply voltage through the internal pull-up resistor; when the button is pressed, the pin is pulled to ground and reads LOW. The software increments the counter at the moment the pin goes from HIGH to LOW; holding the button down does not make the value keep increasing. The counter value is displayed on two LEDs in binary form: the low bit is connected to the first LED and the high bit to the second. The values 0, 1, 2 and 3 correspond to four different on-off combinations of the LEDs. The 220-ohm resistors limit the current through each LED. This circuit teaches basic counter logic by combining state-change detection with binary number display.
The button is on the lower row; one end goes to the input pin and the other to the common ground rail. The two LEDs and their 220-ohm resistors are on the upper rows, on two separate output pins. The LED cathodes and the button's ground end meet on the same rail, which returns to the board with one GND wire.
What you will learn
- Counts button presses by detecting state changes.
- Interprets the binary number system with LED combinations.
- Explains the use of the internal pull-up resistor.
- Controls multiple outputs with a numeric value.
Tips
- If the number increases by more than one per press, the state-change check is missing.
- If the LED combination does not follow binary order, check the bit order.
- If the number increases without pressing, the input pin may be floating.
Try it yourself
- Press four times and verify that the LED combination follows 0, 1, 2, 3.
- Hold the button down and observe that the counter stays constant.
- Add a third LED to set up a display for the 0-7 range.
Getting the parts
If you want to build this project in real life, you can get the parts from hobidevre.com. For more circuit ideas, visit the hobidevre.com blog.
Frequently asked questions
What does this circuit do?
Increment a counter on every button press and show the number's binary equivalent on two LEDs.
How does the circuit work?
The input pin is held connected to the supply voltage through the internal pull-up resistor; when the button is pressed, the pin is pulled to ground and reads LOW. The software increments the counter at the moment the pin goes from HIGH to LOW; holding the button down does not make the value keep increasing. The counter value is displayed on two LEDs in binary form: the low bit is connected to the first LED and the high bit to the second. The values 0, 1, 2 and 3 correspond to four different on-off combinations of the LEDs. The 220-ohm resistors limit the current through each LED. This circuit teaches basic counter logic by combining state-change detection with binary number display.
What is the expected result?
The counter increments on every button press and the two LEDs show the binary equivalent.