Introduction: DIY Miniature Thermometer

Picture of DIY Miniature Thermometer

For just a couple of bucks and a few components you have laying around your work area you can build a min thermometer than fits in your pocket. The whole circuit sits nicely right on top of a 9v battery, and is connected to it with double sided tape. Changing batteries was never so easy!
I hope you enjoy the project and vote it for the contests!

Step 1: Mini Thermometer Demonstration

In case you were wondering why the LEDs are flashing multiple times on each flash it's because I'm using PWM to power the pins. 

Step 2: Ingredients:

Picture of Ingredients:


  • Three bananas with hot sauce
  • Arduino (of course!)
  • Breadboard and jumper wires!
  • ATtiny85/45
  • 8 DIP socket
  • Temperature sensor (I'll be using the LM35)
  • 3 LEDs(Preferable different colors with appropriate resistors)
  • 9v battery and clip
  • Perf board
  • LM7805 5v regulator (Instead of using a 9v batt and a regulator you can use a 3v battery or 3 AAA)
  • 1 small pushbutton
  • 1 small on/off latching button
  • 10k ohm resistor
  • Multimeter
  • Dremel (or other tool to cut perf board)
  • Soldering gun and solder
  • Sharpie
  • Wire cutters & strippers
  • Double Sided Tape

Step 3: Schematic & Files

Picture of Schematic & Files

Here is the sketch I will be running. I will be talking about it a little later.

Step 4: The Circuit P.1

Picture of The Circuit P.1

Before you make the circuit it is always a good idea to breaboard the circuit. I made this mistake and I hope I won't ever do it again. I was so frustrated thinking I had soldered something wrong when really it was something wrong with the code. I recommend testing the circuit with your Arduino first then trying with an ATtiny85. After than you can begin to work on the permanent circuit. 

First of all you need to cut a piece of perf board to the size of a 9v batter. Then get a 9v battery clip. Now I made one myself and you can find the instructions in step 2 of my i'ble.

  1. On either side of the board solder the 9v and GND connections.
  2. Push in the latching pushbutton. This will be the on/off of the whole circuit so you want it to stay in either the up position or the down position. Solder one lead to 9v on the board.
  3. The LM7805 is to cut down from 9v from the battery to a 5v that the ATtiny85 runs of off. Push it into the breadboard near the switch. Solder the input pin of the 7805 to the opposite side of the switch. Then solder the GND from the 7805 to the GND on your board. The reason I put the switch before the LM7805 is because I didn't want voltage constantly flowing through it.
    For your information the fourth picture contains the pinout for the LM7805.
  4. At this point you might want to test the circuit and make sure that you are getting 5v.

Step 5: The Circuit P.2

Picture of The Circuit P.2

  1. I'm not really doing this in order but push in the 8 DIP socket and the pushbutton.
  2. Connect pin 8 of the DIP socket to 5v.
  3. Connect pin 4 to GND.
  4. Now I took my LED and chopped in in half- just to save some space. Solder the anode to 5v and the cathode to a resistor. Run the resistor to GND.
  5. Connect one side of the pushbutton to 5v. Connect the other side of the button to GND with a 10k ohm resistor. Also on the same side as the resistor, solder a wire from the button (BEFORE THE RESISTOR) to pin 3 on the socket.
  6. Check your pushbutton. This is a very important step because if you don't have your button soldered correctly, the whole circuit will not work. Time to pull out your multimeter! Attach one end to GND on the board and the other to pin 3 on the socket. Turn the circuit on (latching button, LED should come on) and press the button. If all goes well you should get 5v every time you press the button. If all doesn't go well recheck your connections and refer to the schematic.

Step 6: The Circuit P.3

Picture of The Circuit P.3

  1. Trim down two more LEDs.
  2. Solder one of the LEDs to pin 0 and the other to pin 1. You can solder the cathodes together and run them to GND using 1 resistor or you could use 1 resistor per LED. I chose not to use one at all.
So this may all be a little confusing but at this point we should have properly connected the on/off button, LM7805, power LED, 2 indicator LEDs, 8 DIP socket, and the pushbutton.

Step 7: Last Bit of Soldering!

Picture of Last Bit of Soldering!

The last soldering you have to do is to connect the temperature sensor to the circuit. Now in my project I used the LM35 but you can use pretty much any temperature sensor you wish to use. Connect the sensor's Vcc and GND to 5v and GND of your board. Then connect Vout to pin 2 on the socket. You done with soldering!

The last thing to do is to connect the 9v battery clip to the batter, and using some double sided tape, attache the board to the battery. 

It's time to get to some programming!

Step 8: Programming!

You will need to upload this sketch to your ATtiny85. If you don't know how to do that click here for more instructions. I will be post a i'ble on how to do it soon as most of the instructions out there have old and non functioning files. Upload this sketch to your ATtiny85, push it into the socket, connect the circuit to a 9v battery, push the on/off button, then press the second button, and PRAY that it works! Lol you should be able to tell the temperature.

In the next step I will give you some details about the code. I also laced the code with comments so that should help out a little bit. 

Step 9: Code Preview

Make note

In my conversion from Celsius to Fahrenheit I added and extra 4. In other words, in order to convert from C˚ to F˚ you multiply the C˚ by 1.8, then you add by 32.

/* DIY Miniture Thermometer

This circuit is small thermometer that fits on the back of a
9v battery. Two LEDs flash out the temperature. For instance, if the
temp is 75, the first led will flash 7 times, and the second LED will
flash 5 times.

The circuit:
*Vout from the sensor is connected to A3
*Input from the button goes on pin 4.
Make note: This is not the same as physical pins.
Please see for more info.

created in 2013
by Daniel Nicholls
Edited by Enjoying Electronics

Additonal Notes:
The conversion scale you see that Ctemp is set to is just for the LM35 temperature sensor.
Look up your own temp sensor's conversion scale and change my number to whatever your number is.



int Ctemp; // Temp in C˚
int digit10s; // Temp 10s digit
int digit1s; // Temp 1s digit
float temp; // Temp in F˚
int tempPin = 3; // Raw input from the temp sensor

int LED10 = 1; // LED to flash the 10s digit
int LED1 = 0; // LED to flash the 1s digit

int button = 4; // Digital input from the pushbutton
int bPress; // Variable that names the sate of the button

int time = 250; // this variable "time" is the delay between the flashes of the LED.
// so if the LEDs are flasing too slow or too fast you can
// adjust it here and it will change the delay everywhere.

void setup()
{ // You should know what all this is :P
pinMode(LED10, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(button, INPUT);
pinMode(tempPin, INPUT);

void loop()

Ctemp = analogRead(tempPin); // Okaydokey we are setting "Ctemp" to the anlog Reading at tempPin. Remember what tempPin is?
Ctemp = Ctemp * 0.48828125; // Converting the analog voltage from the temp sensor to celcius. This is ONLY FOR THE LM35
// Note: This number may be a little off for the LM35. It seems to work OK though.

temp = (Ctemp * 9 / 5) + 36; // Now this is for converting the Celsius reading (Ctemp) to a farenheit temperature.
// We are setting "temp" to the new F˚ reading.

bPress = digitalRead(button); // Setting "bPress" to a digital reading at button. If you recall "button" is set to pin 4.

/******************************BEGINNING OF PLAIN COMPLICATED!*****************************/

if (bPress == HIGH) // The fist if statement. None of the code below will run unless this condition is met.
digit10s = int(temp / 10); // find the 10s digit of the temp. If your temp was 26.89 then it will become 2.689 (divide by 10) and the then int() instruction casts it to an integer removing everything after the decimal place then leaving you with digit10s = 2
digit1s = int(temp - (digit10s * 10)); //find the 1s digit. We use the 10sdigit from above and multiply it by ten, giving 20 and subtract that from our temp (26.89) leaving us with 6.89, then cast this to an int reducing it to 6.

while(digit10s != 0) //do a while loop while digit10s does not equal 0
analogWrite(LED10, 75);
analogWrite(LED10, 0);
digit10s--; //decrement digit10s by 1
} // end of the while statement


while(digit1s != 0) //do a while loop while digit1s does not equal 0
analogWrite(LED1, 75);
analogWrite(LED1, 0);
digit1s--; //decrement digit1s by 1
} // end of the while statement

} // button check

else // Now, do you remeber our IF statement? It was testing the button. So, if the button insn't pressed, turn all the LEDs off.
digitalWrite(LED10, LOW);
digitalWrite(LED1, LOW);

delay(10); // it's to stop the code running too often.

} // void loop

Step 10: How Does the Code Work?


The first thing that needs to happen is we need to get temperature into two separate digits. This is actually easier than you might think.

    digit10s = int(temp / 10);
    digit1s = int(temp - (digit10s * 10));
With this we can separate the two digits. Lets tackle the first one. digit10s is equal to the temperature divided by 10. Our example temp is 63, so 63 / 10 = 6. Now digit10s is equal to 6.

Now for the 1s digit. digit1s is equal to temp -  digit10s * 10.  So if our temp was 63, we subtract (digit10s * 10 = 60) from temp which gives us 3.

digit10s was 6, then we multiplied it by 10, which gives us 60, then we subtract 60 from temp (63). That then gives us the 3. We then set digit1s = to 3.

And that is how the digits are broken down!

Our next bit of code is just a bit more complicated.

