Miniaturizing Arduino Projects

As already mentioned briefly in this post about my Arduino Starter Kit, most of the Arduino boards come with AVR controllers (a microcontroller of the Atmel family), e.g. an ATmega328P-PU. However, when there’s no need for all the inputs and outputs on your Arduino and you really want to miniaturize your project, you can use an Atmel tinyAVR microcontroller instead, such as an ATtiny45 (datasheet) or ATtiny85 (datasheet). These are small, very cheap microcontrollers that are convenient for running smaller programs. This way you can replace your ‘bulky’ Arduino Uno by this tiny package.
Among some of the differences, note the following:
ATmega328P | ATtiny45 | ATtiny85 | |
---|---|---|---|
Pins | 28/32 | 8 | 8 |
Digital channels (including PWM and ADC) | 23 (20 1) | 5 | 5 |
PWM channels | 6 | 2 | 2 |
ADC channels | 6 | 3 | 3 |
Flash 2 (kB) | 32 | 4 | 8 |
SRAM 3 (bytes) | 2048 | 256 | 512 |
EEPROM 4 (bytes) | 1024 | 256 | 512 |
For this article, you’ll need:
- an Arduino Uno
- an ATtiny45 or ATtiny85
- a 10 uF capacitor
- a breadboard
- some jumper wires
First you need to install support for ATtiny boards in your Arduino IDE. You only need to do this once:
- menu File » Preferences and enter the following URL where it says Additional Boards Manager URLs:
https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json - menu Tools » Board » Board Manager, scroll down the list to find the ATtiny entry and click the Install button
You need to temporarily turn your Arduino Uno into an in-system programmer (ISP) for your ATtiny chip. Before we look at the hardware, start by uploading the necessary code to your Arduino Uno:
- menu Tools » Board » Arduino Uno to set your board
- menu File » Examples » ArduinoISP to load the sketch
- compile & upload to your Arduino Uno
The physical pins (labelled on the inside of the ATtiny in the image below) and the pin numbers in the software (as shown next to the pins, outside of the ATtiny) are very different. I will use latter numbering, the pin numbers in the software, to avoid any further confusion. Use the dot in the corner of the ATtiny to orient it properly, it indicates where to begin counting the I/O pins: in case of the ATtiny, that’s the Reset Pin.
Connect the Arduino board to the ATtiny as shown in the diagram below:
ATtiny | Arduino | |
---|---|---|
VCC | VCC (+) | 5V |
SCK | Pin 2 | Pin 13 |
MISO | Pin 1 | Pin 12 |
MOSI | Pin 0 | Pin 11 |
GND | GND (-) | GND |
RESET | Reset | Pin 10 |
Also, connect a 10 µF capacitor between reset and ground on the Arduino Uno board as shown in the diagram. Make sure that the stripe on the capacitor that’s marked with a negative sign should go to ground.
Next, in the Arduino IDE Tools menu:
- menu Tools » Board » ATtiny
- menu Tools » Processor » ATtiny45/85 depending on the microcontroller you’re working with
- menu Tools » Clock » 8 MHz (internal)—make sure you didn’t set it to external!
- menu Tools » Programmer » Arduino as ISP
An ATtiny’s internal clock runs at 1 MHz by default. If you’d {cpp}delay(1000);{/cpp} when still running at 1 MHz, you’d notice a delay of 8 seconds instead of 1 second. That’s why you need to change this to 8 MHz by selecting Burn Bootloader from the Tools menu after setting the options above correctly. Again, make sure you have selected 8 MHz (internal). You only need to do this once for each ATtiny45/85.
That’s it! To test your setup, you can now upload the following Blink sketch with modified pin numbers to the ATtiny using your Arduino as an ISP to test it (menu Sketch » Upload using Programmer). If you would just Upload as usual, you’d be reprogramming the Arduino Uno again and that’s not what you want to do here.
void setup() { pinMode(0, OUTPUT); } void loop() { digitalWrite(0, HIGH); delay(1000); digitalWrite(0, LOW); delay(1000); }
Next, remove the yellow and green cables and hook up a 330 Ω resistor and an LED to ATtiny Pin 0 instead and watch it blink.
Note that the only remaining purpose of the Arduino here is to supply power, as a 5 V voltage source, to the ATtiny45/85.
Later, we’ll explore ways to remove the Arduino altogether and use batteries to make the project portable. Also, soldering the components on a PCB adds another level of miniaturization to the project.
If you find an ATtiny85 too limited for your project but you don’t want to use an Arduino Uno, then take a look at an Arduino Pro Mini or an Adafruit Trinket.
Notes:
- An Arduino Uno exposes 20 of the 23 digital I/O pins on the ATmega328P. ↩
- Flash: non-volatile memory for storing your program. ↩
- SRAM: volatile memory for storing your data during run-time including registers, stack, etc. ↩
- EEPROM: non-volatile memory which can be used for storing data and changeable during run-time, e.g. settings. ↩