Examples - HowTo - Decrease Battery Consumption

A simple class in wiring

This tutorial shows an easy possibility on how to save arduino's battery lifetime while using xBee as a transceiver for sleeping mode. If you want to collect sensor data in a certain interval you should try this tutorial. you energy consumption will decrease.

Just take a lookon our real life measurements with a 7.6V battery and Seeeduino/Arduino on 5V:

If Seeeduino board in SLEEP_MODE_PWR_DOWN
Seeeduino board 13mA
Seeeduino board + sleep xbee 33mA
Seeeduino board + extension board 23mA
Seeeduino board + extension board + awake xbee 74 mA
Seeeduino board + extension board + sleep xbee 25mA (both seeeduino and xbee sleep and wake up in loop)


If Seeeduino borad not sleep
Seeeduino board + extension board + awake xbee 102mA (original version)
Seeeduino board + awake xbee 64mA
Seeeduino board + sleep xbee 45mAv

Hardware setup


Software setup


/*******************************************************************************************
* sleep Arduino + XBee example to reduce battery consumption
* 28.04.2010
* Author:       Hua Hao            /  CAAD - ITA - ETH Zürich  /  hhua@student.ethz.ch
* Coordination: Christoph Wartmann /  http://www.embedded.arch.ethz.ch
* based on the codes of Martin Nawrath: http://interface.khm.de/index.php/lab/experiments/sleep_watchdog_battery
*
* the system works as follows:
1.	Arduino wakes up
2.	Arduino wakes XBee up
3.	Arduino collect data, send data via XBee to coordinator
4.	Arduino makes XBee sleep
5.	Arduino sleeps
6.	go to step 1
*******************************************************************************************/

#include <avr/sleep.h>
#include <avr/wdt.h>
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
int nint;
int xbeePin=8;//D8
boolean f_wdt=1;

void setup(){
        Serial.begin(9600);
        pinMode(xbeePin,OUTPUT); //set D8 pin for OUTPUT
        cbi( SMCR,SE );      // sleep enable, power down mode
        cbi( SMCR,SM0 );     // power down mode
        sbi( SMCR,SM1 );     // power down mode
        cbi( SMCR,SM2 );     // power down mode
        setup_watchdog(8);   //every 4 seconds
}

void loop() {
        if (f_wdt==1) {  // wait for timed out watchdog / flag is set when a watchdog timeout occurs
                f_wdt=0;       // reset flag
                digitalWrite(xbeePin,LOW);  //awake xbee
                nint++;
                delay(10);
                sendData();
                delay(10);               // wait until the last serial character is send
                digitalWrite(xbeePin,HIGH);  //sleep xbee,5V on D8 pin of Arduino,and provide 3.3V on pin9 of the remote XBee(use resistor).
                //PIN HIBERNATE sleep mode is used(set SM=1 for remote XBee in X-CTU)
                pinMode(xbeePin,INPUT); // set all used port to intput to save power
                system_sleep();
                pinMode(xbeePin,OUTPUT); // set all ports into state before sleep
        }
}
void sendData(){
        //set your own format of data here
        //the data will display on the serial monitor of your computer connecting a coordinator XBee (receiveing data from remote XBee)
        Serial.print(analogRead(1));
        Serial.print(":");
        Serial.print(analogRead(2));
        Serial.print(":");
        Serial.println(analogRead(3));
}

void system_sleep() {// system wakes up when wtchdog is timed out
        cbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter OFF
        set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
        sleep_enable();
        sleep_mode();                        // System sleeps here
        sleep_disable();                     // System continues execution here when watchdog timed out
        sbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter ON
}
void setup_watchdog(int ii) {
        // 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms
        // 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
        byte bb;
        int ww;
        if (ii > 9 ) ii=9;
        bb=ii & 7;
        if (ii > 7) bb|= (1<<5);
        bb|= (1<<WDCE);
        ww=bb;
        MCUSR &= ~(1<<WDRF);
        WDTCSR |= (1<<WDCE) | (1<<WDE); // start timed sequence
        WDTCSR = bb;// set new watchdog timeout value
        WDTCSR |= _BV(WDIE);
}
ISR(WDT_vect) {// Watchdog Interrupt Service / is executed when  watchdog timed out
        f_wdt=1;  // set global flag
}

This website has been archived and is no longer maintained.