A helpful blog designed to get beginners up and running with Arduino, Zigbee and general embedded development.

Sunday, 25 April 2010

Sleeping Arduino - Part 1

OverviewIn this series of blogs I will be describing how to put an Arduino Diecimila into sleep mode, thus reducing the power consumption of the device, and detail several mechanisms for waking the Arduino. This can be quite useful (even necessary) when you are powering your Arduino via a battery and/or solar panel.

Four mechanisms for waking the Arduino from sleep will be covered:

via an external interrupt. The Diecimila will wake up only when an external interrupt occurs.

via the UART (USB serial interface). The Diecimila will remain asleep until data is received over the serial interface.

via an internal timer. The Diecimila will periodically be woken up from sleep via Timer1, carry out an action and go back to sleep.

via the watchdog timer. The Diecimila will periodically wake up from sleep via the Watchdog timer, carry out an action and go back to sleep. Note using the Watchdog for this provides the longest sleep time and lowest power consumption (see here).

Note: There are various versions of Arduino available (see the I/O Board section of here), we will be using the Arduino Diecimila with an ATmega168 micro-controller. The source code provided below may run on other versions of Arduino, but the power consumption values will most likely be different.

This tutorial assumes the user is able to run the Arduino environment, create sketches and run them on the USB based Arduino Diecimila. For further information please see the official Getting Started with Arduino web page.

Arduino Power Consumption There are several devices on the Arduino Diecimila that consume battery power, including:

ATmega168 micro-controller

FT232RL USB UART

The power regulator

The Arduino Diecimila I have uses about 35mAmps during normal operation and in power-down sleep mode about 15mAmps. There isn't a huge difference here, the main problem is that the power regulator draws 10mAmps, irrespective of the sleep state the Arduino is in. The ATmega168 micro-controller draws about 0.05 mAmps when in power-down sleep mode and 20mAmps during normal operation.

A cheap 9 Volt alkaline battery will have a typical capacity of 565 mAh. If used to power our Arduino Diecimila, it will last for about

16 hours (565mAh/35mA) under normal operation

up to almost 38 hours (565mAh/15mA) in power-down sleep mode, depending on how often and for how long the Arduino is woken from sleep mode.

If you require your battery to last longer, you would have to consider the following options:

Use a battery with a bigger capacity, e.g. 9 Volt Lithium batteries have a typical capacity of 1200mAh, or you could use a battery pack, made up of several batteries.

Use a solar panel with/without a battery pack. If a battery pack is used, it can be charged by the solar panel during daylight hours.

Use the ATmega168 micro-controller stand-alone outside of the Arduino, see here.

Also note that the power consumption will be influenced by any external circuit that is connected to the Arduino, e.g. if you are interfacing with a bread board or using an Arduino shield.

The more power saving the sleep mode provides, the less functionality is active.E.g. in Power-Down sleep mode, only the external interrupt and watch dog timer (WDT) are active, in Idle sleep mode the UART, timers, ADC, etc are all active, just the CPU and Flash clocks are disabled. See Section 9 of the ATmega168 datasheet for more information.

When the micro-controller is entered into sleep mode by your code, the execution of code will pause at that point. In order to resume execution of your code, the micro-controller must then be woken from sleep mode by one of it's internal hardware modules, e.g. timer expiring, external interrupt, WDT, etc.

There are several Arduino library functions used to control sleep mode. They are:

Yea, it's really a good job already done! Like everybody, I'm searching for this way to wake my arduino up from internal way. Your completion of these series will be great for so many of us ! Thank you very much for your work Donal! Great !

I did a solar tracker using arduino. but the board draw too much power. so I want put arduino in sleep mode when sunlight is not strong. thanks for your BLOG.I am a liitle disappointed that sleep mode only save 20mA. if I put arduino in sleep for 12hr/day. then I could save 240mAhr/day.

I am using the Capacitive Sensing Library to create capacitive touch pins (as per http://playground.arduino.cc/Main/CapacitiveSensor?from=Main.CapSense), and am wondering what levels of sleep, if any, they would be able to bring the Arduino out of.

I am using the Capacitive Sensing Library to create capacitive touch pins (as per http://playground.arduino.cc/Main/CapacitiveSensor?from=Main.CapSense), and am wondering what levels of sleep, if any, they would be able to bring the Arduino out of.