Using a dollar store solar garden light for low-power ATtiny projects is the holy grail of cheap hacks. Where else can you buy a solar cell, 300mAh NiCd battery, and a boost converter chip for $0.99?  

However, harnessing the converter’s power reliably for a 2V to 5V microcontroller is a bit tricky as its output ranges from off (low battery) up to 10V. The usual approach of adding a LDO regulator or a zener diode and a cap usually works, but adds parts and may not supply a full 2V to 5V range. A more efficient and complicated circuit (link) also supports an efficient low power mode using more parts, and may not work for some types of converter chips.  

A much simpler and cheaper approach is to have the ATtiny regulate its own power supply by monitoring Vcc (battery supply voltage) and controlling the converter by its solar cell input (SOL), using 1 GPIO pin. This is a simplified switched-mode power supply.

A garden light turns off its LED when the solar cell is charging the battery during daylight. At night the solar cell doesn’t charge and the converter, sensing this, turns on the LED. For this hack a GPIO from the ATtiny connected to the SOL input mimics the solar cell activity, making this a converter on/off switch.

Typical garden light circuit using YX805A converter chip (this chip isn't recommended.)

Internal to the ATtiny is a way to measure Vcc using its ADC and an internal 1.1V bandgap reference, Vbg (see Microchip AN2447 for details.)

By free-running the ADC to periodically sample Vcc, the SOL output is toggled based on a selected threshold voltage. A filtering cap smoothes this bang-bang control.

In normal operation Vcc is kept close to the target voltage regardless of power draw (within the converter’s limits.) An added bonus is the threshold voltage may be lowered for a low-power mode, thus extending battery life.

Warning! Why dangerous?

When unconnected to a load the converter’s output shoots up to 10V. The filter cap retains this voltage for a few seconds to a few minutes, depending on how big of a cap is installed. Plugging an ATtiny into a hot 10V socket may damage it, or if you’re lucky, just erase part of its FLASH program. Also, bad software can kill! If the Vcc feedback control loop stops working the converter might stick in the ON state, potentially exceeding max Vcc. You’ve been warned!

Dirty Details:

  • Use an ATtiny85V, the low-voltage version for best results.
  • The ATtiny’s ADC is non-linear and contains measurement errors.
  • The ATtiny’s Vbg reference varies between 1.0 and 1.2V, and has a small start-up delay.
  • The ATtiny’s feedback loop uses the ADC. If the ADC is required for some other operation it needs to be multiplexed carefully.
  • Cheap garden lights use a variety of converter chips. Not all work for this circuit. The YX8051 works ok.


Demo Circuit Using YX8051 Converter Chip:

This circuit shows the mods required to use a garden light. C1 can vary but not recommended below 10uF to keep voltage swings down.

Here's a good link using these converter chips.

Here's a similar circuit (wayback machine, but missing pictures and diagrams) with some regulation. Uses the YX805. I had problems with the YX805 recovering from a depleted battery in my circuit and couldn't use it.

Arduino Code Example:

The ADC is configured for reading Vbg with Vcc ref, free-run mode, generating an interrupt every sample, roughly 630 samples per second.

In the ADC ISR the ADC value is compared to a target threshold, toggling the converter's SOL input as required. Note there's no attempt to calculate an actual voltage value (per AN2447) as we're only interested if above/below a threshold. Also note this ADC value increases for lower Vcc.

To turn off the converter, setting the GPIO on the SOL input to INPUT_PULLUP...

Read more »