This first project is kind of a “Hello World” of electronics, since it does not involve much more than lighting a LED. But it is something I had meant to do for a long time: a proper solar-powered lamp which, unlike most of the cheap stuff you can buy in stores, would stay lit for the whole night, have a nice light color, configurable dark detection, protection against deep battery depletion, and several lighting modes, in short be exactly the lamp I wanted. So… here it is!
Before going further, I should mention that there are other projects around, such as the “Kimono Lantern” by the Tokoy Hackerspace, which is a very nice design – and also a pretty special story as it was used extensively after the 2011 Japanese earthquake. But it does not match the specs I had in mind, so I decided to do another design from scratch.
On top of the specs mentioned in the intro, I also wanted the lamp to be powered by a single AA rechargeable battery and fit inside a standard jam jar. The final specs are therefore:
- Single AA battery power
- 6.5cm max board size
- Light modes: constant on, on 50%, flicker – “candle like”, strong flicker, and several blinking patterns
- Warm white color
- Configurable dark detection
- Stop the LED before the battery gets totally depleted
- Weatherproof: most of the cheap stuff you buy in stores fails after a few months because of humidity, we don’t want this!
In order to be able to create something really flexible, I decided to use an ATtiny series microcontroller: those are very easy to progam and take about 5 minutes to get familiar with, really. Tons on info on them on the Internet, you can program them in C, and there is a nice Eclipse plugin to do fast development with a good level of comfort.
The schematics of the first version are shown below:
As you can see, there is nothing very special about this lamp: basically a LED and a switch. The extra components are a voltage divider, and the power converter which is the only really interesting bit and is described in more details below.
One of my main requirements was to use a single AA cell, but white LEDs normally require a voltage in the region of 2.5 to 3V: this means we have to create a higher voltage from the 1.2 standard AA rechargeable battery voltage. The standard way of doing this is through what is called a “boost converter”.
In our case, though, we are in luck: Atmel makes a special version of the ATtiny called the ATtiny43u, which contains a built-in boost converter driver! This ATtiny is especially designed for use with single cell designs, and is able to create its own 3V power from any source above 0.7V using just a few external components, namely the inductor, diode and capacitor mentioned above – the ATtiny takes care of the switching.
Not only does Atmel make those AVRs with built-in boost converter controllers, but they also have written an application note for the ATtiny43u called “AVR188: Design Guidelines for ATtiny43U“. This document gives advice on component selection as well as PCB layout tips. In short, it makes our job very easy, which is good since it is important to get good converter efficiency if we want our lamp to work properly.
As can be seen on the schematic above, I used the recommended component values from the design note, no need to get fancy and be more clever than the Atmel engineers! I will get back to this point when I talk about PCB layout.
Once the prototype is built, we will be in a position to check out how the boost converter behaves and decide whether we should use other component values to improve things if necessary.
LED selection was pretty important for the project: it is not that easy to find good white LEDs with okay efficiency and a nice light color: most whites are nearly blue and very cold, which is definitely not what I was looking for! After a few hours spent on the internet searching for good sources, I finally found what I was looking for with Evil Mad Scientist, another of my favourite Open Hardware blog/shop/company: they stock quite a few types of LEDs with various colors and several whites: I placed an order for several kinds, colors and sizes to test on my initial prototype.
I finally selected their 10mm warm while diffused LEDs, which looks absolutely great! I have also used their smaller 5mm model for another project too, which I will describe one of these days.
Sink or source?
One question when connecting the LED to the AVR is whether the I/O pin will be used in sink or source mode, i.e. whether the LED will be connected to VCC (sink mode) or GND (source mode). I tried both solutions for the prototype version of the design, as described below. The main difference, according the the ATtiny43u spec sheet, is that the ATtiny43u has got so-called “High sink” I/O pins which are able to sink more current than other pins – and more current than in source mode too.
No current limiting resistor ?
On the schematic, the LED is connected directly to one of the AVR pins, without a current limiting resistor – or rather a 0 ohm resistor, so that I can experiment with various LED types. This is rather counter-intuitive until you realize that the ATtiny43u is running at only 3V on its boost converter. Despite the fact it advertises being able to output up to 30mA on its pins, actual current output capability depends on the voltage that is present on the pin. The 10mm white LEDs I have selected have a forward voltage of 2.7V, and looking at ATtiny spec sheets below, at that voltage the ATtiny will only output about 5mA!
Strangely enough, the ATtiny43u spec sheet available on atmel.com seems to have stayed in preliminary version but the voltage/current graph for output pins is present in most other ATtiny reference documentations, and the 43u seems to be following the same characteristics. Our white LED is therefore driven at around 4 to 5 mA, which is way below its max capabilities, but – and we’re in luck here – about as bright as a small candle, which is exactly what we need.
In sink mode, on the other hand, we connect the LED to VCC and the LED will only light up when the I/O pin is in logic zero state. I have connected the LED to PB1 which is a ‘high sink’ I/O. Nevertheless, we are in a similar position as in the previous case: looking at similar ATtiny family spec sheets, and with the LED voltage still being at 2.7V, the minimum I/O voltage of the pin ends up around 0.2/0.3V when it is in logic zero, which corresponds to a roughly 10mA figure – on the ATtiny 85 spec sheet – as shown below:
The conclusion for this is that we should get a marginal increase of current through the LED if we connect it in sink mode rather than in source mode. Testing on the prototype confirmed this, so a sink-mode solution was chosen for the final design.
For the charging part, the AA battery is simply connected to a small solar cell, through a diode: using low power cells guarantees that there is no danger of damaging the battery even on very long and sunny days: a 1000mAh battery can safely be trickled charged for 8 to 10 hours at a rate of 20mA, or a 600mAh at a rate of 15mA (using C/40 as trickle current).
For efficiency purposes and to make my life easier, I used the same low-dropout diode as for the power converter: in both cases we are looking for the lowest possible voltage drop on the diode to improve efficiency, so using the same component actually makes good sense.
At this stage, the question is: what sort of solar cell do I need, and will this cell be able to fully recharge the battery on an average day?
AA NiMH batteries comme in all forms and sizes, and generally have a capacity above 700mAh. More importantly, recent batteries support up to 1500 charge cycles, which is an important figure if we want our solar light to last several years on the same battery: remember there are 365 days in a year, so you do get at more than 1000 charge cycles in less than three years.
I wanted something less than 6cm wide for the panel: a few searches showed that a standard value seems to be 2V/150mA, and such panels can be found on Chinese wholesale sites quite easily. I would have liked to use ‘made in EU’, but it seems that no one in Europe makes this kind of small panels… Of course, a claim of 2V/150mA should be taken with a lot of caution, so real world tests will be essential.
- LED fully lit: 5mA at 3V Vcc on the ATtiny43u
- ATtiny43u current draw at 1.2V battery voltage with boost converter active: 5mA from the spec sheet
On the solar cell side: with a theoretical 2V/150mA for the panel, we should be able to count on around 20 to 30mA on a well-lit day, so we will get those 140mAh back in just a few hours. In theory. Actual measurements once the protype is built will check this against real world values. More in the further articles!
Light detection is very easy to do on our circuit: after all, we have a solar panel which will output a voltage that is proportional to the amount of light it receives, up to a point – but at the high point, we are in full daylight anyway, and we only want to detect darkness.
The panel voltage cannot exceed the voltage of the AA battery plus the diode’s dropout voltage (about 0.35V). We are putting this voltage through a resistor bridge to get it divided by two, and we measure it on one of the ATtiny ADC ports. Our plan being to use the internal 1.1V voltage reference, we should be well within the limits for the maximum ADC voltage that will be measured on the panel with no big difficulty.
Additionally, the voltage divider only uses a tiny bit of energy and only when there is power on the solar cell: about 60uA, which is negligible.
Nothing much to say about the switch: no need to external resistors, we can just use the ATtiny’s internal port pullups: a press on the switch will make the switch pin go from “1” to “0”. As we will see in the firmware part, we want to be able to wake up the ATtiny43u from sleep by a switch press, and on the ATtiny43u this is possible using the PIN level change interrupts, so we are fine.
This ends our first part on the solar lamp design. Our next article will focus on designing the PCB – it will be my very first PCB which uses SMD parts – and have it manufactured.