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: