Introduction: Temperature Displayed on 4 Digit 7 Segment (common Anode)

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:
http://randomnerdtutorials.com/
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

Step 2: Schematics

I think it's a bit hard to follow the yellow connections with this schematic.
So i recommend that you take a look at the 74HC595 pins and to the internal circuit diagram of the 4 digit 7 segment display (common anode).
So how does the yellow connections were made?
Basically  the pin 11 connects to the QA, the pin 7 to the QB and so one…

Step 3: Upload the Code

You can find the code here: https://gist.github.com/ruisantos16/5419223

Step 4: Final Product

Check this video to see the circuit in action!
you can also visit my website for more electronic projects, interesting news and tips


T
hanks for reading!
And make sure you follow me so you can be notified when I release my new projects! 

Comments

author
nodoubtman (author)2015-12-24

just to clear things out :

segments pins pinout :

74hc595 -- 7 segments

15 = a

1 = b

2 = c

3 = d

4 = e

5 = f

6 = g

author
Plongkie (author)nodoubtman2017-07-28

Hi, Im still a beginner at this but I find your comment a lot clearer than the schematic Im following, but Im still in the process of clearing things out, I hope you could help me where to connect the skyblue wires in the 7segment display.. Thank you so much!

author
lenovog4 (author)2017-05-23

Hello,

first of all, great work! this was the first tutorials that actually worked for me.

i just have a small question: is it possible, to set the display let say "1234" in the setup and leave it like that, without refreshing in every loop? In my project I'm using a ultrasonic sensor parallel to the segment display and the delays cause some trouble(the segment display isn't refreshing fast enough).

mabye you have an idea to solve such a problem.

thanks in advance and keep up the good work ;)

author
TahaA29 (author)lenovog42017-06-15

if you input any piece of code in the void setup(){} area of code it runs it on a single static system. This means it will only run it once, and the code won't refresh as setup() is not a loop system.

author
julowsky (author)2015-07-25

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?

author
taubin1 (author)julowsky2015-09-18

you need to map out your pins to see what they each trigger

author
ghismo made it! (author)taubin12016-12-14

Many thanks for this project, it was very useful to sort this out !

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.

Thanks again !

FourDigitsSevenSegments74HC595_bb.png
author
Christopher IanR (author)ghismo2017-05-14

Sir do i have to change the code? i tried your diagram and the code above but it doesnt work fine

author
SaifulK2 (author)2017-02-16

How can I do this same project but using the atmega328p on a breadboard and using a c programming language..any tutorial links will be greatly appreciate..ty..

author
LloydP6 (author)2017-02-04

is it ok i will use lm 35 temperature sensor?

author
spock.legend (author)LloydP62017-02-10

The one used in this tutorial is a LM35 so you're good I think :P ( I'm pretty sure).

author
spock.legend (author)2017-02-04

and can anyone send me the schematics for the (common cathode) display ? please.

author
spock.legend (author)2017-02-04

will this work with mega 2560 ?

author
Remembermyname (author)2017-01-30

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!

author
germapho made it! (author)2017-01-18

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.

tempsensor.jpg
author
sbud (author)2016-04-09

Hi. Nice project. Im very beginner for arduino.
Could you post circuit diagram of your project?

author
Raphango (author)2013-10-09

What if I'm using a common cathode 4 digit 7 segment? Does it changes the cirtuit/code very bad?

author
RuiSantos (author)Raphango2013-10-10

yeah it actually changes the code and the circuit a bit... but it's totally possible!
if you make a quick search you'll see the difference and what you have to change.

I hope this helps! thanks for commenting!

