Introduction: Arduino Digital 7-Segment Thermometer

Hello everybody! I will be showing you how to make a digital 7-segment thermometer using the LM335 temperature sensor.

This a guide for an Arduino version, but I am working on a mini ATtiny84 version. Once I get that working, I will post another Instructable on how to make it.

I'm sure you could make this same thermometer with an LM35 also, if that's what you have, and you probably won't have to modify the code.

This is an entry in both the LED contest with Elemental LED and the Hurricane Lasers contest, so if you like it, vote for it! Thanks!

Also, I am considering starting an electronics kit business to sell kits for the Instructables that I make, so if you like the idea, drop a comment or PM me!

Step 1: Parts List

Here are the things you will need for this project. You can get all these parts from a wholesale supplier like Mouser or Digi-Key for around $10-$15 or less, except for the Arduino board. You can get this from Mouser for around $30.

Parts:
1x Arduino Uno/Duemilanove/maybe Diecimila or equivalent
1x LM335 temperature sensor (I'm sure you could make it work with a LM35 too)
2x Single digit 7-segment display, common cathode (or a single 2 digit one)
1x 2.2k ohm resistor (not sure if you need this if you are using an LM35)
Jumper wires

Tools:
USB A-B cable
Breadboard

Step 2: Program the Arduino

The code I wrote requires you to have the Arduino Seven Segment library installed. To do this, go here and download all the files by going to "File>Download" at the top of the page.

Then locate you Arduino sketchbook folder (should be located in "Documents>Arduino" on Windows) and create a folder called "hardware" if there isn't already one. Go in that folder, and paste the folder you downloaded before into the "hardware" folder.

It should not be in a .zip or .rar format, which it will most likely come as when you download it, you must extract the entire folder and place it in the hardware folder.


After you installed the library, upload the code below to the Arduino board, and proceed to the next step.


#include "SevSeg.h"

SevSeg sevseg;

int tempUnits = fahrenheit; //which unit of temperature do you prefer?

int refreshTime = 5000; //how many seconds should it wait before it checks and displays the temp again? 1000 = 1 second

unsigned long timer;
float celsius = 0, kelvin = 0, fahrenheit = 0;

void setup()
{
  sevseg.Begin(0,2,3,4,5,6,7,8,9,10,11,12,13);
}

void loop()
{
  sevseg.PrintOutput();
 
  //Reads the input and converts it to Kelvin degrees
  kelvin = analogRead(0) * 0.004882812 * 100;
 
  //Converts Kelvin to Celsius minus 2.5 degrees error
  celsius = kelvin - 2.5 - 273.15;
 
  //Converts Celsius to Fahrenheit minus 2.5 degrees error
  fahrenheit = ((kelvin - 2.5) * 9 / 5) - 459.67;
   
  unsigned long mils=millis();
  if (mils-timer>=refreshTime) {
    timer=mils;
    //Print teperature to the displays
  sevseg.NewNum(tempUnits,(byte) 2);
  }
}

Step 3: Modify the Code to Use a Common Anode Display (optional)

Changing the code to work with a common anode display is simple. Change this line of code:

sevseg.Begin(0,2,3,4,5,6,7,8,9,10,11,12,13);

to:

sevseg.Begin(1,2,3,4,5,6,7,8,9,10,11,12,13);

Step 4: Change the Units and Refresh Time (optional)

To change the units of the temperature displayed to Celsius or back to Fahrenheit, change the line of code at the top that says:

int tempUnits = fahrenheit;

to:

int tempUnits = celsius;

if you prefer Celsius.

To change the rate at which the display updates the temperature, change the line of code at the top that says:

int refreshTime = 5000;

to:

int refreshTime = <however many seconds you want it to wait before updating * 1000>;

The code is set to refresh every 5 seconds by default. If you put a number that is too low, it will update so fast that you won't be able to read it.

Step 5: Put It Together!

Here is the schematic for the thermometer. I made mine on a breadboard.

Step 6: Done!

Plug it in and it should display the temperature in Fahrenheit or Celsius, depending on which unit you chose.

Done!

Comments

author
salexandridis (author)2013-07-14

It seems that Mr/Mrs xBacon is unwilling to answer any question related to this instructable. He/She obviously doesn't even read the comments....or his/her inbox! So, that's why I undertook to search and evntually find the solution to the 'Zeros Problem" ! Here's the CORRECT, 100% WORKING code:

#include "SevSeg.h"

SevSeg sevseg;

int refreshTime = 2000; //how many seconds should it wait before it checks and displays the temp again? 1000 = 1 second

unsigned long timer;
float celsius = 0, kelvin = 0, fahrenheit = 0;

void setup()
{
sevseg.Begin(0,2,3,4,5,6,7,8,9,10,11,12,13);
}

void loop()
{
sevseg.PrintOutput();

//Reads the input and converts it to Kelvin degrees
kelvin = analogRead(0) * 0.004882812 * 100;

//Converts Kelvin to Celsius minus 2.5 degrees error
celsius = kelvin - 2.5 - 273.15;

//Converts Kelvin to Fahrenheit minus 2.5 degrees error
fahrenheit = ((kelvin - 2.5) * 9 / 5) - 459.67;

unsigned long mils=millis();
if (mils-timer>=refreshTime) {
timer=mils;
//Print teperature to the displays
sevseg.NewNum(celsius,(byte) 2);
}
}

If you want to change the unit of temperature, all you have to do is to change the last command: sevseg.NewNum(celsius,(byte) 2);
Instead of "celsius", you can type "fahrenheit" or "kelvin". It seems that all this "tempUnits" thing doesn't work, so I totally excluded it from the code.
You may also change the delay by following the steps of this instructabe.
Have fun!

author
alexm474 (author)salexandridis2017-08-21

Thanks for the code, its working .

Can you please tell how can i make it 3 digit, like 30.5 celcius

But in this code, the output of kelvin and Celsius is reversed.

author
gmally (author)salexandridis2015-04-20

is it possible to display the readings on serail as well as on the LED Dsiplay?

I've tried but I can only get one or the other but not both.

author
FabioNovaski made it! (author)2017-08-14

After some adjustments, it works!

20864392_1853218558083074_2062635580_n.jpg
author
KoKoY2 made it! (author)2017-04-26

I made it with LM35 and thank you! but the code did not work.SevSeg.h header file is now updated and i downloaded the old version.If not the old version, it will not verify and upload.I edited some....

#include "SevSeg.h"

SevSeg sevseg;

unsigned long timer;
float celsius = 0;
int refreshTime = 5000; //how many seconds should it wait before it checks and displays the temp again? 1000 = 1 second

void setup()
{
sevseg.Begin(0,2,3,4,5,6,7,8,9,10,11,12,13);
}

void loop()
{
sevseg.PrintOutput();
celsius = analogRead(0);
float mv = ( celsius/1024.0)*5000;
float cel = mv/10;

unsigned long mils=millis();
if (mils-timer>=refreshTime) {
timer=mils;
//Print teperature to the displays
sevseg.NewNum(cel,(byte) 2);
}
}

thank u ...

IMG_20170427_105134.jpg
author
AgileMind (author)2017-03-25

Please help. I unable to compile the above code an I don't have SevSeg.h file.

author
EdunY (author)2017-03-18

Hey There !! Nice Tutorial, Please Send Code to edunhenry@yahoo.com, Thanks :)

