Low Power ATTiny85 Experiment

I spent time on and off this summer trying to build a micro-controller-based circuit that would run on minimal power. My desire is to build a circuit that runs on solar power but will fall back to battery during the night or when it is cloudy. Given the lack of sun around here in the winter, it could be a few weeks between days with enough light to recharge batteries so the design must allow the circuit to run for several weeks, minimal, on battery.

The circuit itself is a simple gate alarm. A switch on the gate is monitored. If the gate is opened, a loud beep occurs. If the gate is not closed within a specified time, an audible alarm is sounded. This is a useful circuit for me and a great platform for the low power experiment, because it would need to be mounted near the gate where I have no power, but sunlight is available for charging.

The Micro-controller Circuit

The schematic for the circuit is straight forward:


The micro-controller is an ATTiny85. The gate switch, connected to pin 1 monitors the gate. Pin 2 controls a transistor which sounds the audible alarm. Pin 3 is connected to a push button. When the gate needs to be left open, this can be pressed to silence the alarm. Finally, pin 4 is connected to the RST pin. This allows the ATTiny85 to hard reset itself.

I tend to use Arduino Nanos because they are cheap and full-featured, but they need a lot of power. I think my cheap Chinese version was drawing 70mA. My last low power experiment used an Arduino RBBB but even that took 22mA. The ATTiny85 is advertised to only need .3mA. When in sleep mode, the ATTiny85 only needs .1uA.

To make this project run a long time I want to put the micro-controller in sleep mode and trigger it to wake when either the gate switch or push button switch are activated. I researched how to do this in my blog entry ATTiny85 Wake from Sleep on Pin State Change Code Example.

The Power Circuit

Power is provided with this circuit:


The solar cells were taken from Harbor Freight garden lights. The batteries are 2 NiMH D batteries from Harbor Freight. Fully charged, the batteries provide about 2.6V. For a normal ATTiny85, the operating voltage is 2.7-5.5V. So I use a DC-DC converter to step the voltage up to 5V.

I found the following website useful when trying to set up this circuit so it would use either solar or battery and the solar charges the battery when there is enough extra current:


The downside to using a DC-DC converter is it consumes a fair amount of power. While the ATTiny85 may only need .1uA in sleep mode, the converter is consuming about .4-.5uA. Doing some guesstimating, even at .4uA, the D battery pack would last well over a year. (OK, that is not really possible as NiMH batteries will loose 20-50% of their charge in 6 months). That is more than the 2-4 weeks max time I estimate between being able to get a full charge from the solar cells.

BTW, my sparkfun DC converter took around .4uA. The cheap Chinese one that I replaced it with for the final circuit took 5mA because it had a little onboard LED. I smashed the surface mount LED with wire cutters and scraped everything away with an exacto knife and the current was down to about .5uA.

I ran this test circuit on ONLY the D battery pack. Starting with a full charge of 2.6V, after a month of operation the battery charge was about 2.5V. So I’m pretty sure I’ll be able to count on the battery pack keeping the circuit running between the times the sun is too weak to provide current to the circuit.

If I really needed this circuit to last a very long time on just a battery, I would look at using an ATTiny85V. This micro-controller operates on 1.8-5.5V. With the ATTiny85V, the DC converter could be removed (though doing so reduces the beepers volume). I’m debating getting one of these and trying it. I just need to think up some justification.

Here is the breadboarded projects. Quite messy. The power supply and the micro-controller were built independently and then connected together once I was happy with each.


Oct 2014 Update:

First, I’ve been running this circuit on battery only since early August. It has run almost 2 months on battery only!

I finally had time to move this project to perf board to get it installed:


I figured it would be faster to implement on perfboard. Now that I’m done, I’m not so sure. I can do homemade PCBs pretty fast. The only hiccup would be dealing with the DC-DC converter. I would have had to create a custom component and I don’t know how to do that yet.

There was a mistake in the schematic (now corrected in this blog). Had I created this as a PCB I would have had to do it all over again and chances are I would not have been able to recover all of the components. I’m seeing perfboard is a little more forgiving when I make such a mistake.

The real mistake was made when I was breadboarding the circuit. Normally, I update the schematic, then the breadboard. This project had a lot of messing around in it and I ended up drawing a schematic from the breadboard. At the time I did it I didn’t think drawing a schematic from a breadboard was a good idea. Now I know it for a fact. I wasted time, components, and the end product doesn’t look as good as it could.

Oct 2014: Update #2

It has taken way too long to wrap this up – most of my free time this summer has went into building a basement workshop (more on that soon). As of today the lower power ATTiny 85 circuit, a.k.a. gate monitor, has been installed.

Part of my foot dragging is due to knowing I would have to fabricate some mechanism to sense if the gate is opened or closed.  My 3D printer is down right now, making matters worse. My fabrication skills, admittedly, suck. However, I did a reasonable job this time.

Given this is more of a long-term experiment than an actual production circuit I think the installation will last at least as long as I would like (until next summer).

