Arduino Project on ATtiny85

Last updated: 18 May 2022

The ATtiny is a family of microcontrollers that have been around since 1999 (first produced by Atmel Corporation, now owned by Microchip Technology Inc). The ATtiny85 DIPDual inline package: chip with two rows of parallel pins - perfect for setting up on a breadboard :) chip was released in 2005. It's very popular because of its low price, reliability and consumption-to-speed performance.

ATtiny85 (courtesy of Microchip Technology Inc)
ATtiny85 (courtesy of Microchip Technology Inc)

The drawbacks are that the ATtiny has less memory, less pins, less architectural possibilities and is (using the default configuration) slower than the Arduino or ATMega328. Also there is no serial communication so you'll need to code and debug your Arduino project on an Arduino and, when you're sure it's working, tweak the pin-numbering and upload it to the ATtiny.

The following pin-out diagram shows how you've only got 5 pins for connecting other components. You might be tempted to say "Hold on - I can clearly see eight pins", and you'd be right; but we need to bear in mind that one is needed for the power supply (VCC), one to go to earth (GND) and one is the reset pin (reset). That's three pins that we can't use for digital input/output. Eight minus three leaves us five pins to play with.

ATtiny 45 / 85 pin-out
ATtiny 45 / 85 pin-out

Having said that, for simple projects the ATtiny is more than adequate; and, as we'll see, it's quite easy to port an Arduino project to the ATtiny.

A fun (and educational) way to do this is by using the Arduino as a programmer. In other words we use the Arduino as a bridge from our PC to the ATtiny to upload our code; then we run the code on the ATtiny completely independently from the Arduino.

Our flame effect project is a perfect example. As we only need four digital output pins, we even have one pin left over :)

Stuff you'll need

  • Arduino board (any model) + USB cable
  • ATtiny85 microcontroller chip
  • LEDs (red X 2, yellow X 2)
  • resistors (330Ω x 4)
  • jumper wires (male-to-male X 6)
  • solderless breadboard
  • 10μF capacitor (doesn't need to be exact)
  • AA (or AAA) batteries X 3
  • battery holder for your 3 batteries (series)

Steps

Connect the Arduino to the ATtiny for programming

With the Arduino connected to your PC via the USB cable, mount the ATtiny on the breadboard and connect both devices pins in the following way:

Arduino UNO pin ATtiny pinThese are the names shown in the pin-out above. The physical pin number is shown in parentheses.
+5v VCC+ (8)
GND GND (4)
10 RESET (1)
11 pin 0 (5)
12 pin 1 (6)
13 pin 2 (7)

Your set-up should look like this:

Arduino UNO connected as programmer to ATtiny85
Arduino UNO connected as programmer to ATtiny85
Arduino UNO connected as programmer to ATtiny85 diagram
Arduino UNO connected as programmer to ATtiny85 diagram
Arduino UNO connected as programmer to ATtiny85 schematic
Arduino UNO connected as programmer to ATtiny85 schematic

Configure the Arduino as a programmer

  1. Open your Arduino IDE.
  2. Check in the Tools > Boards menu that ATtiny25/45/85 is present.
  3. If not, do just do the following to add it:
    1. Go to file > preferences > additional boards manager URLs and add: https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json to the list.
    2. Tools > board > board manager > select attiny board by amellis (which should now appear in the list) > install.
  4. Open the ISP sketch: File > Examples > select ArduinoISP.
  5. UploadSketch > Upload or Ctrl + U it to the Arduino board.
  6. Connect the RESET pin of the Arduino to GND through the 10μF capacitor This is to prevent avrdude (the programme running on your PC) from resetting the Arduino. Not all Arduino boards actually need it but it's probably best to include it. You're free to research and experiment of course :) (it doesn't need to be exactly 10μF; I actually used a 2.2μF capacitor):
    Arduino UNO connected as programmer to ATtiny85 diagram
    Arduino UNO connected as programmer to ATtiny85 with cap
    Capacitor for Arduino as programmer
    Capacitor for Arduino as programmer
  7. Burn the ATtiny bootloader to the ATtiny chip:
    1. Tools > Programmer > select Arduino as ISP (not arduinoISP!!!!!).
    2. Hit Tools > Burn bootloader.
  8. Upload flames sketch to the ATtiny
    1. Open the flames sketch.
    2. First we need to change the pin-numbering of our original Arduino because the ATtiny's pin-out is completely different to the Arduino's. Change the code as follows. The new pin numbers are highlighted:
      long r;
      
      void setup(){
        pinMode(0, OUTPUT);
        pinMode(1, OUTPUT);
        pinMode(2, OUTPUT);
        pinMode(3, OUTPUT);
      }
      
      void flicker(int x){
        r = random(100L);
        digitalWrite(x, r < 90);
      }
      
      void loop(){
        flicker(0);
        flicker(1);
        flicker(2);
        flicker(3);
        delay(100);
      }
  9. Tools > Board > ATtiny 25/45/85
  10. Tools > Processor > ATtiny85
  11. Tools > Clock > Internal 8 MHz
  12. Hit UploadSketch > Upload or Ctrl + U.

Wire the ATtiny for the flames project

This is exactly the same set-up as the flame effect project except we're using ATtiny pins 0, 1, 2 and 3 instead of Arduino pins 2, 3, 4 and 5; and instead of using power from the USB cable, we're using batteries (the diagram shows 4 AAA batteries because I couldn't find a fritzing part for 3 AA batteries :( ). Don't forget that if you haven't got batteries and holder at hand, you can always power the ATtiny chip from your Arduino's VCC and GND pins; but it won't look so impressive (bearing in mind it's supposed to be a stand-alone device ;) ).

ATtiny85 flame effect diagram (4 LEDs)
ATtiny85 flame effect diagram (4 LEDs)

Check out the results!

Here's the same thing with 2 LEDs connected to a mini-breadboard with no Arduino.

ATtiny85 running off batteries
ATtiny85 running off batteries
ATtiny85 running off batteries video

© 2022