VIN Technologies › Labs › Microcontroller Lab
Button press counter (Serial output)
Microcontroller Lab · free online experiment, runs in your browser with no install or sign-up.
Open this experiment in the circuit simulator
Objective
Count the rising edges of a push button on pin 2 and print the running total on the Serial monitor.
Procedure
- Press Start Simulation and open the Serial tab: count=1 … count=4.
- Change the button's press pattern to add more presses.
Theory
Edge detection: a press is counted when the pin changes from LOW to HIGH, not while it stays HIGH. The button pattern 0101010100 at 0.5 s steps gives four presses.
Questions to answer
- What happens if the contact bounces?
Components used
Arduino UNO R3 (clone, SMD), Breadboard 400 points, LED 5mm Red, Push Button tactile 6x6, 2 × Resistor 220 ohm 1/4W
About the model
Breadboard contacts are ideal (no contact resistance or capacitance). Arduino-style C/C++ subset interpreter (not AVR machine code): no interrupts or libraries, int is 16-bit, only delay() advances time, pin modes are fixed after setup(). Outputs are 5 V behind 25 Ω.
Open this experiment in the circuit simulator