The circuit board and batteries were installed into a plastic electrical box. I used wire nuts on all leads so I can completely disassemble it if I need.


I decided to just keep the solar cells mounted to the test piece of cedar scrap I have been using all summer. They are held on with double sided tape which I’ve seen last thru at least one winter in the past:


I did seal the wires completely with electrical tape to keep water and snow out.

The gate switch was the trick. In the past I would have used a magnetic reed switch but my last experience with one was bad. I had a spare snap action switch from a past project so I decided to use that.

The plan was to have a bolt attached to the gate that would hit the snap action switch to indicate the gate is closed. This is the same idea used for the limit switches on my 3D printer. The problem with doing this is I can guarantee my fabrication skills are not good enough to build something with tight enough tolerances that a bolt head would hit the lever of a switch.

In the back of my head I decided in needed something ‘hingy’ so the bolt would hit that large target and the lever of the switch would then be hit. As I pondered how to do this it suddenly occurred to me I had some hinge material sitting around. I found it and cut a piece off. I messed with the hinge and the switch and found it would work perfect. Here is my concoction:


Hopefully you can see the bolt attached to the edge of the gate. It presses the hinge which in turn presses the switch lever.

I think that concludes this experiment.

April 2015 Update:

This project worked great all winter. Except in one situation, I never noticed the gate without power. The only time I did was because the gate didn’t close tight and ran the battery down because I didn’t hear the alarm. Even then, it recharged back up pretty quick.

One mistake I made was not doing a decent site survey before installing the solar panel. I knew it would face east and only get partial day sun. What I didn’t realize was that the house’s shadow would cover the solar panel part of the morning. But even with those factors, using D batteries and a circuit that has very little drain, it still worked in the dead of the winter when I could go a week+ without any direct sunlight.

The other lesson learned is in making outdoor hardware as bullet proof as possible. The hinge system I used to connect the bolt to the snap switch spring worked well but eventually the screw holding the hing got a bit loose causing the hinge to get a bit crooked. When that happened, there was no room for error in closing the gate (it had to be tight). If I was doing chores and just going back and forth through the gate, it wasn’t closing tight enough on its own. I would have to latch it into place.

Once I figured out the culprit and cranked down on the hinge screw, problem fixed.

Overall, this little project has worked great and I will keep it in ‘production’ to see how it wears.

If I were going to do this again and wanted the gate battery to last as long as possible, I would connect the power supply directly to the switch so the circuit stays entirely off except when the gate is opened. But even with the ATTiny85 drawing power in sleep mode, I am not going to overrun the solar cells and should always be able to run the alarm for enough time to hear it.

Edit May 2016:

There is a nice write up on minimizing power usage in the January 2016 Nuts and Volts (Vol 37 No 1.) entitled “Beyond the Arduino Power: Less is More”. Unfortunately this isn’t posted online (at least at this time), but maybe they’ll change that status some day:



This entry was posted in c-tinys, Low Power Arduino. Bookmark the permalink.

