6 comments on “Ultra Low Power Led Flasher (with ATtiny)

  1. Here is an interesting observation. I created your 3V circuit and used the same code above on my attiny85 running at 1MHZ. I noticed:

    a. When LED is not flashing, the consumption is 4.2uA.

    b. When the LED is flashing, the consumption seems to cycle from 16uA and increase by 10uA for every flash. When it reaches 130uA it flips to the opposite and starts to decrease by 10uA until it reached 16uA and starts all over again.

  2. I edited it for cheaper ATtiny13 (I am using ATtiny13A-SU internal R/C osc 4.8 MHz divided by 8 – 600 kHz = low_fuses=0x69 high_fuses=0xff ). Code is more optimised and also there is added on/off switch. ATtiny13 in this configuration = 600kHz and on 3V battery consuming cca 0.1uA if it is in OFF state and 4.4uA between LED flashes = power down, but WDT is running. After battery is connected, and after reset, power is ON. So you do not need to use/connect switch.

    Currently I am using Arduino IDE 1.6.0 with core13 for compiling and uploading this sketch.
    http://sourceforge.net/projects/ard-core13/

    /*

    ATTINY13 Ultra Low Power Led Flasher with ON/OFF switch

    ATTINY13
    +-\/-+
    ADC0 PB5 1| |8 Vcc
    ADC3 PB3 2| |7 PB2 ADC1
    PCINT4 ADC2 PB4 3| |6 PB1 PWM1 INT0 tactile switch
    GND 4| |5 PB0 PWM0 LED
    +—-+
    WDT = Watchdog Timer
    */

    #include // sleep code

    //define function cbi – Clear Bit in I/O Register
    //define function sbi – Set Bit in I/O Register
    #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~(1<<bit))
    #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= 1< 7) // for 8 and 9
    {
    cbi(t,3); // set 3rd bit to 0
    sbi(t,5); // set 5th bit to 1
    }
    t |= 1<<6; // WDTIE = 1 (WDT int. enable)
    WDTCR = t; // write WDT prescale setting bits
    }

    /////////////////////////////////////////////////////////////////////
    void loop(){ // one 30ms flash, sleep
    sbi(PORTB,led); // turn LED ON
    delay(30); // for 30ms
    cbi(PORTB,led); // and OFF
    sleep_cpu(); // Power down
    // MCU is waked up by WDT interrupt or INT0
    }

    /////////////////////////////////////////////////////////////////////
    ISR(WDT_vect) // WDT interrupt service routine
    {
    // empty, but it must be here 🙂
    // it will not work without it
    }

    /////////////////////////////////////////////////////////////////////
    ISR(INT0_vect) // INT0 interrupt service routine
    {
    delay(1000); // wait 1 sec
    WDTCR ^= (1<<WDTIE); // toggle WDT interrupt
    }

    • 1st post is messed

      /*
       
      ATTINY13 Ultra Low Power Led Flasher with ON/OFF switch
      
                      ATTINY13
                       +-\/-+
             ADC0 PB5 1|    |8 Vcc
             ADC3 PB3 2|    |7 PB2 ADC1
      PCINT4 ADC2 PB4 3|    |6 PB1 PWM1 INT0    tactile switch
                  GND 4|    |5 PB0 PWM0         LED
                       +----+
      WDT = Watchdog Timer
      */
       
      #include <avr/sleep.h>// sleep code
      
      //define function cbi - Clear Bit in I/O Register
      //define function sbi - Set Bit in I/O Register
      #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~(1<<bit))
      #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= 1<<bit)
       
      #define led 0               // LED on PB0 - pin 5
      // tactile switch must be on PB1/ pin 6 because it is INT0 pin
      
      ///////////////////////////////////////////////////////////////////// 
      void setup(){
      MCUCR = 48;                 // SE and SM1 in MCUCR = 1
      cbi(ADCSRA,ADEN);           // Switch Analog to Digital converter OFF
      sbi(ACSR,ACD);              // disable the analog comparator
      sbi(PORTB,PORTB1);          // turn on pull-up on tact switch pin
      sbi(DDRB,led);              // LED pin = output
      sbi(GIMSK,INT0);            // INT0 is now activated
      setup_watchdog(7);          // WDT prescale select 0-9
      // 0=16ms, 1=32ms, 2=64ms, 3=125ms, 4=250ms, 5=500ms
      // 6=1 sec, 7=2 sec, 8=4 sec, 9=8sec
      }
      
      ///////////////////////////////////////////////////////////////////// 
      void setup_watchdog(byte t) // WDTCR setup function
      {
      // WDP3 is not 3rd but 5th bit in WDTCR register
      // for value 8 and 9 3rd bit must be 0 and 5th 1
        if (t > 7)                // for 8 and 9
          {                                       
          cbi(t,3);               // set 3rd bit to 0
          sbi(t,5);               // set 5th bit to 1
          }
      t |= 1<<6;                  // WDTIE = 1 (WDT int. enable)
      WDTCR = t;                  // write WDT prescale setting bits
      } 
      
      ///////////////////////////////////////////////////////////////////// 
      void loop(){                // one 30ms flash, sleep
      sbi(PORTB,led);             // turn LED ON
      delay(30);                  // for 30ms
      cbi(PORTB,led);             // and OFF
      sleep_cpu();                // Power down
      // MCU is waked up by WDT interrupt or INT0
      }
      
      /////////////////////////////////////////////////////////////////////
      ISR(WDT_vect)                // WDT interrupt service routine 
      {
                                   // empty, but it must be here 🙂
                                   // it will not work without it
      }
      
      /////////////////////////////////////////////////////////////////////
      ISR(INT0_vect)              // INT0 interrupt service routine 
      {
      delay(1000);                // wait 1 sec
      WDTCR ^= (1<<WDTIE);        // toggle WDT interrupt
      }
      
    • jordiwrGeorge:
      This is the command:
      “setup_watchdog(7);” and this is just comment: // WDT prescale select 0-9

      This is also just comment:
      // 0=16ms, 1=32ms, 2=64ms, 3=125ms, 4=250ms, 5=500ms
      // 6=1 sec, 7=2 sec, 8=4 sec, 9=8sec
      So you can use values 0….9 in command “setup_watchdog(7);”
      And each value means time from 16ms to 8 seconds, you can chose 2 or 4 seconds.

      For 4 seconds you need to change 7 to 8 in command:
      “setup_watchdog(7);”

  3. Hello;
    I am new in this field i need a simple single LED flasher circuit with code that will accept two types of signal one is positive +5v and other is -5v when +5 signal input to atiny it starts flashing LED at rate of 2sec and when -5v signal input the LED becomes solid.Please reply.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s