author
Vitor Reppen (author)2015-06-17

Ok I modify some things on the code and got it work on a LM35, If anyone want the code just reply this comment and I let you know.

Great job in this project, thank you. Helped a lot!

author

Hello, can you please send me the code?

author

hello. I used your lm35 modified code in a larger project sוrrouding the lm35, I wanted to ask for an explanation of every line in the code to help me understand it better.(i'm a student it is for my final project) leshetzlee@gmail.com

author
RDP_1210 (author)Vitor Reppen2016-03-17

I need code rpd1210@gmail.com

author
AnoopS7 (author)Vitor Reppen2015-10-28

i need code

saxenanoop@gmail.com

author
gowri (author)Vitor Reppen2015-09-20

will you please to help he.i have LM35 . can you sent the code to me

author
Vitor Reppen (author)gowri2015-09-20

Read the comment i send to @SaironN, theres the code.

author
SaironN (author)Vitor Reppen2015-06-18

I want to know please!!
vih_neta@hotmail.com

author
Vitor Reppen (author)SaironN2015-06-19

I don't send by email, but I let you know here :D

#include "SevSeg.h"

SevSeg sevseg;

int refreshTime = 2000; //how many seconds should it wait before it checks and displays the temp again? 1000 = 1 second

unsigned long timer;
float celsius = 0, kelvin = 0, fahrenheit = 0;

void setup()
{
sevseg.Begin(1,2,3,4,5,6,7,8,9,10,11,12,13);
}

void loop()
{
sevseg.PrintOutput();

//LM35 code to display celsius
celsius = (5.0 * analogRead(0) * 100.0) / 1024;

unsigned long mils=millis();
if (mils-timer>=refreshTime) {
timer=mils;
//Print teperature to the displays
sevseg.NewNum(celsius,(byte) 2);
}
}

Thanks to :

salexandridis

xBacon

author
Satele made it! (author)2016-11-26

Took me a while to know how this is done but it was mostly adding the library the author included on the libraries folder and wiring it as the diagram says.

Using this as my 5th semester final project on the 2nd submodule.. Wish me luck!

15209148_984599134985396_1582301558_n.jpg15209227_984592901652686_574160403_n.jpg
author
natural-HARI (author)2016-08-25

i want to use a 3 digit 7 seg display instead of 2 digits . what is the code for it?

author
xarabalios (author)2016-06-05

Hi.i 'd like if someone help me to modify the code so it can mesure temperatures from -20 to any other.
Thank you in advance.

author
shinfeng made it! (author)2016-04-17

hello i try many time but still hv problem for uploading this code

7 SEGMENT code.JPG
author
shinfeng (author)2016-04-17

hello may i know why serial.begin(1,2,3,4,5,6,7,8,9,10,11,12,13);totally hv 13pin? because what i know is 2digit + A to dot just only need 10pin, can u please explain for more detail thank you.

author
RDP_1210 (author)2016-03-17

The code won't let me upload to my arduino because its saying Fahrenheit isn't defined in this scope. How should I fix this?

author
ozuniga1980 (author)2015-04-03

no works sorry bad code

author
Arpan2103 (author)ozuniga19802016-01-04

Same Here..

author
PepeR1 (author)2015-08-11

author
Diannes3 (author)2015-07-06

I want this, send to me please dianneschuur@gmail.com

author
Vitor Reppen (author)2015-06-19

Oh and thanks to

salexandridis for the code, I only modify a few things from that code to work on lm35

author
iamakidilam (author)2015-05-20

does this work? i'm having a common cathode display

author
MokshJadhav (author)2015-05-10

@salexandridis has made the proper code. Check my instructable(PING with 2 LED seven segment displays) for the proper diagram if you have any difficulties in assembling the project.

author
gmally (author)2015-04-20

is it possible to display the readings on serail as well as on the LED Dsiplay?

I've tried but I can only get one or the other but not both.

author
enhatem (author)2014-12-24

Shouldn't there be resistors connect for each LED in the 7-Segment Display ?

author
ahmeds7 (author)2014-11-10

thank you

author
ggomes3 (author)2014-06-05

ythghgd

author
jameeljoker (author)2013-04-14

how exactly do i wire all this up? the image is blurry and i really dont get the schematic. Can anyone please help??

author
mkor68 (author)2013-03-24

Love the simplicity of your project. I'm trying to make this work but it only gives zeros. The wiring is correct. Is the sketch missing something?
Thx.

author
salexandridis (author)2013-03-09

I get the 0s too. There are no problems in wiring and I'm using the LM335.

author
yzheng (author)2013-02-13

professorred

did you use this wiring diagram?
http://mysite.du.edu/~etuttle/electron/circ186.gif

author
yzheng (author)2013-02-12

if i want to add a 3rd digit 7 segment, the common cathode is connected to D3?

more importantly, will you be selling/making ready-made pcbs? it would be alot easier than buying a prototyping board and using crude solder traces.

author
tbagain ü (author)2013-01-28

Hi! I've tried doing this. It seems I wired everything correctly. However, it displays "00." I'm using a LM335 temp sensor with common cathode 7-segment as you've done in your demonstration. Is this a problem with the sensor? do I need to calibrate it? thanks!

author
marcusone (author)2013-01-19

Can it work with individual 7-seg displays?

author
soccer2291 (author)2013-01-02

Is there supposed to be seven series resistors in line with each segment on the display?

author
nharun1 (author)2012-10-07

can it work with 3 digit 7-segment?? thanks in advance.

author
xBacon (author)nharun12012-10-07

Yes, it can work with that. Since the 3 digit is already multiplexed, you just connect the segment pins to the arduino, and the first 2 digit pins to the arduino. It should work then.

author
professorred (author)2012-09-08

Hi. No matter how I set up the LM35, I am getting a result of 00. I am not sure what is going on. Thank you.

author
xBacon (author)professorred2012-09-09

you must use the LM335, not the LM35.

author
professorred (author)xBacon2012-09-09

Ah. I was wondering because of the line in the parts list that mentioned that it should work with the LM35 but thank you. :)

author
xBacon (author)professorred2012-09-09

well, it should work if you connect the lm35 in the correct way. the connections are different for the lm35 and he lm335. try going on google and searching "lm35 arduino" and you should come up with a circuit diagram. just follow the diagram and connect it to the analog input used in the sketch.

author
professorred (author)2012-09-04

Hi. I copied and pasted the code to my arduino program and when I hit verify, it came up with an error saying Fahrenheit was not declared in this scope. Please help. Thank you.

author
xBacon (author)professorred2012-09-04

Try moving the line:

int tempUnits = fahrenheit;

to under the line that says:

float celsius = 0, kelvin = 0, fahrenheit = 0;

Tell me if this works.

author
professorred (author)xBacon2012-09-05

Thank you much. That worked like a charm. Now to build it. Thanks again.

About This Instructable

80,243views

62favorites

License:

Bio: I'm a big Arduino fan. I'm always looking for new and exciting things to do with electronics and Arduino. I also like video ... More »
More by xBacon:DIY Infrared Proximity Sensor (Arduino Compatible)Color Changing LED TreePlug-in LED Color Fading Night Light
Add instructable to: