Julian Straub

creations and thoughts

Micro watt ATtiny LED blinker

Posted at — May 4, 2020

Since starting the light harvesting projects, I have been possible to run a microcontroller from harvested energy alone. Looking at the Atmel microcontroller lineup the best suited controllers seemed to be the ATtiny family ones. According to the datasheet they can go as low as \(0.1\mu A\) in power down mode.

I built a very simple setup to start: a ATtiny85 with a LED connected to its Port B0 pin. The ATtiny is powered by a \(7.5F\) super capacitor that is charged to up to \(5.6V\) from a \(6V\) solar panel through a Schottky diode.

The code for the micro power blinker turns off all periphery (like ADC and timers) that may consume energy.

void initPowerSave() {
  DDRB = (1<<PB0); // only leave PB0 on for LED, rest is input
  PORTB = 0;
  ADCSRA &= ~(1<<ADEN); // disable the ADC
  // disable all other modules
  PRR = (1<<PRADC) | (1<<PRUSI) | (1<<PRTIM0) | (1<<PRTIM1); 
}

The watchdog timer interrupt is used to periodically wake up the ATtiny from power down (which consumes about \(10\mu A\) at \(5V\) ) to execute some code. In this case the code turns on the LED for 1ms before going back to sleep. It is important to execute power down at the end of the watchdog timer interrupt because otherwise the microcontroller just continues normal execution in the main thread!

void initWatchdog() {
  cli();
  MCUSR = 0x00;
  WDTCR |= (1<<WDCE) | (1<<WDE); // needed in safety level 1
  // enable watchdog AND watchdog timer interrupt 
  // and set prescaler to 1Hz frequency at 5V
  WDTCR = (1<<WDIE) | (1<<WDP2) | (1<<WDP1); 
  sei();
}
void sleep() {
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  cli();
  sleep_enable();
  sleep_bod_disable();
  sei();
  sleep_cpu();
}
// watchdog interrupt is the only time the ATtiny is not in power down.
ISR(WDT_vect) {
  PORTB |= (1<<PB0);
  _delay_ms(1);
  PORTB &= ~(1<<PB0);
  sleep(); // back to sleep
}
int main(void) {
  initPowerSave();
  initWatchdog();
  sleep(); // start sleeping; 
	// never reached since the interrupt puts the ATtiny back to sleep.
  sleep_disable(); 
}

The LED resistor is selected such that a current of \(20mA\) can generate a bright flash. We turn on the LED for 1ms every 1s. Hence, the average power consumption is roughly

$$ P = 5V \left(10\mu A + \tfrac{1}{1000} 20mA\right) = 5V 30 \mu A = 180\mu W $$

Since we can use the energy in the capacitor down to about 1.8V (which is where the ATtiny stops working, and a red LED would stop working as well), we have an energy of

$$ E_C = \tfrac{1}{2} C (U_0^2 - (1.8V)^2) $$

available. For the \(7.5F\) capacitor charged to \(U_0 = 5.6V\) initially, this makes \(E_C = 105 J\) . Hence, theoretically, a fully charged supercapacitor of that size can drive the micro power blinker for

$$ t = \tfrac{E_C}{P} \approx 162 h $$

which is about \(6.7\) days. If the solar cell can replenish the energy during the day, the system should be able to run indefinitely. Assuming 8 out of 24h can be used for light harvesting, then the solar cell needs to provide only \(3\times\) the power consumed by the circuit. In this case \(0.54 mW\) . Judging from the solar cell characterizations that seems quite possible even just at ambient indoor lighting during the day.