In this project I’ll display the temperature in a 4 digit 7 segment display (common anode).
The sensor is the cheapest you can find so actually the temperature changes pretty easily which makes the display to show always different temperatures. But the idea is to apply this code to other projects with 7 segment displays that I might do later. if you want to learn a bit more of 7 segment displays you can read more at this post I've made.

This project is great to learn more about:
  • Reading sensors (in this case temperature)
  • 7 segment displays (4 digit 7 segment displays)
  • 8 bit Shift Registers (74HC595)
  • Pratice wiring
and for more project and tips you can also check my website:
You can see this project working right now:

Step 1: Parts Required

  • 1x Arduino Uno
  • 1x Temperature Sensor (I’m using the LM335Z)
  • 1x 4 Digit 7 Segment Display (common anode)
  • 1x 74HC595 8 Bit Shift Register
  • 8x 220 Ohm Resistors
  • 1x 4700 ohm Resistor
  • 1x Breadboard (or  two)
  • Jumper Cables
<p>is it ok i will use lm 35 temperature sensor?</p>
<p>The one used in this tutorial is a LM35 so you're good I think :P ( I'm pretty sure).</p>
<p>and can anyone send me the schematics for the (common cathode) display ? please.</p>
<p>will this work with mega 2560 ?</p>
<p>Excellent project! Is there anyway to get it to read negative temps. I'm trying to with the DS18B20 but cannot seem to get the code to work right. I removed the 100's place to just a 10's decimal like 20.2 instead of 20.22 to make the left most digit for minus sign. Also, is there a way to drop the leading zero on the left digit? It now comes up as 020.2 or 002.2 . Many thanks!</p>
<p>Thank you for the tutorial! I assembled it and it worked the first time using the schematic in the comments section and code. It was just what I was looking for: a tutorial using the 74HC595 and temperature sensor. </p>
<p>Hi, thanks for the tutorial. My 4 Bit 7-Segment display has a total of 12 pins. What configuration changes take place to replace the 7-segment display shown with the 7-segment display I currently have?</p>
<p>you need to map out your pins to see what they each trigger</p>
<p>Many thanks for this project, it was very useful to sort this out !</p><p>I've done it with a 12 pins 4 digits 7 segments display, I have changed the latch, data and clock pin as well, as I was already using the other pins in my project. For those interested clock pin is 7, latch is 8, data is 12 ; digit 1 to 4 is between 2 and 5 and segment A to DP are on the 74HC595 output QA to QH.</p><p>Thanks again !</p>
<p>Hi. Nice project. Im very beginner for arduino. <br>Could you post circuit diagram of your project?</p>
What if I'm using a common cathode 4 digit 7 segment? Does it changes the cirtuit/code very bad?
yeah it actually changes the code and the circuit a bit... but it's totally possible! <br>if you make a quick search you'll see the difference and what you have to change. <br> <br>I hope this helps! thanks for commenting!
I have managed to do it! Take a look at my code:<br> /*<br> * created by Rui Santos, http://randomnerdtutorials.com<br> * ALTERED BY: Raphango<br> * Temperature Sensor Displayed on 4 Digit 7 segment common CATHODE<br> * 2013<br> */<br> const int digitPins[4] = {7,6,5,4}; //4 common CATHODE pins of the display (inverted the pins order)<br> const int clockPin = 11;&nbsp;&nbsp;&nbsp; //74HC595 Pin 11<br> const int latchPin = 12;&nbsp;&nbsp;&nbsp; //74HC595 Pin 12<br> const int dataPin = 13;&nbsp;&nbsp;&nbsp;&nbsp; //74HC595 Pin 14<br> const int tempPin = A0;&nbsp;&nbsp;&nbsp;&nbsp; //temperature sensor pin<br> const byte digit[10] =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //seven segment digits in bits<br> {<br> &nbsp; B00111111, //0<br> &nbsp; B00000110, //1<br> &nbsp; B01011011, //2<br> &nbsp; B01001111, //3<br> &nbsp; B01100110, //4<br> &nbsp; B01101101, //5<br> &nbsp; B01111101, //6<br> &nbsp; B00000111, //7<br> &nbsp; B01111111, //8<br> &nbsp; B01101111&nbsp; //9<br> };<br> int digitBuffer[4] = {0};<br> int digitScan = 0;<br> float tempC; //Deleted kelvin and farenheit<br> <br> void setup(){&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br> &nbsp; for(int i=0;i&lt;4;i++)<br> &nbsp; {<br> &nbsp;&nbsp;&nbsp; pinMode(digitPins[i],OUTPUT);<br> &nbsp; }<br> &nbsp; pinMode(tempPin, INPUT);<br> &nbsp; pinMode(latchPin, OUTPUT);<br> &nbsp; pinMode(clockPin, OUTPUT);<br> &nbsp; pinMode(dataPin, OUTPUT);&nbsp;<br> &nbsp; pinMode(tempPin, INPUT);<br> &nbsp; //Serial.begin(9600);<br> }<br> <br> //writes the temperature on display<br> void updateDisp(){<br> &nbsp;&nbsp;<br> &nbsp; for(byte j=0; j&lt;4; j++) {digitalWrite(digitPins[j], HIGH);} // Turns the display off. Changed to HIGH<br> &nbsp; digitalWrite(latchPin, LOW);&nbsp;<br> &nbsp; shiftOut(dataPin, clockPin, MSBFIRST, B00000000);<br> &nbsp; digitalWrite(latchPin, HIGH);<br> <br> &nbsp; delayMicroseconds(2);<br> <br> &nbsp; digitalWrite(digitPins[digitScan], LOW); //Changed to LOW for turning the leds on.<br> <br> &nbsp; digitalWrite(latchPin, LOW);&nbsp;<br> &nbsp; if(digitScan==2)<br> &nbsp;&nbsp;&nbsp; shiftOut(dataPin, clockPin, MSBFIRST, (digit[digitBuffer[digitScan]] | B10000000)); //print the decimal point on the 3rd digit<br> &nbsp; else<br> &nbsp;&nbsp;&nbsp; shiftOut(dataPin, clockPin, MSBFIRST, digit[digitBuffer[digitScan]]);<br> <br> &nbsp; digitalWrite(latchPin, HIGH);<br> <br> &nbsp; digitScan++;<br> &nbsp; if(digitScan&gt;3) digitScan=0;<br> }<br> <br> <br> void loop(){<br> &nbsp; tempC = analogRead(tempPin)*0.00488; &nbsp;//multiplied for this conversion constant<br> &nbsp; tempC = tempC*10000;<br> &nbsp; digitBuffer[3] = int(tempC)/1000;<br> &nbsp; digitBuffer[2] = (int(tempC)%1000)/100;<br> &nbsp; digitBuffer[1] = (int(tempC)%100)/10;<br> &nbsp; digitBuffer[0] = (int(tempC)%100)%10;<br> if (digitBuffer[0]&gt;=5) {<br> digitBuffer[0] = 5;<br> }<br> else {<br> digitBuffer[0] = 0;<br> }<br> delay(4);<br> &nbsp; updateDisp();<br> &nbsp;<br> }<br> <br> <br> ###########################<br> Here's a video too:<br> <div> <iframe frameborder="0" height="315" src="//www.youtube.com/embed/Rn1q_rj7RLg" width="420"></iframe></div> Do you have already discovered how to smooth the transitions of showed temperature? Its quite annoying to see that glittering all the time....<br> <div> &nbsp;</div>
<p>Good day, I cannot figure out how to get it to work with a common cathode. Can you help me with the alterations you did to the circuit to get it ot work with your code??</p>
Awesome! thanks for trying my project... <br>I'm sorry I had a few issues with that code... and I don't know why I couldn't figure out how to smooth the transitions. but I agree with you... it's a bit annoying. In the meanwhile I've started some new projects and I've never had time again to upgrade that code... :( <br> <br>Thanks again for trying my project. <br>Can I post it on my website? <br>(on this page: http://randomnerdtutorials.com/feedback)
Of course!<br>Feel free to use it.<br><br>About the flickering, I did some changes to the &quot;delay&quot; values, but all it does is lighting up one of the 4 digits each time at an eye perceivable speed.<br><br>What I thought about doing was slowing the &quot;update&quot; rate, but unsuccesfully, since I'm a begginer in the shiftOut thing... =P<br><br>Thanks again!<br>
<p>Very cool project!</p><p>try building the circuit with <a href="http://circuito.io" rel="nofollow">circuito.io</a> - you'll get a detailed schematic and code.</p>
<p>just to clear things out :</p><p>segments pins pinout :</p><p>74hc595 -- 7 segments</p><p>15 = a</p><p>1 = b</p><p>2 = c</p><p>3 = d</p><p>4 = e</p><p>5 = f</p><p>6 = g</p>
<p>ei elemento , tu desenhou errado , e quase estragou o projeto aqui pivete , se liga viu </p>
<p>very nice project. How do I get it to work on a 3digit 7 segment common cathode? thank you</p>
sir, what the code if i use lm 35?
I think my code will work for lm35... but i don't have time to write the code for you... <br>I'm sorry, I receive to many requests. <br>Good luck with your project!
What a good work!

About This Instructable




Bio: Author, Blogger, Electronics Enthusiast and Entrepreneur. For complete Electronics Projects and Tutorials go to: http://randomnerdtutorials.com/start-here
More by RuiSantos:ESP8266 Web Server (Without Arduino) Arduino Simple Memory Game Arduino – Datalogger with Temperature Sensor and Photoresistor 
Add instructable to: