Home Computing TinySnore Turns Your ATtiny Into a Low-Power Prodigy

TinySnore Turns Your ATtiny Into a Low-Power Prodigy

By Jeremy S. Cook

Freelance Tech Journalist / Technical Writer, Engineering Consultant

Jeremy Cook Consulting

May 03, 2024

Blog

Image Credit: Jeremy Cook

The ATtiny 25/45/85 series is a fantastic little chip, with a low price, flexible voltage input options, and a limited number of IO pins that can be a fun optimization challenge*. It uses a minimal amount of power when compared to something like an Arduino Uno, or certainly a Raspberry Pi, but running an ATtiny constantly will still drain a CR2032 battery, or even a couple of AA cells, in a relatively short amount of time.

Put your ATtiny to sleep with the TinySnore Arduino library! Once it’s installed, simply call the snore(sleep_ms) function in the same way you would typically use delay. For applications that need to do something intermittently (e.g. take environmental readings), this can dramatically reduce power consumption.

Per creator Connor Nishijima’s Reddit blurb** in the library (some years ago) ATtiny stats are as follows:

  • At 5V, 16MHz: Active current = 14.8mA, sleep current = .0066mA
  • At 3.3V, 16MHz: Active current = 8.5mA, sleep current = .0047mA

This is a massive (minuscule?) reduction in power needs, and agrees with Figure 22-12 from the ATtiny25/45/85 datasheet:

Image Credit: ATtiny25/45/85 datasheet

To put things in perspective, a CR2032 coin cell battery nominally outputs 3.0V, with a current capacity of roughly 235mAh. Taking this to be close enough to the 3.3V number listed above, in active mode an ATtiny will exhaust this power supply in about (235mAh / 8.5mA =) 27.6 hours.

However, put the ATtiny to sleep and you instead get 235mAh / .0047mA = 50,000 hours. That is 2083 days, or 5.7 YEARS! The significant caveat is that the ATtiny is not doing anything useful while in sleep mode, but it can wake up intermittently to perform a function–e.g. take a temperature reading–then go back to sleep when the task is done.

While actual results will depend on your particular application, putting your ATtiny to sleep will extend the device’s life significantly. TinySnore makes it super simple.

 Caption: TinySnore can be installed via the Arduino IDE’s library manager / Image Credit: screencap

To test this out, I wrote a script that turns an LED on using the delay function for 5 seconds, then turns it off for 5 seconds with no “snoring” whatsoever.  Code is found here for modified blink sketches in snore and no-snore versions. A CR2032 battery was used with a 220 ohm resistor for the LED. An ATtiny 45V was tested running at 16 MHz.

  • No-Snore Results: LED on: 10.6mA, LED off: 7.1 mA, average: 8.9mA
  • Snore Results: LED on 4.2mA, LED off: 0.0mA, average 2.1mA

In the snore version, the vast majority of current was used by the LED itself. Note that the LED can stay on when sleep mode is activated.

Endurance

The result of this experiment is that the non-sleep version of this LED blinker will intermittently shine for 26 hours, while the TinySnore version can go for 112 hours, or about 4 ½ days. Of course, if you cut the cycle time down, say to 5%–e.g. 1 second on, 19 seconds off, the average would then be cut down to .21mA, giving a run time of 1119 hours, or roughly 46 ½ days.

While you may have a more interesting application in mind than blinking LEDs, it’s a great illustration of how a few simple changes can dramatically affect battery life. That being said, putting your device to sleep isn’t the end of your efficiency journey.

Caption: Current consumption isn’t really 0, but low enough that my equipment didn’t register / Image Credit: Jeremy Cook

TinySnore is an excellent tool for minimizing ATtiny power consumption, but it’s not appropriate for every project. Other options that should be considered include using a lower voltage power supply and/or a processor frequency while changing the LED resistor values on your display.

Such techniques can be a bit more nuanced and require knowledge beyond simply using a library. In my upcoming Developing With Arduino online training session I’ll go over concepts and techniques that you can use to minimize your IoT devices’ power consumption, allowing you to get the most out of resource-limited devices. I’m really excited about this subject, and I hope you will join me to learn more!

*This “Secret Maze” game, with four LEDs, four buttons, and a buzzer, is probably the most impressive ATtiny IO optimization that I’ve ever seen.

**Also. per that Reddit blurb, the library appears to work with the ATtiny84 series as well, though I have not tested this.

Jeremy Cook is a freelance tech journalist and engineering consultant with over 10 years of factory automation experience. An avid maker and experimenter, you can follow him on Twitter, or see his electromechanical exploits on the Jeremy S. Cook YouTube Channel!

More from Jeremy

 

Reference

Denial of responsibility! TechCodex is an automatic aggregator of Global media. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, and all materials to their authors. For any complaint, please reach us at – [email protected]. We will take necessary action within 24 hours.
DMCA compliant image

Leave a Comment