Electronics, IT and photography blog focusing on Pentax equipment, AVR Micro-controllers and Open Source (mainly Linux and FreeBSD topics)
vrijdag 14 september 2012
Solar powered Arduino and attiny projects
I've started creating a solar powered base platform for attiny or Arduino based projects. What is the real life need for such a project, you might ask.
Well, the Atmel processors are amazingly energy efficient when programmed in the right way. Your project might run for over a year on a set of 2 normal 1.5V AA batteries.
The example project to which I link in the end of this blog will signal the battery voltage level by blinking a led several times every 10 seconds. Each blink represents 0.1V over the 2.0V base voltage. So 7 blinks means we have a battery voltage of 2.7V.
How long will this project run from batteries? Let's calculate an approximation:
In sleep mode my attiny84 uses 0.004mA. When calculating it uses about 20mA, but it is sleeping most of the time. Running at 8MHz it will only execute code for about 1ms every 10 seconds, so it's average contribution to the power usage is 20/10000= 0.2mA.
The led draws about 3mA when lit. You can measure the current by reading the voltage over the led serie resistor: 1.0V over 330ohm. It blinks 7 times for 125ms every 10s, so it contributes about 7*125/10000*3= 0.26mA on average.
Total average usage is about 0.3 (led) + 0.2 (micro controller)= 0.5mA. A 2000mAh battery will result in 2000/0.5= 4000h battery time, that is about half a year. Note that you should use low discharge NiMH cells (the pre-charged variety) or normal alkaline cells for long running low power applications. If you use solar charging then self discharge is not an issue.
If your project is more power hungry and runs only for a few weeks from a set of batteries, then a solar powered solution makes really sense. Another reason to use solar power is when the application is on a location where changing batteries is difficult.
Charging NiMH batteries
is in general hard when you want to do it optimally. For a start, you cannot charge cells in series reliably. A good NiMH charger will charge each cell individually, because they tend to get out of sync after a while. It's a good idea to charge the cells in a good charger before using them in your attiny project, and e.g. once in a year. For the same reason you should use identical cells of the same make and previous usage. Don't worry too much about these aspects, in reality your solar powered project will run just fine.
Over charging and trickle loading
Over charging NiMH batteries should be prevented. A simple way is to just use a low charge current over a long time. A C/20 current which is interrupted every 12 hours (because it gets dark :-) or a C/40 24 hour constant current (trickle charging) is absolutely safe. For 2000mAh cells this means 100mA or 50mA. Now the good news! You'll have to buy quite a big solar panel to risk over charging your batteries. Just use a small one which compensates the average power usage of your project. Measure charge current during sunny periods and you should be happy if you exceed 100mA or even 50mA. Our example project uses about 12mAh in a day. An average of 15 minutes of 50mA sun charge each day will keep your cells full. So no need to worry about over charging or too less charge capacity in general. If you measure about 2.7V over your two cells then they are fully charged. 2.8V means you're charging. Over 2.9V means that you are charging quite fast. In the latter case measure charge current and consider using a charge current limiter. The cheapest way is to use a smaller solar panel.
The Solar Panel
I used two small 4V/40mA panels in series:
3V is an absolute minimum if you want to get any charge current into your two NiMH cells in series. The cells have 2.4V when they are not full. The dark current diode has a 0.3V forward drop when you use a germanium or Schottky diode, so charging starts at 2.7V. It will start at 3.1V if you use a normal silicon diode which has a forward drop of 0.7V.
Note that the voltage/current specifications of panels are in very bright sunshine. If you need to charge in low light environments then it's better to use a panel which has a voltage specification well over 3V.
If you use a solar panel which provides over 5.5V then you should take care that you do not disconnect the NiMH cells in bright light. The connected NiMH cells will prevent a high voltage, but when they are disconnected the voltage provided by the solar cells may rise over 5.5V and your attiny chip may be damaged. You can add a 5.6V zener diode to prevent damage.
The schema and other components
I've already mentioned the diode which prevents a discharge of the NiMH cells over the solar panel when it's dark. You can use any diode, but for optimal power efficiency you could use a germanium or Schottky diode.
In order to measure the NiMH voltage with the attiny ADC we use a voltage divider composed of two resistors. The attiny has an internal reference voltage of 1.1V, so we cannot measure voltages over 1.1V. The two resistors (1MOhm and 330kOhm) in series divide the voltage approximately by 4, so we'll be able to measure 0 - 4.4V. If you use 4 cells in series then replace the 330kOhm by e.g. 220kOhm, so you can measure up to 6.1V. I used large resistors so that the current loss is very small, less than 3uA. In my example code, get it here from github, I calibrated the resistors and 1.1V reference voltage by measuring the voltage on the ADC input. Note that the 100nF capacitor between the ADC input and ground is really needed to eliminate high frequency noise on the ADC input. Without it your ADC measurements will be all over the place. I also added a capacitor over Vcc and GND just to be safe.
I tested with a power supply of 3.43V. The ADC returns a value in the range 0 - 1023. The expected ADC value would be:
330/(1000+330) * 3.43 / 1.1 * 1024 = 792
I got 775, a 1.5% error, not too bad considering the 5% resistors I used.
How to proceed from here
Now that I have a stable base platform I plan to use it as a remote wireless sensor. I'll be adding a radio transmitter (eg a Bluetooth slave which you already see on the bread board) to send temperature and barometric pressure info to my server. The goal is to intercept this info from a commercial 433Mhz outdoor weather station. Its data will be added to the graph (from another Arduino project) which shows current temperature and humidity in my work room:
The transmitter will need more than 2.7V so I'll either use a DC/DC converter or switch to 4 NiMH cells, but more about that in another blog entry...
Powering a normal Arduino
In this blog entry I described powering an attiny from 2 NiMH cells. The principle is easy to adapt to normal Arduinos. Just use 4 NiMH cells in series (results in 4.8 - 5.5V voltage) and connect it with a diode to a small solar panel which supplies at least 6V when the sun shines. That's all.
You can monitor the charge voltage or (charge) current with a cheap multimeter and check that all is fine. Connect your normal arduino to the NiMH cells and it will run just fine.
If you want to connect the NiMH cells to the power regulator input of the Arduino then you'll have to add more cells for a higher voltage (at least 6V) if you really want to run the Arduino at 5V, but you'll waste some (solar) power. Arduinos will not really need the full 5.0V (except the original atmega8) when they run at 16Mhz, so you can safely use the regulator. As a side effect the Arduino will draw less current because the voltage is now lower. Compared to a standalone attiny the Arduino power led and support circuits will always waste energy, but if your solar panel is not too small it will keep running.
Some measured data:
4 NiMH cells connected to unregulated 5V pin: 45mA current due to led and not in sleep mode.
NiMH connected on regulated Vin pin: 34mA current due to led and not in sleep mode. The 5V pin is now on 4.3V while the 4 NiMH cells provide 5.25V. At this rate (34mA) you'll need to charge every other day, so a solar based charger really makes sense.
Arduino in sleep mode in above setup: I estimate that it will use less than 5mA. This means that a normal Arduino might run a few weeks on 4 charged NiMH cells, and adding a small solar panel will extend this to ever.