Skip to Content

ATtiny85 Button LED: Internal Pull-Up Fun

Learn to read a button and light an LED on the ATtiny85 using the built-in pull-up resistor.
May 12, 2026 by
ATtiny85 Button LED: Internal Pull-Up Fun
Velxio

Welcome to the world of the ATtiny85! This tiny but mighty microcontroller is perfect for small embedded projects. In this tutorial, we'll wire up a simple button and LED. Press the button, and the LED lights up — it's a classic "hello world" of digital input and output.

The secret ingredient is the internal pull-up resistor on the input pin. That means you don't need an external resistor for the button — just connect it directly between the pin and ground. We'll use pin PB0 for the button and PB1 for the LED. The circuit is minimal, and the code is straightforward. Let's dive in!

Circuit Walkthrough

The components are few: an ATtiny85 microcontroller, a green pushbutton, and a red LED. Here's how they connect:

  • Button (tiny-btn1): One leg (pin 1.l) connects to the ATtiny85's PB0 via a yellow wire. The other leg (2.l) connects to GND (black wire). This wiring lets the pin read HIGH (by default) and LOW when the button is pressed (because it pulls the pin to ground).
  • LED (tiny-led1): The anode (pin A) connects to PB1 via a red wire. The cathode (pin C) connects to GND via another black wire. The LED lights up when PB1 goes HIGH.

That's it — two components, four wires. No external resistor for the button (thanks to the internal pull-up), and the LED uses the ATtiny85's current-limited GPIO (safe for a standard LED at low current). Here's the bill of materials:

ComponentQuantityNotes
ATtiny85 microcontroller1DIP-8 package
Pushbutton (green)1Normally open, momentary
Red LED1Any standard 5mm LED
Jumper wires4Yellow, red, black (2x)

Code Walkthrough

The firmware is written in Arduino-style C++ and is only a few lines. Let's break it down:

// ATtiny85 — Button on PB0, LED on PB1
// Button wiring: one leg to PB0, other leg to GND
// INPUT_PULLUP means HIGH = released, LOW = pressed

void setup() {
  pinMode(0, INPUT_PULLUP);  // PB0 — button with internal pull-up
  pinMode(1, OUTPUT);         // PB1 — LED
}

void loop() {
  bool pressed = (digitalRead(0) == LOW);
  digitalWrite(1, pressed ? HIGH : LOW);
}

In setup(), we configure pin 0 (PB0) as an input with the internal pull-up resistor enabled. This means the pin reads HIGH when the button is not pressed (because the pull-up connects it to Vcc) and LOW when the button connects it to GND. Pin 1 (PB1) is set as an output to drive the LED.

In loop(), we read the button state: digitalRead(0) returns HIGH (1) or LOW (0). We check if it's LOW to indicate a press. Then we write that condition to the LED pin: if pressed, output HIGH (LED on); otherwise LOW (LED off). The result is immediate, responsive button control.

Key Concepts You'll Learn

  • Digital I/O: Configuring pins as input or output and reading/writing digital values.
  • Internal Pull-Up Resistor: Saves components and simplifies wiring. Must remember that INPUT_PULLUP inverts the logic: press = LOW.
  • Pin Mapping: On an ATtiny85, the Arduino pin numbers correspond to the GPIO pin names (e.g., pin 0 = PB0, pin 1 = PB1).
  • Minimal Circuit Design: How to make a functional project with only a few components.

Common Pitfalls & Debugging Tips

  • Button not working? Check your wiring — the button legs can be tricky. Ensure one leg goes to PB0 and the other to GND. Swapping them won't break anything; just press and see if the logic flips.
  • LED always on or off? Verify the LED polarity. The anode (long leg) must go to PB1, cathode to GND. An inverted LED won't light.
  • Pull-up confusion: Remember, with INPUT_PULLUP, the pin reads HIGH when the button is open, and LOW when closed. Your code must account for this.
  • Pin numbers: On ATtiny85, Arduino pin numbers match the chip pin numbers for PB0 (pin 5), PB1 (pin 6), etc. Double-check your wiring against the datasheet.

Suggested Extensions & Variations

  • Toggle Mode: Modify the code so the LED toggles on each button press instead of staying on only while pressed.
  • Multiple LEDs: Add more LEDs on other pins (e.g., PB2, PB3) and create a sequence with each press.
  • Debouncing: Add a small delay or a debounce library to avoid flickering on mechanical button bounce.
  • Analog Input: Replace the button with a potentiometer on an analog pin (e.g., PB2 which also is ADC1) to control LED brightness via PWM.

Try It Yourself on Velxio

Want to see this circuit in action without soldering? Head over to the live example on Velxio — the in-browser circuit simulator with SPICE-accurate analog support. You can run the code, tinker with the wiring, and even modify the firmware on the fly. No hardware required!

Click here to open the ATtiny85 Button LED project on Velxio and start experimenting now.

ATtiny85: Blink Built-in LED on PB1
Learn to program the tiny 8-bit ATtiny85 and blink its onboard LED with just a few lines of Arduino code.