This is our main block of code because it's what makes the LEDs flash the temperature.

    while(digit10s != 0) //do a while loop while digit10s does not equal 0
       analogWrite(LED10, 75);
       analogWrite(LED10, 0);
       digit10s--;       //decrement digit10s by 1
    } // end of the while statement

The first thing to notice is that we have a while loop and what this does is that as long as the condition is met, the code will run over and over.

Now what condition?

while(digit10s != 0) *** This is saying run the block below as long as digit10s is not equal to 0.

Lets look into digit10s. Digit10s is the 10's digit from the temperature. We dived the temperature by 10 to give us the 10's digit. So say it's 63 degrees outside. The 10's digit (digit10s) is equal to 6.

Now how does this flash the LEDs the proper amount of times? Well, it's saying, "digit10s is not equal 0, (remember, it's equal to 6 now) so run the block below. The first thing is it turns the LED on for 1 second then turns it off. Then we come to this

digit10s--; Here we use the '--' operation and what that does is it takes off 1 from the variable every time it gets passed. So that means if digit10s was equal to 6, it is now equal to 5. Now 5 is still not equal to 0, so we run the block again. Running the block again turns the LED on and off one more time and then we also come to digit10s--; again. That decrement digit10s by one again so now digit10s is equal to 4. This block is run 6 times (which flashes the LED 6 times). Why 6? Because digit10s was equal to 6, remember? Now, if we run the digit10s--; 6 times, that subtracts 6 from digit10s. That leaves digit10s equal to 0.

But what stops the block after it's gone through 6 times? Well if we look back we will see the operation being tested.

while(digit10s != 0) // while digit10s is NOT equal to 0, run the code below over and over.

It's saying run the block over and over while digit10s is NOT equal to zero. But now digit10s IS equal to 0! So that block is stopped and the Arduino moves onto the next block of code.

Step 11: Conclusion

I hope you enjoyed my project please PM me or comment if you have any questions, comments or suggestions. 
If you make one,  please let me know how it worked!



r5sb (author)2013-11-29

Nice Instructable! Completed mine today...used the button to put the pin to LOW instead of HIGH though...skipped using a pull up resistor this way.

HavocRC (author)r5sb2013-11-29

Dude that's awesome! Thanks for posting the pic! What did you do with the resistor? You connected the pin from 5v directly to the ATtiny pin?

r5sb (author)HavocRC2013-11-29 when the button is pressed the pin goes low.

HavocRC (author)r5sb2013-12-02

Nice, that makes sense, since you ground the pin. Thanks!

mrmerino (author)2013-11-15

Could I make it so that it blinks at me in binary? And in Celsius?

HavocRC (author)mrmerino2013-11-15

Why not?

HavocRC (author)HavocRC2013-11-15

To have it print out C˚ just take out the F˚ conversion.

Computothought (author)2013-11-02

Was kind of confused about the schematic.The rj45 threw me for a loop. Being not too smart in these things, I made my own diagram. Not sure if it is riight though/

HavocRC (author)Computothought2013-11-05

The RJ45 is just a name. I forgot to change it. Instead it should be ATtiny85. The pins are still the same. I think yours is correct.

Computothought (author)HavocRC2013-11-07


jrburke99 (author)2013-10-31

I made my own such device recently, but it uses an IR LED to blink a warning single at me via an IR camera in my son's bedroom if it gets too hot or too cold. It also has a red LED that blinks out the temperature just as yours does. But I think my code simplifies the process a bit. You should try this out. Also, you should be able to run all of this off of a 3v button cell, saving you even more space and weight. Just make sure you look up the sleep functions for the ATtiny, and use it as much as possible. In my code, the "SleepyTime" function puts the MCU to sleep for a period of time (32=32ms, 5=.5seconds). For your device, you could easily make it sleep constantly, checking for a button press periodically. For example, sleep in .5 second intervals, checking for a button press in between. 

