1. 程式人生 > >How To Run ATmega328P For a Year On Coin Cell Battery

How To Run ATmega328P For a Year On Coin Cell Battery

An Arduino Uno runs less than one day on a 9 V battery because it uses about 45 mA current. Using an Arduino Pro Mini, with a simple modification, the power consumption goes down to 54 μA (0.054 mA) with the 3.3 V version or 23 μA (0.023 mA) with the 5 V version, in power-down sleep. That is 4 years on a 9 V battery with 1,200 mAh capacity or 2,000 times more efficient than the Arduino Uno. After removing the voltage regulator, the power consumption is only 4.5 μA for the 3.3 V version and 5.8 μA for the 5 V version, in power-down sleep.
The Pro Mini with the ATmega328P chip can be bought for less than $2 from China (see

here).
This article explains what you should know about the Arduino Pro Mini, how to bring the Pro Mini in a low-power mode, how to disable the power LED, how to remove the voltage regulator, which alternative low quiescent current regulators exist, and how much current you save with each step when using the 3.3 V or 5 V version.


Results Overview

ATmega328P Pro Mini Version PWR Source State 5.0 V @ 16 MHz 3.3 V @ 8 MHz
Unmodified RAW Pin ACT 19.9 mA 4.74 mA
Unmodified RAW Pin PDS 3.14 mA 0.90 mA
No Power LED RAW Pin ACT 16.9 mA 3.90 mA
No Power LED RAW Pin PDS 0.0232 mA* 0.0541 mA*
No Power LED, no Regulator VCC Pin ACT 12.7 mA 3.58 mA
No Power LED, no Regulator VCC Pin PDS 0.0058 mA 0.0045 mA

ACT - Active Mode
PDS - Dower-Down Sleep with Watchdog Timer enabled
* Here it is surprising that the 5 V version uses less current than the 3.3 V version. I cannot explain why, but the numbers were checked twice.

What is the Arduino Pro Mini?

The Arduino Pro Mini usually has the same microcontroller (MCU) as the Arduino Uno, the Atmel ATMega328P. Because it is the same MCU, the speed and memory size are the same. The Pro Mini also has the same I/O pins as the Uno.
The major difference between the Arduino Uno and the Pro Mini is their size (see picture above). Further, the Pro Mini does not have a USB Host Connection.
When you buy a Pro Mini, you can choose between the 3.3 V and the 5 V version. The 5 V version can run at 16 MHz while the 3.3 V version only runs at 8 MHz. There is also a version with an adjustable regulator that support 3.3 V and 5 V via a jumper setting. The version with the adjustable regulator has a much higher power consumption in power down sleep. So it is not well suited for battery powered scenarios. Whether you choose 5 V or 3.3 V will likely depend on what sensors or other modules you want to connect. If all modules use 3.3 V then the 3.3 V version is the better choice. If some modules use 5 V, then the 5 V version might be the better choice. Since I want to use the 3.3 V HopeRF Wireless transceiver modules RFM69H or RFM69HW for an upcoming project, I prefer the 3.3 V version.
To upload a sketch, you need a FTDI USB to Serial/UART TTL adapter. For the 3.3 V Arduino version it is recommended to use a TTL Level Serial Converter Cable that converts between USB 5 V and Arduino 3.3 V (see here). Mine uses the CP2102 chip and did only cost 2 EUR. The CP2102 has a 3.3 V and a 5 V connection (the 3.3 V output is on one of the sides), the pins are 5 V tolerant and the level is always 3.3 V. The cable has 5 strands. You connect 5 V or 3.3 V to VCC, GND to GND, RXD to TXO, TXD to RXI and DTR to DTR (can be named GRN). DTR is used by the Arduino software to automatically reset the MCU before an upload. Connect the TTL adapter directly to your PC instead of going through a USB hub. When the direct connection works, then you may test if it still works when using a hub.
One note about the power supply. You can supply unregulated voltage to the RAW pin. For example from a 9 V battery. The voltage must be at least 0.4 V higher than the board voltage because the regulator drops voltage. The difference between the input voltage and the board voltage is dissipated as heat. The datasheet of the standard regulator, the MIC5205, states that to avoid overheating, you should not use more than 6.23 V input for 3.3 V output when using the maximum load of 150 mA (datasheet is linked in sources). Alternatively, the VCC pin can be used to directly power the board. The voltage that you apply to VCC is the voltage that the MCU and all pins will have.
There is one thing to be aware of. The Pro Mini usually comes without attached headers. You need to solder the headers yourself. Unless you have spare headers lying round, I would strongly recommend to buy a Pro Mini where the headers are already included and only need to be soldered. I once tried to just use male jumper cables and got errors when uploading a sketch because the holes are too large for the jumper cable to fit tight enough.

Step 1 - Power Down Sleep to Save Energy

When the ATmega328P is in Active Mode, it will continuously execute several million instructions per second. Further, the On-Board Peripherals Analog to Digital Converter (ADC), Serial Peripheral Interface (SPI), Timer 0,1,2, Two Wire Interface (I2C), USART, Watchdog Timer (WDT), and the Brown-out Detection (BOD) consume power.
To save power, the ATmega328P MCU supports a number of sleep modes and unused peripherals can be turned off. The sleep modes differ in what parts remain active, by the sleep duration and the time needed to wake-up (wake-up period). The sleep mode and active peripherals can be controlled with the AVR sleep and power libraries or, more concisely, with the excellent Low-Power library from Rocketscream (see here).
The Low-Power library is simple to use but very powerful. The statement LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); puts the MCU in SLEEP_MODE_PWR_DOWN for 16 ms to 8 s, depending on the first argument. It disables the ADC and the BOD. Power-down sleep means that all chip functions are disabled till the next interrupt. Further, the external oscillator is stopped. Only level interrupts on INT1 and INT2, pin change interrupts, TWI/I2C address match, or the WDT, if enabled, can wake the MCU up. So with the single statement, you will minimize energy consumption. For a 3.3 V Pro Mini without power LED and without regulator (see below) that is running the statement, the energy consumption is 4.5 μA. That is very close to what is mentioned in the ATmega328P datasheet for power-down sleep with WDT enabled of 4.2 μA (datasheet linked in sources). Therefore, I am quite confident, that the powerDown function shuts down everything that is reasonably possible. With the statement LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);, the WDT will be disabled and you would not wake up until an interrupt is triggered.
To install the library, download it here, rename the extracted folder to LowPower and save it in your library path as C:\Program Files (x86)\Arduino\libraries. The library contains some examples. See here for a complete example sketch. See here for the MailboxNotifier wireless application that uses the LowPower library.
With an unmodified 3.3 V Arduino Pro Mini, you will use only 0.90 mA instead of 4.75 mA when using LowPower.powerDown instead of delay. How to go down to 0.0541 mA is explained in the next section.

Step 2 - Disable the Power LED to Save More Energy

Without the power LED, the 3.3 V Arduino Pro Mini uses about 0.85 mA less, the 5 V version even 3 mA less. However the ATmega328P cannot control the power LED. So, to disable the LED, you need to make a small hardware modification by cutting one of the two tiny traces which connect to the power LED.
There are two LEDs on the Pro Mini board. The two LEDs are marked with a red square in the following picture. The power LED is marked with an arrow. If you are not sure where the power LED is on your board, then you can just power it and you will see the LED.

When you found the power LED, then try to locate at least one trace that leads to the LED. In the second picture below, I marked the traces on my board. A high-resolution picture with a lot of light helps to find the traces.
When you found a trace to the power LED, then you take a knife and break the trace, so that it will not conduct any more. You can see my result in the third picture below.
altaltaltGranulations, your Pro Mini should now only use about 54 μA (0.054 mA) in power-down mode if it is the 3.3 V version and about 23 μA (0.023 mA) if it is the 5 V version.

Step 3 - Replace or Remove the Voltage Regulator to Minimize Energy Usage

