Servo power down / current drain / watchdog timer attiny85

Well I've made a few changes (so I could understand it basically) and tested with my Attiny85 I happened to have lying around. :slight_smile:

#include <avr/sleep.h>
#include <avr/wdt.h>
#include "Servo8Bit.h"

Servo8Bit myServo;  //create a servo object.
int pinLed = 0;

void setup()
  {
  pinMode(pinLed,OUTPUT);
  }  // end of setup

void loop()
  {
  //reattach the servo that was previously detached
  myServo.attach(1,544,2200); //attach the servo to pin PB1 

  digitalWrite(pinLed,HIGH);  // let led blink
  for(int pos = 0; pos < 180; pos++)  // goes from 0 degrees to 180 degrees
    {                                   // in steps of 1 degree
    myServo.write(pos);             // tell servo to go to position in variable 'pos'
    delay(15);                      // waits 15ms for the servo to reach the position
    }

  for(int pos = 180; pos > 1; pos--)  // goes from 180 degrees to 0 degrees
    {
    myServo.write(pos);             // tell servo to go to position in variable 'pos'
    delay(15);                      // waits 15ms for the servo to reach the position
    }
  digitalWrite(pinLed,LOW);

  myServo.detach ();

  //save the value of the Timer Counter Control Register 1
  byte saved_TCCR1 = TCCR1;
  //turn off timer 1
  TCCR1 = 0; //turn off timer 1
 
  pinMode(pinLed,INPUT); // set all used port to intput to save power
 
  system_sleep();
 
  pinMode(pinLed,OUTPUT); // set all ports into state before sleep
  //Restore the TCCR1 register to re-enable the timer.
  TCCR1 = saved_TCCR1;
}  // end of loop

// set system into the sleep state 
// system wakes up when wtchdog is timed out
void system_sleep() 
  {
  // disable ADC
  byte saved_ADCSRA = ADCSRA;  
  ADCSRA = 0;

  // clear various "reset" flags
  MCUSR = 0;     
  // allow changes, disable reset
  WDTCR = _BV (WDCE) | _BV (WDE);
  // set interrupt mode and an interval 
  WDTCR = _BV (WDIE) | _BV (WDP3) | _BV (WDP0);    // set WDIE, and 8 seconds delay
  wdt_reset();  // pat the dog
  
  set_sleep_mode (SLEEP_MODE_PWR_DOWN);  

  sleep_enable();
  sleep_cpu ();  
  sleep_disable();

  ADCSRA = saved_ADCSRA; 
  }  // end of system_sleep

// Watchdog Interrupt Service / is executed when watchdog timed out
ISR(WDT_vect) 
  {
   wdt_disable();  // disable watchdog
  }   // end of WDT_vect

I didn't quite get what the flag was for the watchdog, so that went out the window. And a few other things I didn't get either.

I'm not quite sure about the servo output. I'm seeing about 25 pulses of about 1.54 mS high each followed by 18.76 mS low, per batch.

With the LED disconnected the circuit draws about 8.8 mA when active, and about 675 uA when sleeping. Is that roughly what you are expecting? With the LED on pin 5 it draws 16.5 mA (that would vary depending on the resistor on the LED).

(edit) See below for corrected figures.