Programming Within 512 Bytes of RAM
The ATtiny85's 512 bytes of SRAM sounds impossibly restrictive. In practice, it enforces disciplined programming that professionals apply by instinct: store constants in flash, not SRAM. In C/C++, string literals like const char msg[] = "Hello" are copied to SRAM by default. Use PROGMEM and pgm_read_byte() to read strings directly from flash without RAM cost.
Stack depth matters critically. Each function call consumes stack space: 2 bytes for the return address, plus any local variables. A 4-byte float, 16-byte char array, and 6 levels of function nesting can consume 100+ bytes of your 512. Structure ATtiny85 firmware as flat state machines with minimal function call depth.
avr-size --format=avr --mcu=attiny85 your_program.elf to see exact SRAM usage breakdown: BSS (globals), Data (initialized globals), and estimated Stack. Never let Stack + BSS + Data exceed 450 bytes ā leave 62 bytes headroom for ISR stack frames.Power Engineering: Coin-Cell Battery Life Calculations
A CR2032 coin cell holds approximately 220 mAh at 3V. An ATtiny85 running at 1 MHz from the internal RC oscillator draws about 0.3 mA active and 0.1 µA in Power-Down sleep with watchdog timer disabled (4 µA with WDT enabled at 8-second intervals).
For a sensor that wakes every 8 seconds, takes a reading (5 ms active), and sleeps:
Battery Life Calculation:
Active: 5ms Ć 0.3mA = 0.0015 mAh per cycle
Sleep: 7.995s à 4µA = 0.0000089 mAh per cycle
Total per cycle ā 0.00151 mAh
Cycles per day: 10,800 (every 8 sec)
Battery life: 220mAh Ć· 16.3mAh/day ā 13.5 days
With WDT disabled and GPIO-triggered wakeup: ~1,200+ days
The Production Migration Path: Arduino ā ATtiny85
The classic embedded development workflow: prototype on Arduino Uno for rapid iteration, then migrate to a bare ATtiny85 for the final product. This eliminates: USB-serial bridge chip (~$0.30), AMS1117 5V regulator (~$0.10), 16 MHz crystal + caps (~$0.10), 28-pin package overhead, and the Uno's entire PCB footprint.
Prototype on Arduino
Full debugging capability, Serial.print(), logic analyzer, oscilloscope. Pin 0ā5 mapping to ATtiny85's PB0āPB5 is direct.
Port to ATtiny85 Core
Add ATtiny85 board to Arduino IDE, recompile. Fix any Serial.print() calls (remove or use SoftwareSerial on PB3). Test on breadboard.
Program via ISP
Use Arduino Uno as ISP programmer. Upload ArduinoISP sketch, connect 6 wires to ATtiny85. Set fuses for clock source and BOD level.
Design PCB
ATtiny85 in SOIC-8 footprint. Add decoupling caps (100nF + 10µF), RESET pull-up (10kΩ), ISP programming header (6-pin). Total BOM ~$0.80.
Fuse Bits: The Engineering Detail That Bricks Chips
ATtiny85 fuse bits configure the chip at a hardware level ā clock source, brown-out detection, RESET pin behavior, and programming mode. They are written once per programming session and persist until deliberately changed.
ā ļø RSTDISBL fuse
Setting this disables the RESET pin and converts it to GPIO. The chip can no longer be reprogrammed via standard ISP. Recovery requires a 12V high-voltage programmer. Never set this unless you are programming the final chip for sealed production.
ā ļø CKDIV8 fuse
Set by default from factory ā divides internal 8 MHz oscillator by 8, resulting in 1 MHz operation. If your code assumes 8 MHz, timing, delay(), and UART baud rates will all be 8Ć wrong. Always check this fuse when a new chip behaves strangely.
ā BODLEVEL fuse
Sets the brown-out detection voltage. For 3.3V operation, set BOD to 2.7V. For 5V, set 4.3V. BOD adds ~15 µA quiescent current but prevents data corruption in EEPROM when voltage dips during sleep transitions.
Decision Guide
ā Choose ATtiny85 when:
- Coin-cell / ultra-low-power battery sensor
- Simple state machine: read sensor, output signal
- Space-constrained PCB (SOIC-8 = 5 Ć 4 mm)
- High-volume production cost matters
- Logic: under 4 KB code, under 300 bytes data
- No UART debugging needed in production
ā Choose ATmega328P when:
- More than 5 GPIO pins needed
- Hardware UART for debug or communication
- 16-bit Timer1 needed (servo, encoder)
- Multiple independent I2C devices
- Code size > 8 KB flash
- Data buffers or lookup tables > 400 bytes
Frequently Asked Questions
How do I debug ATtiny85 code without Serial?
Without hardware UART, debugging options are: (1) Toggle a GPIO and measure with a logic analyzer or oscilloscope. (2) Use TinyDebugSerial (bit-banged UART) on PB3 or PB4 at 9600 baud ā readable with any USB-serial adapter. (3) Flash an LED at different rates to indicate state. (4) Use the DebugWire interface with a debugger like Atmel-ICE for full source-level debugging (requires disabling RESET pin as GPIO).
Can ATtiny85 replace Arduino Uno in a finished product?
Absolutely ā and this is actually the recommended production path. Prototype on Arduino Uno, then migrate the logic to ATtiny85 (or ATmega328P bare chip without the Uno board). The ATtiny85 eliminates the USB-serial chip, voltage regulator, and other Uno overhead that you don't need in production hardware. Total BOM cost drops from ~$5 (clone Uno) to ~$0.60 (ATtiny85 + crystal + caps).
What is the ATtiny85 USI and how does it compare to hardware I2C/SPI?
USI (Universal Serial Interface) is a flexible serial peripheral that can be configured as SPI, I2C (TWI), or a general shift register. Unlike ATmega328P's hardware TWI which handles addressing and ACK/NACK automatically with interrupts, USI requires more software involvement for I2C ā you need to manually handle START/STOP conditions and check ACK bits. Libraries like TinyWire abstract this, but clock speeds above 100 kHz are difficult to achieve reliably.
What are ATtiny85 fuse bits and why are they important?
Fuse bits are one-time-programmable configuration bytes in the ATtiny85 that control clock source, brown-out detection threshold, EEPROM preservation during chip erase, RESET pin behavior, and bootloader section size. Critically: setting RSTDISBL fuse disables the RESET pin (turning it into a GPIO) ā this permanently prevents reprogramming via ISP unless you use a 12V programming setup. Never set this fuse without understanding the recovery procedure.
Verdict
The ATtiny85 is not a lesser Arduino ā it is a disciplined engineering choice. When your application genuinely fits within 8 KB of flash and 512 bytes of SRAM, using a 28-pin ATmega328P is engineering waste. Production designs should use the smallest MCU that meets requirements ā smaller PCB, lower BOM cost, lower power, higher reliability (fewer components). Use Arduino for development; use bare AVRs for production. Learn the AVR low-power sleep modes in depth with our guide on Arduino Uno advanced features, or see how these AVRs compare to 32-bit alternatives in STM32 vs Arduino Uno.