Arduino Digital 7-Segment Thermometer

84,196

65

51

Posted in TechnologyArduino

Introduction: Arduino Digital 7-Segment Thermometer

About: 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 gaming on my PC and Xbox. I also ride my bike almost every day, and sometimes swim/...

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!

4 People Made This Project!

Recommendations

  • Microcontroller Contest

    Microcontroller Contest
  • Woodworking Contest

    Woodworking Contest
  • Casting Contest

    Casting Contest
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

51 Comments

Tienes que optimizar el código ...

29497945_1837506659627573_105419946510516224_n.jpg29511532_1837506599627579_1981145903997648896_n.jpg

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!

2 replies

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.

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.

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

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

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!

8 replies

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

I need code rpd1210@gmail.com

i need code

saxenanoop@gmail.com

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

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

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

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

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

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.

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.

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?