This project demonstrates how to interface a push button switch with the Arduino UNO (ATmega328P) using register-level programming, without any Arduino functions.
- Arduino UNO (ATmega328P)
- Push Button Switch
- LED (for output indication)
- 220Ξ© Resistor (LED current limit)
- Optional: Pull-down resistor (if not using internal pull-up)
| Component | Function | Arduino Pin | Port |
|---|---|---|---|
| Push Button | Input | D2 | PD2 |
| LED | Output | D12 | PB4 |
| VCC | Power | +5V | β |
| GND | Ground | GND | β |
DDRB |= (1 << DDB4)β Configures PB4 as output (LED).DDRD &= ~(1 << DDD2)β Configures PD2 as input (button).PORTD |= (1 << PD2)β Activates internal pull-up resistor.- Logic check:
- Pressed (LOW) β LED ON
- Released (HIGH) β LED OFF
- When the button is pressed, PD2 goes LOW, LED turns ON.
- When released, PD2 goes HIGH (via pull-up), LED turns OFF.
- Compile using AVR-GCC, Atmel Studio, or PlatformIO.
- Upload the HEX file to Arduino UNO.
- Watch the LED respond instantly to button presses.