Philip Tabone
Published © GPL3+

Sleep AT-tiny

Very low power sleep mode of the ATtiny helps make projects on battery last for days (and possibly months).

AdvancedFull instructions provided2 hours270
Sleep AT-tiny

Things used in this project

Hardware components

Microchip ATtiny85
Resistor 22.1k ohm
Resistor 22.1k ohm
Resistor 4.75k ohm
Resistor 4.75k ohm
Breadboard (generic)
Breadboard (generic)
Resistor 2.21k ohm
Resistor 2.21k ohm
LED (generic)
LED (generic)


Read more


AT-tiny timer wake

Design for AT-tiny with sleep timer. Push button puts it back to sleep.
Replace LED with your own awesome project (Via transistor or mosfet)

AT-tiny Interrupt wake

Push button to wake up AT-tiny, Go back to sleep after LED 1 sec Blink. Replace LED with your own awesome project (via Transistor or Mosfet)


Sleep with timer wake

Keeps AT-tiny asleep and wakes up on timer interval. Then goes back to sleep.
#include <avr/sleep.h>

#include <avr/wdt.h>

#ifndef cbi

#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))


#ifndef sbi

#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))


int pinLed = 0;
int trig = 2;
int heart = 1;
volatile boolean f_wdt = 1;
int counter = 0;

void setup(){




  setup_watchdog(8); // approximately 4 seconds sleep


void loop(){

  if (f_wdt==1) {  // wait for timed out watchdog / flag is set when a watchdog timeout occurs

    f_wdt=0;       // reset flag

  if (counter > 192){ //timer to reset approx 15 min


    delay(500); // Wait for trigger high until set back to sleep



    counter = 0;


    // Show heartbeat uncomment to show blink



    //digitalWrite(heart,LOW );

    pinMode(pinLed,INPUT); // set all used port to intput to save power


    pinMode(pinLed,OUTPUT); // set all ports into state before sleep



// set system into the sleep state 

// system wakes up when wtchdog is timed out

void system_sleep() {

  cbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter OFF

  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here


  sleep_mode();                        // System sleeps here

  sleep_disable();                     // System continues execution here when watchdog timed out 

  sbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter ON


// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms

// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec

void setup_watchdog(int ii) {

  byte bb;

  int ww;

  if (ii > 9 ) ii=9;

  bb=ii & 7;

  if (ii > 7) bb|= (1<<5);

  bb|= (1<<WDCE);


  MCUSR &= ~(1<<WDRF);

  // start timed sequence

  WDTCR |= (1<<WDCE) | (1<<WDE);

  // set new watchdog timeout value

  WDTCR = bb;



// Watchdog Interrupt Service / is executed when watchdog timed out

ISR(WDT_vect) {


  f_wdt=1;  // set global flag


Sleep with interrupt Wake

Put AT-tiny to sleep and wake up on interrupt.
//ATtiny low power using interrupt to wake

#include <avr/sleep.h>

#include <avr/interrupt.h>

const int switchPin = 3;

const int statusLED = 2;

void setup() {

    pinMode(switchPin, INPUT);

    pinMode(statusLED, OUTPUT);

    // Flash quick sequence so we know setup has started

    for (int k = 0; k < 5; k++) {

        if (k % 2 == 0) {

            digitalWrite(statusLED, HIGH);


        else {

            digitalWrite(statusLED, LOW);



        } // for

    } // setup

void sleep() {

    GIMSK |= _BV(PCIE);                     // Enable Pin Change Interrupts

    PCMSK |= _BV(PCINT3);                   // Use PB3 as interrupt pin

    ADCSRA &= ~_BV(ADEN);                   // ADC off

    set_sleep_mode(SLEEP_MODE_PWR_DOWN);    // replaces above statement

    sleep_enable();                         // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)

    sei();                                  // Enable interrupts

    sleep_cpu();                            // sleep

    cli();                                  // Disable interrupts

    PCMSK &= ~_BV(PCINT3);                  // Turn off PB3 as interrupt pin

    sleep_disable();                        // Clear SE bit

    ADCSRA |= _BV(ADEN);                    // ADC on

    sei();                                  // Enable interrupts

    } // sleep

ISR(PCINT0_vect) {

    // This is called when the interrupt occurs, but I don't need to do anything in it


void loop() {


    digitalWrite(statusLED, HIGH);


    digitalWrite(statusLED, LOW);



Philip Tabone

Philip Tabone

3 projects • 7 followers
If I need, it I'll build it.