TensDigit = (int)Temperature / 10;  // Split the number up into 2 digits
OnesDigit = (int)Temperature % 10;

      if (TensDigit != 0) {
        for (int i=1; i<=TensDigit; i++) {  // Blink LED # times for tens digit
          digitalWrite(STATUSLEDPIN, HIGH);
          digitalWrite(STATUSLEDPIN, LOW);

      SleepyTime(1);  // Pause between the 2 digits

      if (OnesDigit != 0) {
        for (int i=1; i<=OnesDigit; i++) {  // Blink LED # times for ones digit
          digitalWrite(STATUSLEDPIN, HIGH);
          digitalWrite(STATUSLEDPIN, LOW);

HavocRC (author)jrburke992013-10-31

JrBurk thank you soo much I couldn't figure out how to make the 10s digit blink and the 1s. I asked a question in the forum but it wasn't answered so I turned to my own poor devices :D.

So I don't really understand what you are doing with the 10's and 1's digit would you please explain?

Ok so the sleeping time saves some power?

Yes I was gonna run it off 3v battery but I didn't have any around :(. No job, no money, lack of electronics.

Thanks I will be eagerly awaiting a reply.

traisjames (author)HavocRC2013-11-03
I was thinking the same thing as jrburke99. In the code

TensDigit = (int)Temperature / 10; // Split the number up into 2 digits
OnesDigit = (int)Temperature % 10;

you need to know that % means mod or remainder, and (int)Temperature means that whatever the Temperature / 10 gives, make an integer with no decimal point.

In your video your thermometer reads 69°. In the first line a rolling solve would look like this:
•TensDigit = (int)Temperature / 10; //Start
•TensDigit = (int)69 / 10; //Fill Temperature with 69
•TensDigit = (int)6.9; //Divide 69 by 10, giving you 6.9, which is a double (has a tenths digit (9)
•TensDigit = 6; //Convert double to int, which does not have anything to the right of the decimal point

The second line is a bit more fun. Let's roll that:

•OnesDigit = (int)Temperature % 10; //Start
•OnesDigit = (int)69 % 10; //Fill Temperature with 69 OnesDigit = (int)9; //when you do that long form math from elementary school and your answer here would be 69÷10= 60 with a remainder of 9
•OnesDigit = 9; //Convert to an integer.

I have taught coding before and Modulo (mod in some languages, % in others

If you are not conferrable with Modulo, it works the same way as this:
•OnesDigit = Temperature-TensDigit*10; //Start
Which goes:
•OnesDigit = 69-6*10; //Fill in the numbers
•OnesDigit = 9; //Solve, using order of operations

Either way you now have TensDigit = 6 and OnesDigit = 9.
HavocRC (author)traisjames2013-11-03

Basically I don't know how to easily know how to say in code, "Flash LED (10s digit) times" without adding delays. Then when I add delays then that means I have to specifically make a block for each number.

traisjames (author)HavocRC2013-11-03

Instead of saying "Flash LED (10s digit) times", you want to say "Flash LED once 10s digit times". Thats where this block comes in:

for (int i=1; i<=TensDigit; i++) {  // Blink LED # times for tens digit
   digitalWrite(STATUSLEDPIN, HIGH);
   digitalWrite(STATUSLEDPIN, LOW);

This section of code is one blink:

digitalWrite(STATUSLEDPIN, LOW);

Now to do that 6 times for 69°, we just do a loop.  This line is the loop:
for (int i=1; i<=TensDigit; i++)   // Blink LED # times for tens digit.  There is also an open and close { } for the code that repeats.

In english this says "Let's repeat some code a few times.  Let's make a counter we will label i, and set it to 1; We will repeat as long as i is less than or equal to the number in the TensDigit variable; and last every time we get to the bottom of the loop let's add 1 to i.

for (int i=1; i<=6; i++){
   print i;  //pretend code to demonstrate

gives us the result of

print i prints the i variable once.  We just call it 6 times, and each time it runs i is different.

Our good friend has some info on loops.

If your new to programming I would suggest going to  This is to learn Javascript which is similar in Syntax to what Arduino uses.  While you are learning a different language it will teach you to think like a programmer and immediately recognize, hey i want to do a For Loop here or a Do Loop there.

HavocRC (author)traisjames2013-11-04

Can I replace the sleepy time with a delay?

Thanks a lot I will see if I can't figure it out.

traisjames (author)HavocRC2013-11-04

Delay() would work. SleepyTime is not a built in function but instead one that jrburke99 made (code at which not only does a delay but also powers down much of the chip to save power.

HavocRC (author)traisjames2013-11-04

Right. Well thank you for explaining that code I will work on a new code for this soon. Thanks!

HavocRC (author)traisjames2013-11-03

Thank you I looked up modulo and I had my dad explain it to me. I understand now how that works. I'm still having trouble coding. I can get the temp split into 10ths and 1nes but I can figure out how to get the the LED to flash several times without still going through a bunch of if statements 1-9.

Edgar (author)2013-11-04

Nice! These pulses could power an analogue counter, of sorts... Small disks with Digits on them, like those on old Pinball machines, but lots smaller.
Voted, and Blogged about it:

Edgar (author)2013-11-04

Nice! :)
Voted, and also Blogged about it, too useful to pass un-noticed:

Creeper37757 (author)2013-11-02

What if the temperature was to 100 degrees Fahrenheit?

HavocRC (author)Creeper377572013-11-02

You could make both LEDs flash very fast if you wanted to! I just didn't do that because it doesn't get 100 where I live. If it goes below 0 degrees you could have the LEDs flash slowly. Just a few simple if statements.

maggiemcfee (author)HavocRC2013-11-03

Or just make the first LED blink 10 times. As long as there's a clear pause between 1st and 2nd LED it should be easy to tell. Ten in a row, it's 100. Ten in a row, pause, 1 and it's 101.

HavocRC (author)maggiemcfee2013-11-03


halamka (author)2013-11-03

- yintercept -- The most difficult, fundamental digital computer loop is binary division. I figure that a memory string is needed to store the BASIC commands. With a loop of course. ENTER becomes a BASIC entity. FORTRAN computers of the 1970's were actually more sophisticated with numbers. Note that Microsoft computers had 4 original partners.

halamka (author)2013-11-03

Scale factor = X , atd / x = int , if int < > then flash . It may be that Bill gates / paul allen is drawing attention away from microprocessors. I just got a large computer monitor. I have 20 mhz z80 chips that can load a single screen in 480x240/20,000,000 = .006 seconds from memory. The Commodore 64 computer could always instantly fill the screen from memory.

halamka (author)2013-11-03

I have been ignoring arduino because it seems to fall into a category of microsoft nonsense. What is the 8 pin chip? Is it secret so asian factiory workers can go home?

HavocRC (author)halamka2013-11-03


elektrikpco (author)2013-11-02

Hi. If you did this project with Dallas DS18b20 temperature sensor - it could power just a CR2032 tablet battery (3 Volt) and will be small. Attiny 45/85 exellent work with 3 Volt. Flash of tiny 85 will be enough for program on IDE Arduino with all needed lib

HavocRC (author)elektrikpco2013-11-03

True. I had a LM35 and wanted to use it. A 9v battery is also more convenient.

manuka (author)2013-11-03

Much the same approach, but with simpler code, can be done using a high level PICAXE-08M. On the compact Celsius scale I used longer flashes for tens, & shorter for units. Hence 24 Celsius = 2 longs then 4 shorts. Sub zero could also be organised, but it rarely gets that cold here (Wellington, New Zealand)!  For the sensor a DS18B20 is preferred, but even a cheap thermistor may do. Refer details =>

HavocRC (author)manuka2013-11-03

Hey thanks for the suggestion but I am trying to stick with Arduino and it's language.
That's a really good idea! Long, then short.

dmoore75 (author)2013-11-02

Could you use a for/next block to scan through temperature ranges instead of using case statements? No experience with AT Tiny, but it's supported in Arduino IDE. This should help to reduce your code size and give more accurate readings.

HavocRC (author)dmoore752013-11-03

I'm not sure what you mean by more accurate because it doesn't matter how I go through the temperatures it's gonna be the same whether I use if statements, cases or whatever. I don't know how to use a for/next block. If you'd like to to make a new sketch I that would be awesome! Yeah, that would reduce the code size and be easier. Like I said in the beginning, I didn't really know how to do this. The code I made was made from a beginner.

Creeper37757 (author)2013-11-02


carlos66ba (author)2013-10-31

Nice/ You could use 3 AAA batteries (does not take much more space than a 9V) and skip the voltage regulator.

HavocRC (author)carlos66ba2013-11-01

Yup I just don't have that :D

jrburke99 (author)2013-11-01

Here is a post I made on the Arduino forums with all of the details and my code, etc. Hope this helps you out!

HavocRC (author)jrburke992013-11-01

Thanks I have checked it and am trying to figure some things out.

jrburke99 (author)2013-11-01

To print to a terminal window, look into the Serial commands on the Arduino site.

So "TensDigit" and "OnesDigit" are integers, so no decimals. If you take your temperature (let's say 87.3) and divide by 10, storing the result into an integer, you will get 8. So that parses out the 10's digit of your temperature. Using the "Temp % 10" operation will divide by 10, and then return the remainder. So 87 % 10 will result in a 7.

HavocRC (author)jrburke992013-11-01

Hey Burk thank you so much! I had to look up modulo and get my Dad to tell me what it did and now I understand. That's a crazy smart idea. Thanks a lot I'll be working on a newer code :D.

jrburke99 (author)2013-10-31

Also, try using an ATtiny 85v, which works exactly the same, but uses less power. With a button cell, you won't need the voltage regulator bits. Also, analog temp devices can give readings all over the place. Try making a loop where it reads in a temp and prints it out to the terminal window. You will see how it can have spikes and odd readings. I originally tried using analog, but went with digital instead, as it had much steadier readings. But if you want to stick with the analog for ease of use, try having it loop and take, say 100 readings in a row and stick them into an array. Then toss out the highest 10 and lowest 10 readings (or whatever you think is best), and then average the rest. I tried that and got much steadier/accurate readings. It's a good way to learn some new programming skills, too! Have fun!

HavocRC (author)jrburke992013-10-31

That sounds really cool but my programming skills aren't that good :(.

Print it out to a terminal window?

About This Instructable




Bio: 19 year old hobbyiest and future EE.
More by HavocRC:DIY FPV Antenna Protector CaseControl Your RC Plane With Your Phone's AcclerometerDIY Receiver Controlled Switch (Cheap and Easy)
Add instructable to: