Running ATmega328 on Capacitor Power

On a recent visit to the local electronics store, I asked about the largest capacitor that they had, half expecting to get one of the new ‘super’ capacitors. To my dismay, I was given a regular 16V 10,000uF cap. 

As the cost was under half-a-dollar a piece, I bought two of them, even though there was no immediate plans on how to use them. 

Over the weekend, I came across a post (here) which, in very simple terms, describe getting the ATmega328 microcontroller that is used in the Arduino Uno to run on very low power, by utilizing the built-in sleep modes. Immediately, I wanted to see how long an ATmega328 would run on the charge stored in the capacitors. 

Getting started was quick as I already had the microcontroller setup on a breadboard. (For details on how to do this, please refer my previous post.) 

For the sketch, I used a modified version of the ‘Blink’ example which comes with the Arduino IDE. The LED would light up for 25 milliseconds followed by a 4975 milliseconds of delay, which effectively blinks off 5 second intervals. 

The two capacitors were wired up parallel to each other on a separate breadboard, giving a total capacitance of 20,000uF. They were charged to 5.5V using a battery pack. (You can simply apply the positive and negative leads of the battery pack to the respective leads of the capacitors for around 3 seconds to charge them.) 

2x 10,000uF Capacitors
2x 10,000uF Capacitors
Charging the Capacitors with a Battery Pack
Charging the Capacitors with a Battery Pack

For the first run, I used the standard setup without the power saving code. 

The LED blinked as soon as the capacitors were connected to the circuit. The second blink came after 5 seconds, as expected. The third blink – well – It never came. The total runtime would have been somewhere between 5 and 10 seconds.

Great. For the second run, the power saving code was added to the sketch. Capacitors were discharged by connecting to a small DC motor, and were charged back to 5.5V. 

Once the circuit was powered, LED blinked once, then again, then again, then again.1 minute, 5 minutes, 10 minutes passed. Double checked to see whether I accidently left the batteries connected. Nope, it’s running purely on the capacitors! 20 minutes passed, and it was getting both exciting and boring in equal measures having to stare at the LED blinking away.

#include <JeeLib.h>

int led_pin = 13;
ISR(WDT_vect) {Sleepy::watchdogEvent();}

void setup(){
pinMode(led_pin, OUTPUT);
}

void loop(){
digitalWrite(led_pin, HIGH);
Sleepy::loseSomeTime(25);
digitalWrite(led_pin, LOW);
Sleepy::loseSomeTime(4975);
}

Finally, at 47 minutes, the LED flashed for the last time. Essentially, it has blinked more than 560 times, compared with just 2 times without the power saving code. Not bad at all! 

Running ATmega328 on Capacitor Power
Running ATmega328 on Capacitor Power

According to the multi meter readings, the standard ATmega328 setup was drawing around 7mA of current while the LED is off, and around 10mA with the LED on. However, with the power saving code in place, the chip was only drawing a mere 9uA of current while it’s in sleep, which is a significant reduction. 

Several things should be noted here. The capacitors were charged up to 5.5V, which is the maximum voltage the chip can safely handle. (It would happily run using just two AA batteries.) I tried charging the caps up to 10 volts and supplying power through a LM7805 voltage regulator. However, the capacitors were drained out of charge in no time, likely due to the linear power regulation wastage. Also, most regular capacitors self-discharge at a significant rate, and this will affect how long the ATmega328 can run on capacitor power alone. 

The next step would be to find out whether this could be put to any practical use. It would be great, for example, to run a data logger overnight using the charge collected from a solar panel during the day time, eliminating the batteries.

Breadboarding the Arduino Uno

Once you have perfected a project to your liking on the Arduino Uno, moving it on to its own circuit offers several benefits:

  • It free up the Arduino Uno, so it can be used for another project.
  • The project can run on lower power than it runs on the Arduino Uno.
  • The project can be made more compact and durable by housing in a suitable enclosure.
  • It is less costly than having to dedicate an Arduino Uno for each project that you want to make permanent.

The first step in moving a project onto its own circuit is to replicate the Arduino Uno’s functionality on the external circuit.

Sounds complicated? Actually, it turns out to be quite simple.

Arduino Uno is built around the Atmel ATmega328-PU microcontroller. In addition to the microcontroller itself, the Arduino Uno board contains a lot of bits and pieces of circuitry that, for example, regulates power and manages communication with the computer. Most of these extra circuitry are actually not required when you make your project permanent.

Lets discuss how we can get the ATmega328-PU microcontroller running on your own breadboard.

Breadboard Arduino Uno
Breadboard Arduino Uno

To get started, gather the following stuff:

  • 1x ATmega328-PU microcontroller
  • 1x breadboard
  • 1x 16 Mhz crystal oscillator
  • 2x 22 pF ceramic capacitor
  • 1x 10µF capacitor
  • 1x 10kΩ resistor
  • 1x 460Ω resistor
  • 1x LED
  • 1x LM7805 voltage regulator
  • 22 gauge breadboard wire

First, we need to load a program onto the microcontroller, so we can verify whether our circuit is running correctly. For convenience, lets use the ‘Blink’ example sketch which comes with the Arduino IDE.

The simplest way to load the program onto the microcontroller is to carefully replace the chip on the Arduino Uno with our own, and load the ‘Blink’ sketch onto it using the Arduino IDE. Once the sketch is loaded, make sure the onboard LED (connected to digital pin 13) is blinking according to the sketch. Then, extract the chip out of the Arduino Uno and replace the original microcontroller.

Be careful not to break any pins when you remove the chip from the socket; this is easily said than done. If you do not have a chip extractor tool, you can use a couple of screwdrivers to lift the chip from both ends. Also, if your ATmega328-PU did not come with the Arduino Uno bootloader, you will first need to bootload it using the Arduino IDE, before loading the ‘Blink’ sketch.

Great. Then, place the microcontroller and the other components on the breadboard as per the schematic. As you may see, I’ve placed a 10uF capacitor across the power rails of the breadboard to stabilize any noise in the input voltage. This is not a must, but its better if you can have it. Do yourself a favour by using cut-to-length breadboard wires; as tempting as it is to use jumper wires to connect it all together, it will result in a rather messy circuit!

ATmega328 Breadboard Schematic
ATmega328 Breadboard Schematic

To keep things simple, the LM7805 voltage regulator is shown separate from the rest of the circuit. In fact, depending on the components used in the project, you will be able to skip the voltage regulator altogether and power it with just 2 AA batteries; our ‘Blink’ example definitely can be. You can add in the voltage regulator if you intend to use a voltage source of more than 5V.

LM7805 Voltage Regulator
LM7805 Voltage Regulator. Depending on the components used in the project, you will be able to skip the voltage regulator altogether and power it with just 2 AA batteries.
LM7805 5V Voltage Regulator Schematic
LM7805 5V Voltage Regulator Schematic

Once you have put everything in place and wired up the components, triple-check to make sure that nothing is connected to where it shouldn’t be.

Then, power up the circuit. With any amount of luck, the LED should start to turn on and off in one second intervals. Congratulations, you have made your own barebones Arduino Uno with much less components!

Breadboard arduino running the 'Blink' sketch.
Breadboard arduino running the ‘Blink’ sketch.

If the LED doesn’t blink, immediately disconnect power, and check the circuit for any loose or incorrect connections. If you are using batteries, you may also want to check that they have not run out of juice. The ATmega328-PU chip can take some mishandling before going out in smoke; your circuit should run once any errors are traced and fixed.

Namal's blog on everyday geekery.