author
Raphango (author)RuiSantos2013-10-10
I have managed to do it! Take a look at my code:
/*
* created by Rui Santos, http://randomnerdtutorials.com
* ALTERED BY: Raphango
* Temperature Sensor Displayed on 4 Digit 7 segment common CATHODE
* 2013
*/
const int digitPins[4] = {7,6,5,4}; //4 common CATHODE pins of the display (inverted the pins order)
const int clockPin = 11;    //74HC595 Pin 11
const int latchPin = 12;    //74HC595 Pin 12
const int dataPin = 13;     //74HC595 Pin 14
const int tempPin = A0;     //temperature sensor pin
const byte digit[10] =      //seven segment digits in bits
{
  B00111111, //0
  B00000110, //1
  B01011011, //2
  B01001111, //3
  B01100110, //4
  B01101101, //5
  B01111101, //6
  B00000111, //7
  B01111111, //8
  B01101111  //9
};
int digitBuffer[4] = {0};
int digitScan = 0;
float tempC; //Deleted kelvin and farenheit

void setup(){               
  for(int i=0;i<4;i++)
  {
    pinMode(digitPins[i],OUTPUT);
  }
  pinMode(tempPin, INPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 
  pinMode(tempPin, INPUT);
  //Serial.begin(9600);
}

//writes the temperature on display
void updateDisp(){
  
  for(byte j=0; j<4; j++) {digitalWrite(digitPins[j], HIGH);} // Turns the display off. Changed to HIGH
  digitalWrite(latchPin, LOW); 
  shiftOut(dataPin, clockPin, MSBFIRST, B00000000);
  digitalWrite(latchPin, HIGH);

  delayMicroseconds(2);

  digitalWrite(digitPins[digitScan], LOW); //Changed to LOW for turning the leds on.

  digitalWrite(latchPin, LOW); 
  if(digitScan==2)
    shiftOut(dataPin, clockPin, MSBFIRST, (digit[digitBuffer[digitScan]] | B10000000)); //print the decimal point on the 3rd digit
  else
    shiftOut(dataPin, clockPin, MSBFIRST, digit[digitBuffer[digitScan]]);

  digitalWrite(latchPin, HIGH);

  digitScan++;
  if(digitScan>3) digitScan=0;
}


void loop(){
  tempC = analogRead(tempPin)*0.00488;  //multiplied for this conversion constant
  tempC = tempC*10000;
  digitBuffer[3] = int(tempC)/1000;
  digitBuffer[2] = (int(tempC)%1000)/100;
  digitBuffer[1] = (int(tempC)%100)/10;
  digitBuffer[0] = (int(tempC)%100)%10;
if (digitBuffer[0]>=5) {
digitBuffer[0] = 5;
}
else {
digitBuffer[0] = 0;
}
delay(4);
  updateDisp();
 
}


###########################
Here's a video too:
Do you have already discovered how to smooth the transitions of showed temperature? Its quite annoying to see that glittering all the time....
 
author
JensS11 (author)Raphango2016-02-17

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??

author
RuiSantos (author)Raphango2013-10-15

Awesome! thanks for trying my project...
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... :(

Thanks again for trying my project.
Can I post it on my website?
(on this page: http://randomnerdtutorials.com/feedback)

author
Raphango (author)RuiSantos2013-10-16

Of course!
Feel free to use it.

About the flickering, I did some changes to the "delay" values, but all it does is lighting up one of the 4 digits each time at an eye perceivable speed.

What I thought about doing was slowing the "update" rate, but unsuccesfully, since I'm a begginer in the shiftOut thing... =P

Thanks again!

author
yanais (author)2016-02-08

Very cool project!

try building the circuit with circuito.io - you'll get a detailed schematic and code.

author
wesleybragah288 (author)2015-11-13

ei elemento , tu desenhou errado , e quase estragou o projeto aqui pivete , se liga viu

author
inthiquab (author)2014-11-18

very nice project. How do I get it to work on a 3digit 7 segment common cathode? thank you

author
kbhat5 (author)2014-09-18

author
SudiartoHsu (author)2013-10-14

sir, what the code if i use lm 35?

author
RuiSantos (author)SudiartoHsu2013-10-15

I think my code will work for lm35... but i don't have time to write the code for you...
I'm sorry, I receive to many requests.
Good luck with your project!

author
rimar2000 (author)2013-04-28

What a good work!

author
RuiSantos (author)rimar20002013-04-28

Thanks!

About This Instructable

84,814views

105favorites

License:

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 GameArduino – Datalogger with Temperature Sensor and Photoresistor
Add instructable to: