December 9, 2013:
Revised: v1.1

A Binary Desktop Thermometer

Desktop thermometer

An interesting object for your office desk or tabletop, this useful and accurate binary thermometer will attract lots of attention from visitors and fellow workers.


I wanted a simple project to help me to learn more about the AVR microprocessor family. AVR  processor outputs have some advantages when it comes to driving LEDs, and I wanted to test out this feature. I had an LM335 temperature sensor sitting on my desk at the time, a part planned for use in another design, and some bright blue LEDs were sitting in my parts box left over from a binary clock I had recently completed. That’s basically how this project got started.

I had purchased a few of the cheapest AVR microprocessors I could find to get me started, and an ATtiny15L, a small 8-pin chip, was also available in my parts box.

Note: The ATtiny15 is now listed by Atmel as obsolete, but the ATtiny25 replaces it, and it even has an ATtiny15 mode.

A digital thermometer is a great project when starting out with microprocessors. The ATtiny15L has a 10-bit A/D converter built-in, so it could be used to measure the 10mV/oC voltage produced by the LM335. In addition, the chip’s ports were capable of tri-state operation, so “charlieplexing” a bunch of LEDs looked simple. Charlieplexing minimizes the number of pins required to drive LEDs, an important factor when you are using an 8-pin chip.

I also felt that a thermometer that could sit on my office desk would make for an interesting conversation piece. That set the basic form-factor.

Development Hurdles

There were a few things to consider. Unlike some microprocessors which will work down to less than 1V, the ATtiny15L requires a 2.7 – 5.5V. I didn’t want to have to use a separate power supply for a desktop thermometer – That’s another untidy cable cluttering up my desk. A 9V battery didn’t seem to look quite right in any physical arrangement I tried, so I looked at other battery options. In the end, a pair of AA batteries seemed the best combination of size, shape and capacity.

When two fresh AA-cells are connected in series, they can produce as much as 3.2V, and when they are exhausted, their combined end-voltage is about 1.6V (i.e. 0.8V/cell). The starting voltage was close to the limit of the chip, and the end-voltage was well below the minimum. Clearly, some form of boost power supply was required.

I could have used a boost PSU regulator chip like the Linear LTC3525 or the Texas Instruments TPS61070 and minimized the parts required - Four or five parts compared with the fourteen parts used here - but I couldn’t purchase any suitable device locally. It’s a common problem, I’m sure. That started me off on a secondary project, to design a reasonably efficient boost power supply using conventional parts.

This is a fairly common problem with many projects – You start designing and building one thing, and end up unexpectedly working on three or four other related mini-projects. In this case, it all worked out well, as shown you can see from the final schematic. The little boost regulator I designed delivers 5V from nearly flat batteries, an input voltage less than 2V, with efficiencies of up to 70%.

But my problems hadn’t stopped there. As I began to develop the LM335 version, I quickly discovered that this sensor required calibration to give accurate results. Solving that rapidly became complicated, with extra parts and additional software.

In the meantime, I found yet another problem. The ATtiny15L had to measure the output voltage produced by the LM335 very accurately. Careful reading of the 85 page datasheet revealed that chip’s internal voltage reference was only accurate to +/- 0.2V, equivalent to a spread of +/- 20 degrees! While I could develop a still more complex two-step calibration method, this was rapidly spiraling out of control.

While it was tough to throw away a few days of software effort, the LM335-based design was clearly a dead-end. So I went looking for an alternative temperature sensor. I quickly found the ideal alternative in the Dallas/Maxim DS18S20. While it’s more expensive, this tiny sensor has a ‘one-wire’ digital interface, it is accurate, without calibration, to +/-0.5oC. A few extra calculations could even allow temperature measurements within 0.1oC. So that was the solution used here

Circuit Description

The circuit diagram of the binary thermometer is shown below. A boost converter built around an LM393 dual comparator (IC1) and a 2N7000 FET (Q3) lifts the voltage from a pair of AA cells to 5V. The LM393 is ideal for such a boost converter. It’s widely available, inexpensive, and able to operate with a supply rail as low as 2V. One comparator is arranged as a square wave oscillator while the second compares the output voltage from the converter against a reference voltage. While it’s not very accurate, a green LED can be used as a simple 1.7V reference source. It also doubles as a ‘power on’ indicator.

Circuit diagram of desktop thermometer
Figure 1 : Schematic diagram of the binary desktop thermometer

Inductors for switch-mode power supplies are often problematic, but with the modest current required to drive a few high efficiency LEDs and the ATtiny15L meant a readily available 1mH axial  molded inductor turned out to be perfect for the task (L1). A Schottky diode was also required for boost converter efficiency and a small 40V/1A type is adequate here (D1).

Battery voltage is first passed through a small BC557 PNP transistor (Q1). This acts as a switch, connecting the battery to the boost converter. It is turned on when the user briefly presses the ‘Power’ button. As soon as the boost converter starts, the 5V supply starts the ATtiny15 microprocessor. It then turns on a BC548 NPN transistor (Q2) which keeps Q1 turned on after the user stops pressing the ‘Power’ switch. Once the measurement and display cycle is completed, the ATtiny15 turns off the thermometer automatically by turning off Q2.

Well, that’s the theory. In practice, when the ATtiny15L turns the supply off, the output of the boost regulator falls, as expected, usually within about 5mS. However, as the chip turns off and it reaches the last stages of powering down and as the supply rail falls below about 1.9V, the chip’s I/O lines begin to act as if they are internally connected via high value resistors to the falling supply rail. This sudden supply voltage appearing on the output line driving Q2, a pin which is meant to be held low, could switch the thermometer back on again! To make sure that Q2 does not turn on, Q2’s base is driven via a resistor divider chain ([R12/R6]). This ensures a supply voltage of at least 3.5V is required to turn Q2 on, and solves the problem.

The Dallas/Maxim DS18S20 sensor converts the ambient temperature it senses into a digital data stream on command from the microprocessor. The command process requires careful timing. The result is a sequence of 8-bit data bursts which are converted by the ATtiny15L into the temperature value displayed on the LEDs. The sensor’s TO-92 plastic case construction does make the device’s response time to temperature changes relatively slow. This is perfectly adequate for a desktop thermometer but it may not be suitable in other applications.

The main temperature display uses six high efficiency blue LEDs to show the numerical value of the temperature in binary format. If it is turned on, a further red LED indicates the temperature being  displayed is at or below zero (i.e. negative). The red LED is turned on at 0oC because no blue LEDs will be lit at this (zero) value of temperature, of course. Alternately, if the thermometer board is covered in ice (not recommended!), you may be able to work that out for yourself just from simple observation!
View from above
While the DS18S20 is capable of temperature measurements from -55 to +125oC, the specifications of the other devices, particularly the ATtiny15L, limits the useful measurement range of the thermometer to about -15 to +85oC. Actually, with the 6 blue LED display, the maximum temperature displayed is just +63oC. I don’t plan to be in the office if the temperature rises above that limit, so that suited me just fine.


The software is written in assembler. Following the power-on sequence described earlier, the software then initializes the DS18S20 sensor. A brief display flashing the array of blue LEDs on and off is then carried out, just to add a little interest to the device, and that done, the DS18S20 sensor is interrogated to obtain the temperature which is then displayed. Strictly speaking, this LED pattern display sequence is quite unnecessary, but I think it makes the thermometer look more ‘intelligent’. It also allows plenty of time for the supply rail to stabilize and the DS18S20 to reset.

The software converts the sensor’s serial data stream into a binary equivalent for display on the LEDs. This display is maintained for a few seconds before the ATtiny15L turns everything off by driving the output pin to Q2 low, which then turns Q1 off. I could have used a pair of 7-segment LED displays to display the temperature, but this would have required a larger microprocessor, like the ATtiny2313, or perhaps an additional chip, like a shift register, to drive the extra LEDs. I had seen a number of thermometers which used 7-segment displays, and to me, these appeared unlikely to generate much interest from people passing my desk. Using a simple series of blue LEDs added a touch of originality, I think, and certainly do draw attention to the device when it is used.
side view of thermometer

Construction and Testing

The thermometer uses readily available components, all of which are mounted on the hexagonal shaped PCB. The PCB artwork can be downloaded from the Download area at the bottom of this webpage. The component layout diagram is also available there.

