Skip to Content

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.
May 12, 2026 by
David Montero

Introduction

The ATtiny85 is a small, low-power 8-bit microcontroller from Microchip (formerly Atmel). Despite its tiny 8-pin package, it packs enough punch for many simple projects—from blinking LEDs to sensor reading and PWM control. In this tutorial, we'll run the classic Blink sketch on the ATtiny85's built-in LED connected to pin PB1 (physical pin 6). No external components required! This is the perfect first project for anyone new to the ATtiny85 or the Arduino environment.

We'll walk through the circuit (which is just the ATtiny85 itself), explain the firmware line by line, and discuss key concepts like digital I/O, pin numbering, and timing with delays. Let's dive in!

Circuit Walkthrough

Unlike many microcontroller projects, this one requires zero external components. The ATtiny85 (on a breakout board like the Digispark or a bare chip on a breadboard) has an LED already connected to PB1. Here's the wiring:

  • Power: Connect VCC (pin 8) to +5V and GND (pin 4) to ground.
  • Built-in LED: The LED is internally connected between PB1 (pin 6) and ground through a current-limiting resistor (usually ~1kΩ). No external wiring needed.

That's it! The board itself is the entire circuit. If you're using a bare ATtiny85, you'll need an ISP programmer (like USBasp) to upload the code, but many development boards (e.g., Digispark) come with a USB bootloader.

Below is the Bill of Materials for this minimal setup:

ComponentValueQuantity
ATtiny85 microcontroller—1
Breadboard (optional)—1
USB-to-serial adapter or ISP programmer—1

No resistors, capacitors, or LEDs are needed—the built-in LED on PB1 is ready to go.

Code Walkthrough

The firmware is written in Arduino C++ and is straightforward. Let's break it down block by block.

// ATtiny85 — Blink built-in LED on PB1
// Pin 1 = PB1 = OC0B/OC1A (also Digispark LED)

void setup() {
  pinMode(1, OUTPUT);  // PB1 as output
}

void loop() {
  digitalWrite(1, HIGH);
  delay(500);
  digitalWrite(1, LOW);
  delay(500);
}

Comments and Pin Mapping

The first lines are comments explaining that pin 1 in the Arduino environment corresponds to PB1 (physical pin 6 on the ATtiny85). This pin is also used as OC0B/OC1A for PWM, but here we use it as a simple digital output.

Setup Function

void setup() runs once at power-up or reset. The single line pinMode(1, OUTPUT); configures digital pin 1 (PB1) as an output. This allows us to drive the LED high or low.

Loop Function

void loop() runs repeatedly forever:

  • digitalWrite(1, HIGH); — sets pin 1 to 5V (high), turning the LED on.
  • delay(500); — waits 500 milliseconds (half a second).
  • digitalWrite(1, LOW); — sets pin 1 to 0V (low), turning the LED off.
  • delay(500); — waits another 500 milliseconds.

This creates a 1-second blink cycle (500 ms on, 500 ms off).

Key Concepts Students Should Learn

  • Digital I/O pins: Microcontrollers can read or write digital signals (HIGH = 5V or 3.3V, LOW = 0V). The pinMode() and digitalWrite() functions control these pins.
  • Arduino pin numbering vs. physical pin numbers: On ATtiny85, Arduino pin 1 is PB1 (physical pin 6). Always check the datasheet or board pinout diagram.
  • Delay-based timing: delay() blocks execution for a set number of milliseconds. It's simple but prevents the microcontroller from doing other work during the delay.
  • Built-in peripherals: Many development boards have an LED on a specific pin—learn to identify it and use it for debugging.

Common Pitfalls and Debugging Tips

  • Wrong pin number: If the LED doesn't blink, double-check that you're using pin 1 (PB1). Some ATtiny85 boards use different pins for the built-in LED (e.g., Digispark uses pin 1).
  • Bootloader issue: If using a Digispark, make sure you've installed the correct board definitions and the driver for the USB connection. The upload process may require plugging the board at the right moment.
  • Power supply: Ensure VCC is between 2.7V and 5.5V (check datasheet). Low voltage may prevent the LED from lighting.
  • Misconfigured fuse bits: If using an ISP programmer, incorrect fuse settings can change the clock speed or disable the reset pin. The default fuses are usually fine for this sketch.

Suggested Extensions and Variations

  1. Change the blink rate: Adjust the delay() values to make the LED blink faster or slower. Try 100 ms and 1000 ms to see the difference.
  2. Use PWM for fading: Replace digitalWrite() with analogWrite() on pin 1 to fade the LED. Note that PB1 supports PWM via Timer0 (OC0B). Example: analogWrite(1, 128); for 50% brightness.
  3. Add an external LED: Connect an external LED with a ~220Ω resistor to another pin (e.g., PB0) and make a pattern.
  4. Read a button: Use an external pull-up resistor and a button on PB3 to control the blink speed.
  5. Use interrupts: Replace delay() with a timer interrupt to blink the LED without blocking, allowing other tasks.

Try It Yourself on Velxio!

You can run and modify this exact sketch in your browser with Velxio — no hardware needed! The simulator provides a virtual ATtiny85 with an LED on PB1. Click the link below to open the live example, edit the code, and see the blink instantly.

🔗 Open ATtiny85 Blink on Velxio

Once you've mastered the blink, explore other ATtiny85 examples like RGB LED, Servo Control, or I2C Communication. Happy tinkering!

Arduino Button Control: How to Turn an LED On/Off with a Pushbutton
Learn to read a button press and control an LED using an Arduino Uno in Velxio's interactive simulator.