Sunday, November 30, 2014

Reducing Arduino’s Power Consumption Part 2

In Part two, of this three part series, we will look at how to use the Power Reduction Register (PRR) to reduce power consumption by turning off parts of Arduino that are not being used. This series is for anybody using Arduino for a battery powered project where maximizing battery life is critical.



*************************Arduino Code***********************************
/* This Arduino Sketch is part of a tutorial on the ForceTronics YouTube Channel and demonstrates how to use the 
Power Reduction Registers (PRR). It is free and open for anybody to use at their own risk.
*/

#include <avr/power.h>
     
 /* Power Reduction Register (PRR) functions from avr/power.h library. 
 For every disable function there is an enable function
  power_adc_disable() or power_adc_enable()
  power_spi_disable() or power_spi_enable()
  power_timer0_disable() or power_timer0_enable()
  power_timer1_disable() or power_timer1_enable()
  power_timer2_disable() or power_timer2_enable()
  power_twi_disable() or power_twi_enable()
  power_all_enable() or power_all_disable()
  
  Note that for max power efficiency you should also disable the rest of the module for ADC and SPI
   SPCR = 0; //disable SPI
   ADCSRA = 0;  // disable ADC
  */

void setup() {
  delay(6000); //Delay to see normal power level first
  ADCSRA = 0;  // disable ADC by setting ADCSRA register to 0
  power_adc_disable(); //disable the clock to the ADC module
  delay(4000); //delay to see just ADC off power level
  SPCR = 0; //disable SPI by setting SPCR register to 0
  power_spi_disable(); //disable the clock to the SPI module
  delay(4000); //delay to see just ADC and SPI off power level
  power_all_disable();
}

void loop() {
  // put your main code here, to run repeatedly:
}