The size of the PCB was dictated by the space required to mount the two AA cells in battery holders under the PCB. These act as ‘feet’ for the thermometer. Having now used the thermometer for three years or more, I’ve found the batteries seem to last nearly forever. I get at least a year’s life out of a pair of alkaline AA batteries. If I was building it again, I would try to use smaller AAA batteries. That would allow the PCB to be as much as 40% smaller.

Wire link on copper-side of the PCBIf you are building this thermometer, I suggest you begin by fitting the power supply switching components and the boost converter (Q1, Q2, IC1, and related parts). You also need to add a wire link on the underside of the PCB. It's shown in blue on the diagram opposite.

Figure 2 : A short insulated jumper is added under the PCB to tie the batteries together in series

When the construction of this boost converter is completed, temporarily connect a pair of AA batteries to the board. Check that the output of the boost converter is between 4.5 and 5.5V. This may vary depending on the exact voltage drop across the green LED (D8). If necessary, you can select a green LED to give the correct output voltage or you can also adjust the value of R9 or R10 slightly to give the correct output voltage from the boost converter.

Once this voltage is set correctly, mount the remaining parts, taking care to insert the LEDs correctly on the PCB. Solder the 8-pin IC socket for IC2 making sure the notch at one end of the IC socket is correctly oriented.
Take particular care when mounting the transistors and the DS18S20. These all look very much the same, but if you mount a device in the wrong place, the unit very unlikely to work.

You can temporarily fit a short insulated wire between pin 8 of IC2’s socket and any of pins 5, 6 or 7, and a further wire from pin 4 of IC2’s socket to any other of these three pins (5, 6 or 7). This will allow you to check that your blue LEDs can be turned on with the 1k resistors fitted (R15, R16, R17). I used high efficiency LEDs which light up very brightly with very low currents, and 1k resistors were fine. In your case, your blue LEDs may not be bright enough, and these three resistors may need to be reduced. Don’t fit any resistor value less than, say, 220 ohms. In fact, anything below 470 ohms probably indicates you should be using better LEDs. Lower resistor values also means the batteries will be exhausted more quickly.

The underside of the prototype

Figure 3 : The wire link can be seen to the right of the left-hand AA cell. The battery holders are hot-glued to the underside once everything is working. This PCB was made using the milling method which leaves considerably more copper behind and gives the PCB quite a different appearance from the PCB layout shown below. But it's the same layout.

Once this has all been tested, program and install IC2 (ATtiny15L). The legs of the IC may need to be bent slightly to fit the socket, so take your time doing this. The software (Source code as well as the programmer-ready hex file) can be downloaded below. I used Ponyprog ( to program the ATtiny15, but the RS232 port required for that programmer has long since vanished from most PCs. I now use an alternative programmer with a USB interface, the USBasp programmer (‎). You can, of course, use any commercially available programmer which works with the AVR family.

Fit the batteries and we’re ready for the final test.

Pressing the power button briefly should immediately turn on the green ‘power’ LED. After a second or so, the blue LEDs will sweep from side to side for several seconds, and then go out. After a further brief delay, the binary value of the temperature will be displayed for a few seconds. The thermometer will then turn itself off.

That’s it! It’s working.

Layout details
Figure 4 : Component layout

Complete the construction by mounting the battery holders onto the underside of the PCB. I used hot glue. I’ve found this to be more than strong enough.

Future Development

This design met all of the goals I set out to achieve. It is simple to use, and accurate. It’s also been a useful learning experience. In operation, the flashing blue LEDs look very attractive, and explaining binary displays makes for a more interesting start to a conversation with a visitor than chatting about the weather. Mind you, one topic (the temperature) can rapidly lead to the other!

My software can also be expanded. There’s certainly plenty of space left in the chip. I briefly played with another version using an ATtiny25 which used a three-line Nokia LCD display. This gave a temperature readout with 0.1degree temperature resolution, and also confirmed it was possible to write the software without resorting to any tedious floating point code.

If I become bored with reading my thermometer’s binary display, perhaps I might put this other LCD version on my desk to pander to the non-geek population. But it won’t be anywhere near as much fun!


Software: (ASM and HEX files)

PCB Layout: (PCB layouts with and without hexagon outline)

Component Layout:

Want to go back to the main page? Click here to return directly.