A button on pin D2 (INPUT_PULLUP) controls the LED on D13: released = HIGH (LED off), pressed to ground = LOW (LED on). Toggle the switch by clicking it.
This page is a utility for simulating atmega328p button-controlled led (input_pullup) online with specified initial values.
In this example, the ATmega328P microcontroller demonstrates how to use a digital input and its built-in pull-up resistor. The tact switch is connected to digital pin D2, which operates in INPUT_PULLUP mode, and the LED is connected to pin D13 via a 220 ohm current-limiting resistor.
After running the program, in the setup() function, pin D2 is configured as an input with an internal pull-up to the +5 V supply voltage using the INPUT_PULLUP mode, and pin D13 is configured as a digital output. Thanks to the built-in pull-up resistor, an external resistor is not required.
In the loop() function, the microcontroller continuously reads the state of the pushbutton using the digitalRead(D2) function. While the pushbutton is not pressed, input D2 remains pulled up to the supply voltage, resulting in a logic high (HIGH), and the LED remains off. When the pushbutton is pressed, the input is shorted to ground (GND), resulting in a logic low (LOW). The program detects the state change and turns on the LED, sending a high logic level to pin D13. After the button is released, the input goes back to the HIGH state, and the LED goes out.
During simulation, the button state can be changed with a simple mouse click, allowing you to observe the change in the logic level at the microcontroller input and the corresponding program response in real time. This example demonstrates one of the most common methods for connecting buttons to microcontrollers using an internal pull-up resistor, which eliminates the possibility of an undefined ("floating") input state.
The program source code, containing the standard setup() and loop() functions, can be edited directly in the microcontroller properties. After making changes, the sketch is automatically compiled and uploaded to the ATmega328P model, allowing you to explore various methods of processing button signals, implement inverted control logic, software debounce, and other algorithms for processing digital inputs.









Comments