ATtiny85V binary thermometer with auto power-off

I found this post recently and found it’s very interesting for a few things; 1) the way to read internal temperature from ATtiny85V in less noisy mode; 2) negabinary system; and 3) sleep mode to save battery power. It works pretty well. I’d like to thank David for sharing the great project and ideas and nicely written code. What it does is to measure the internal temperature using sleep mode precision and flashing 2 LEDs (one for 1 and the other for 0) in negabinary format. And then it goes into sleep mode to save battery power until the watchdog timer interrupt triggers.

After playing with it a couple of days, I found it was difficult to convert negabinary into decimal number. I’m pretty familiar with binary number and I can easily convert it into decimal up to 32. Why 32? I used to count the binary numbers using my right hand by folding and unfolding fingers. So, 2^5 = 32. However the negabinary number system can use 7 digits to show 23, for example. Also, those numbers, 2^odd, are to be subtracted from the total. To me, it was confusing and difficult to convert.

So, I was thinking to find other way to show the negative number and got this idea. My idea was to blink both LEDs briefly followed by positive number if the temperature is below zero. For example, if it’s -12degC, as soon as you press a push button switch, both LEDs are turned on for 400ms and off. After another 400ms, the positive number, 0b1100 (12), flashes.

The code can be downloaded from my GitHub.

Although it consumes very little current during the sleep mode, it still use the battery power. Instead of showing the temperature at given interval, I wanted to show the temperature when I press a button switch. Also, I wanted to turn it off completely. Since it doesn’t require long booting time like a laptop, almost instantly it turns on and show the temperature. So, I started thinking about a circuit that can latch the power after the switch is pressed until if flashes all the binary digits and disconnect the battery power automatically. Since the total current is just about 30mA (2 LEDs and ATtiny85v), the popular PNP transistor, 2N3906, which can work up to 200mA, can be used on high side. Now, in order to latch the power, another BJT transistor, 2N3904, can be used to pull down the base of the 3906 and the 3904 can be ON by a digital output pin from the ATtiny85v. I had to try a couple of different resistors, but it actually worked!!! Below is the schematic diagram.

ATtiny85V binary thermometer_auto off

It works perfectly with this small current consuming project, but the same circuit can be used for higher current project if you replace the PNP resistor with a logic level P-channel MOSFET.

6 thoughts on “ATtiny85V binary thermometer with auto power-off

    • Hi William,
      I didn’t know the line 31 didn’t show the header properly. Sorry about that. I have updated the code in the post. The line 31 should be #include “avr/sleep.h”. If it doesn’t work, try #include
      Thanks.

    • I’m sorry Bill. I should’ve checked the entire code after upload here. I’m not sure what’s wrong, but somehow WordPress editor messed up with certain characters in the code and deleted parts here and there. I tried to correct it but couldn’t. So, I just posted the code in my GitHub. The link is in the post. Please let me know how it goes.
      Thanks.

  1. The code and circuit now works! Been having fun with it. A couple of things I would like to do with the program.
    1. Leave the leading zeros to blink out. When it starts to blink, you will always know where the bits are starting from. That way, adding up the bit values would be easier. You won’t know what the first bit value is until all the bits are shifted out.
    2. Add a series resistor (1k) at PB2 to limit current from the switch in case you hold down the switch or it gets stuck. When PB2 goes low, it can short with Vcc.
    3. It would be nice to have a version that allows the program to loop at intervals, eliminating the switch. Without a switch, the device can be mounted in a bottle and placed outside on a window shelf or better yet in a garden light, flashing out temperatures in the night.
    Too bad the code got corrupted by WordPress. It’s a pretty neat and different project. I sometimes use an auto-turn off circuit for some of my test devices that are powered by 9 volt batteries and use a Picaxe. I even went as far as making a special PC board to do that function.
    Happy Tinkering.

    • Thank you for your update and comments. The reason why I left the leading zeros off was because I usually used it indoor which is normally over 16 degC, so the 1st of 5 bits always blinks first. But I like your idea. Why don’t you upgrade my code/circuit with your idea and see how it works? Thanks and have fun!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s