ATtiny85 – Wield the power of the mighty ATtiny through Arduino in 8 simple steps

In this post I will show how to connect and program the ATtiny85 using the Arduino Uno and Arduino IDE. The ATtiny85 is small but packs a serious punch. If the project-scope allows, it is a good alternative to its bigger sibling ATmega328p. Obviously it does not have as many pins and lacks the 16 bit timer but in many cases it can be more than enough.

The way I have used the ATtiny85 is for parallel computing to alleviate the ATmega328p from certain tasks. I thought about using it for the blinkers-routine in my car project but I never got around to it.


  • 1x Arduino Uno
  • 1x ATtiny85 (8-pin DIP)
  • 1x Capacitor 10 μF
  • 1x Breadboard
  • Jumper wires

The mighty ATtiny85 from Atmel

Some features

– 8-bit Timer/Counter with Prescaler and Two PWM Channels
– 8-bit High Speed Timer/Counter with Separate Prescaler
– 2 High Frequency PWM Outputs with Separate Output Compare Registers
– Programmable Dead Time Generator
– USI – Universal Serial Interface with Start Condition Detector
– 10-bit ADC
– 4 Single Ended Channels
– 2 Differential ADC Channel Pairs with Programmable Gain (1x, 20x)
– Temperature Measurement
– Programmable Watchdog Timer with Separate On-chip Oscillator
– On-chip Analog Comparator

Special Microcontroller Features
– debugWIRE On-chip Debug System
– In-System Programmable via SPI Port
– External and Internal Interrupt Sources
– Low Power Idle, ADC Noise Reduction, and Power-down Modes
– Enhanced Power-on Reset Circuit
– Programmable Brown-out Detection Circuit
– Internal Calibrated Oscillator

Operating Voltage
– 2.7 – 5.5V

Speed Grade
– 0 – 10 MHz @ 2.7 – 5.5V, 0 – 20 MHz @ 4.5 – 5.5V

Industrial Temperature Range

Low Power Consumption
– Active Mode: 1 MHz, 1.8V: 300 µA
– Power-down Mode: 0.1 µA at 1.8V

Step 1: Settings for the Arduino


In “Tools”: Board “Arduino/Genuino Uno”, Programmer “AVR ISP”

Step 2: Upload program “Arduino as ISP” into Arduino.


Go to “Files” – “Examples” – “11.ArduinoISP” – “Arduino ISP” Load in the example and press upload.

Step 3: Hook up the ATtiny85


ATtiny pins


Connect the Arduino & ATtiny85 using breadboard. Insure yourself that the capacitor is correctly connected (it’s polarized).

Step 4: Settings for the ATtiny85

Go to File – Preferences, In “Additional Boards Manager URLs” add

and press “OK”

Go to Tools – Board – Boards manager and search for “attiny” and a library by David A. Mellis should appear. Install it.

Configure the settings in “Tools” according to the figure below.  Note the “Arduino as ISP” setting. By default the ATtiny85 runs at 1MHz.

Optional: In order to make it run at 8MHz the fuses must be changed, as such this only needs to be done once since the fuse-bits records are permanent. Make sure that the clock is set to “internal 8MHz” and chose “Burn Bootloader”. 


Settings needed before uploading sketches to the ATtiny85. If wanted, change the CPU frequency to 8MHz through the “Burn Bootloader” but make sure that the “internal 8MHz” clock is chosen.

Step 5: “Hello World” from ATtiny85

Write the following sketch in the Arduino IDE and upload it.


Simple “Hello World” sketch in the ATtiny

Step 6: Disconnect ATtiny

Disconnect the jumper wires and remove the capacitor from the Arduino and upload the “Bare Minimum” sketch into the Arduino (the ATmega328p not the ATtiny). The explanation as to “why” this is done comes in the next step.


Step 7: Reconnect ATtiny

Reconnect the ATtiny again according to the figure below. Remember, when it is reconnected it will run the CPU at 8MHz as instructed in step #4 and with the code written in step #5, in order to “listen” the Arduino will keep quiet since the BareMinimum sketch from step #6 does not interfere with the ATtiny.


Power up the ATtiny, data transmission through PB4 connected to Arduino pin1 in order to read serial monitor

Step 8: Open serial monitor

Brace yourselves.


The serial monitor displays the data transmitted from the ATtiny

The End

This concludes the principal steps for uploading scripts to the ATtiny85. A perhaps equally exciting script is this LED-fading script that I wrote in C-code. In this script the PWM, external interrupt INT0 connected to a button and the serial monitor are used.

/*Fade LEDs in main, blink if button pressed
  PB0 - Output PWM (LED VCC)
  PB2 - External Interrupt INT0 connected to Button
  PB4 - TX output to serial comm

#include <avr/io.h>
#define F_CPU 8000000UL
#include <util/delay.h>
#include <avr/interrupt.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3,4);  //rx, tx 

//Interrupt Service Routine for INT0
  unsigned char i, temp;
  _delay_ms(150); // Software debouncing control
  /* This for loop blink LEDs on Dataport 5 times*/
  for(i = 0; i<5; i++)
    _delay_ms(500); // Wait 5 seconds
    _delay_ms(500); // Wait 5 seconds

int main(void){
  unsigned char i=0;
  DDRB = (1<<PB0);    //Set our pwm pin as an output
  //Interrupt through button
  DDRB &= ~(1<<PB2);          // Set PB2 as input (Using for interrupt INT0)
  PORTB = (1<<PB2);           // Enable PB2 pull-up resistor, pushed button = 0
  MCUCR |= ((1<<ISC00)|(1<<ISC01));   //trigga på rising edge
  GIMSK |= (1<<INT0);         // local enable int0
  sei();                //Enable Global Interrupt

  DDRB |= (1<<PB4);
  //Timer configuration
  TCCR0A = ((1<<COM0A1)|(1<<WGM01)|(1<<WGM00));    //Enable pwm mode in pin PD6 and set the WGM bits to Fast pwm mode
  TCCR0B = ((1<<CS01)|(1<<CS00));                  //Set prescaler to 32
    //Fade up
    for(i=0; i<255;i++){
      OCR0A = i;        //Set new duty cycle value
      _delay_ms(1);    //delay a litle bit
    //Fade down
    for(i=255; i>0;i--){
      OCR0A = i;        //Set new duty cycle value
      _delay_ms(1);    //delay a litle bit
return 0;