All Arduino Pro Mini clones, that I came across, use the same voltage regulator, the MIC5205-KB50/KB33/KBAA. The datasheet of the regulator reveals that the lost current or Ground Pin Current at 50 mA load is typically 0.350 mA and at 0.1 mA load it is 0.080 mA (datasheet linked in sources). So, ignoring the voltage drop, the efficiency at 50 mA load is 99.3 % and at 0.1 mA load it is only 20 %. For 0.0045 mA load at 3.3 V the efficiency is about 10 % because I measured about ten times more current consumption with the regulator than without (see table above).
Even though the standard voltage regulator is not efficient at low current, it is still good enough to run the 3.3 V Pro Mini on 3 AA Alkaline batteries for more than one year, based on the measured power consumption of 54 μA in power-down sleep and 3.90 mA in active mode.
If you really want to, you can remove the voltage regulator as follows. Before proceeding, you may want to check if you have the Sparkfun version of the Arduino Pro Mini. In that case you just need to unsolder a jumper (see Schematic on sparkfun.com).
To remove the voltage regulator, take a gripper tongs and pull it out. You find the regulator at the position shown in the second picture below. The regulator will be destroyed when removing it this way.
alt
Granulations, your Pro Mini should now only use about 4.5 μA (0.0045 mA) in power-down mode if it is the 3.3 V version and about 5.8 μA (0.0058 mA) if it is the 5 V version.
To power the board, without voltage regulator, you need to supply the correct voltage to the VCC pin. The ATmega328P running at 8 MHz can actually support voltage levels between 2.7 V and 5.5 V (see datasheet in sources). However, the voltage on the pins will vary with the input voltage.
Now you might want to connect a more efficient voltage regulator before the VCC pin. Many people recommend a switching regulator. However a switching regulator is usually not efficient at very low currents. As an example for a switching regulator, see the efficiency chart of the POLOLU 3.3V, 300MA STEP-DOWN VOLTAGE REGULATOR D24V3F3, in the screenshot below. Similarly, the SparkFun 3.3V Step-Up Breakout - NCP1402, also a switching regulator, needs 57 μA at 1.5 V or 24 μA at 3 V to provide 4.5 μA at 3.3 V. That is about 18 % efficiency at 4.5 μA when comparing Watts input to Watts output.
altEfficiency of D24V3F3 switching regulator. Screenshot made when visiting this url.

A regulator that is very efficient at micro amp currents is the Microchip MCP1700 or MCP1703. The MCP1700 allows up to 6 V input and the MCP1703 up to 16 V. Both are available with 3.3 V output (MCP1700-3302E, MCP1703-3302E) or with 5.0 V output (MCP1700-5002E, MCP1703-5002E). The datasheet of the MCP1700 states a quiescent current of only 1.6 μA (datasheet linked in sources). The regulators are used in the ultra-low power Arduino compatible boards from Rocket Scream as can be seen in the Schematic from here or from LowPowerLap as can be seen here. The regulator costs below 50 cents. You will also need two ceramic capacitors that can be 1 μF or 10 μF.
altEfficiency of MCP1700 linear regulator. Screenshot made when visiting this url.

With the new regulator, you should be able to power the Pro Mini from one or two coin cells for a year or more.

Further Low-Energy Related Thoughts

You can find articles that bring the power consumption of the ATmega328P down to 100 nano ampere as Power saving techniques for microprocessors. While it is interesting to read, the measures like disabling the watchdog timer, using the internal oscillator, or running with 4 MHz at 1.8 V, are not practical for most applications because used libraries or connected parts may not work with that configuration.
Instead it may be easier to use a stronger battery or to use a solar panel to harvest energy.
If you are planning to run on batteries, then you may want to check the battery voltage level to detect the end of battery life. There is one paragraph called "Detecting low voltage" in this article that describes how to read the voltage of the VCC pin by using the ADC converter. If your 3.3 V output voltage regulator outputs only 3.2 V or 3.1 V then you would know that the battery must be changed. There is also another method that uses a voltage divider. It can be used to measure the battery voltage directly instead of the board voltage. It is explained here and here.
You may wonder why one should not buy a ATmega328P board that is already optimized for low power instead of hacking a board like shown here. The reason, why I prefer to hack a $ 2 board is because it is much cheaper. However, if you are willing to spend a little more than $ 10 then you can search for Moteino, Rocket Scream Mini-Ultra, JeeNode/JeeLink

Sources and Further Readings

Low Power Library - A Layer Above sleep.h, power.h, auto-disables Burn-out Detection (BOD)
https://github.com/rocketscream/Low-Power

MCP1700 - Low Quiescent Current (about 2 μA @ 4 V input) / Low Dropout Voltage (LDO), 250 mA output, linear regulator, input 2.3 - 6.0 V, output 1.2 - 5.0 V datasheet
http://ww1.microchip.com/downloads/en/DeviceDoc/20001826C.pdf

MCP1703 - Low Quiescent Current (about 2 μA @ 4 V input) / Low Dropout Voltage (LDO), 250 mA output, linear regulator, input 2.7 - 16.0 V, output 1.2 - 5.5 V datasheet
http://ww1.microchip.com/downloads/en/DeviceDoc/22049f.pdf

Atmega328P Power Reduction Down to 100 nano-amps (100 nA)
http://www.gammon.com.au/power