6 Responses to Low Power ATTiny85 Experiment

  1. Pingback: Low Power and Solar Power | Big Dan the Blogging Man

  2. Sean Straw says:

    Where possible (okay, ALWAYS), I like to keep the RESET pin on the AVR as a reset pin and not reprogram it as I/O – that allows me to reprogram the uC it in-circuit via an ICSP header.

    I’m unclear as to the arrangement of 3, 4, and RESET – you can reset by driving RESET low. Are you driving 4 high and looking for a signal on 3, then driving 4 low to effect a hardware reset, or?

    This looks like a good candidate project for using the ATTiny43U. I admit that I have yet to tinker with it myself (I should at least order a tube of them and rectify that), but these have a BUILT-IN boost controller, so you can run them directly off of almost nothing.

    Li-Ion batteries are a potential power source to consider. You can run a boost controller from one or two solar cells to charge the battery, and drive the uC direct off the battery voltage. I love it when laptop batteries make an appearance in the e-waste at the office. One duff cell, or perhaps that they all don’t quite hold the max charge anymore, but a typical PC laptop battery is 9 “18650” type cells. What I use them for rarely need to pull a high current, though the batteries can deliver juice when needed.

    I hear you on the LED load on devices – sometimes they exceed the load of the driven device. I de-solder them and drop them into a little bin of LEDs for potential re-use. Yes, the itty-bitty SMD ones.

    IMO, there is little need to decide to run off of battery OR solar – just set things up so that the battery is charged from the solar and pull your power directly. Less complicated logic, no I/O to make the determination, no switching device and/or voltage drop associated with one, etc.

    I have a couple of old NiMh batteries that are charged in parallel by a single small solar cell (about equal in surface area to _one_ of the four cells you have), which happens to be taped vertically to the inside of a window facing EAST (i.e. only gets direct sun in the morning for a few hours), with a diode in line from the solar cell to the batteries, so that the batteries don’t discharge into the solar cell at night. A small joule thief circuit is driven off the battery, via a light detector, so it comes on only when it is low light. I have this pointing down at my electronics workbench, so that when I walk into my barn, I don’t have to flick on an overhead lamp to find my way to it. Despite the inefficient location of the solar cell, the batteries charge. Even on overcast days.

    Looking at your solar/battery setup, I’m unclear as to why you have two additional diodes in there – that _assures_ a 0.7V diode drop from the battery as well as the solar. I’d lose the two diodes nearest your converter in the schematic and connect the converter at the junction between the batteries and the diode from the solar cells. There, you’ll get full battery voltage (and consequently, lose less power). As long as the solar is outputting more voltage than the battery + the diode drop (0.7V, but you can find diodes with lower voltage drops – I use some 0.3 and 0.4V drop devices), the battery will be getting charged. The link you provide to “robot room” has a battery backup, and that arrangement has diodes from the positive sides of both the solar and the battery, oriented in opposition to one another, which you’d do if you were using a NON RECHARGEABLE battery. In your case, you want the battery to recharge from any excess solar power you have, so that type of arrangement is undesirable.

    An additional trick to using less juice on the ATTiny uCs is to set the fuse bits to run the uC at a lower clock speed (which in many applications – including this one – doesn’t have a negative impact).

  3. Sean Straw says:

    I meant to edit the first paragraph about keeping the RESET pin as a reset pin, since it wasn’t applicable to your design.

    Have a couple of other comments:

    You can forego the resistor and still consume less power than driving the LED constantly if you rapidly pulse the status LED.

    You can read press patterns on the button – say a long hold to silence the alarm for ‘x’ minutes, and a brief one to just reset, etc. I did something similar to this on a device I fabbed for a “fun Friday” event at my office – if the button is depressed when the device boots, a flag is set to enter a certain operational mode. If it is still depressed (well, technically, could be released and re-depressed) after an LCD initialization sequence, then the device enters a diagnostic mode, wherein it continuously reports readings from some sensors.

    Anyway, good to see that the ATTiny has found a place in your projects. You’ll come to love the utility of that little guy, and the price makes it easy to use almost indiscriminately…

  4. Sean Straw says:

    I should always evaluate the circuit more before commenting: I now realize you’re already using Schottky diodes (1N5xxx … duh), so at least already start with the lower voltage drop, although I still maintain you can do without the three diode arrangement.

    I was discussing this circuit with my son over lunch this afternoon and explaining the multiple voltage drops (from solar to battery, and from battery to circuit), and the obvious struck me: if there is nothing to monitor and alert if the gate is in fact CLOSED, why not move the gate switch to between the power and the boost module? Surely there’s no need to power the circuit if the gate is closed?

    I don’t know if you flash the LED periodically to indicate that battery is good or not – in that case, you’d want power to the uC. OTOH, if the gate monitor were to chirp (and flash the LED briefly) whenever the gate initially opens, then every time you used the gate, you’d have an indicator, and could simplify the design. This also largely negates the need to use sleep mode.

    • Dan TheMan says:

      Hahahahaha! Actually, when I was doing the first experiment last winter I decided to fire the arduino up only when the gate was open. It wasn’t until you got me looking at the ATtiny that I realized I could run it long enough that I could return to the idea of leaving it run all the time.

      So the software was written such that if I press the pushbutton, it wake up the CPU and flashes the status LED once and goes back to sleep. An easy way for me to verify the battery isn’t dead.

      In the real world I would power it down. Since this is a learning experience I want to let it run so I can see how it lasts thru the winter.

      I’ll go back and review the solar cell setup, but I was slammed the last couple of days and today I’m making I in a great fall day!

  5. Sean Straw says:

    Insofar as implementing the boost module on your PCB, you could have laid out a USB header pad on your PCB (quite likely a component available in your footprint library, or something you could download online), then soldered individual pins from a header strip (or just wire) to the two power pads on your PCB and “piggybacked” the boost module over that and soldered the two power pins to it.

    Every so often you’ll run across a PCB where some component (a radio module for instance) is soldered down to the main PCB with a set of header pins, rather than being laid out into the main PCB.

    I have a binload of perfboard (both plain and copper padded) which I don’t use outside of a real quickie solderjob because breadboard prototype to etched is so much faster and easier for me than fiddling with soldering the various bridges between components. Once you decide to fab more than one of something, it’s a no-brainer to go etch. Plus, perfboard isn’t at all SMD friendly. I have a few SMD devices soldered to adapters to convert them to through hole for prototyping on breadboards (which is preferable to using a “similar” through-hole device that isn’t precisely the same spec), but wouldn’t want to waste the adapters to transfer the SMD components to a perfboard.

    I’m looking forward to the winter, when I’ll have a bit more indoor time to work on electronic projects than I’ve had this summer. With critical work projects lately, I’ve lacked the time for tinker (outside of spending a couple of days on a CO2 laser cutter).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s