Arduino – 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. You can also read more about 7 segment displays in this post.


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

Parts required

  • 1x Arduino (Click to see on Amazon)
  • 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 CablesIMG_0287


circuit diagram


This can also help you wiring because the Schematics I’ve made using fritizing turned out a bit confusing. This is the 7 segment display internal circuit diagram


7 segment 4 digit common anode

Basically  the pin 11 connects to the QA, the pin 7 to the QB and so one…

Upload the code below

Watch the video demonstration

Related Content: Like ESP8266? Check out Home Automation Using ESP8266

Thanks for reading, you can contact me by leaving a comment. If you like this post probably you might like my next ones, so please support me by subscribing my blog and my Facebook Page.


  1. says

    OK, I’ve got it working… quite a lot of changes, but it works… now I have a problem that the digits are blinking – it seems that reading temp makes them blink… only forst digit is ok, the rest are not… any ideas?

    • Rui Santos says

      I guess it’s a delay problem… if you have some delays in your loop it will make the display to blink!

      • says

        Could that loop has any delays?

        void loop()
        t = sensors.getTempCByIndex(0)*100;
        displayNum(t, 20);

        • Rui Santos says

          I’ve used a really small delay on the loop function and it worked, but it was like delay(2); Actually i think that i don’t even need that delay, but I’ve used it… but I remember that I tried with delay(10) and delay(20) and It kept my display blinking

        • Rui Santos says

          That can be the problem I guess, my temperature sensor just reads the voltage is going trough the sensor and then I convert the voltage to temperature, I don’t know exactly how your sensor does the reading… but if it’s taking too much time to read the temperature, for instance if your using a library that has a function to read the temperature that takes too much time, that will make the display to blink.

    • Rui Santos says

      In the schematics above if you check them carefully it’s something like that
      top pins:
      12 – 11(R) -10 (R)- 9 – 8 – 7(R)
      1(R) – 2(R) – 3(R) – 4(R) – 5(R) – 6 –
      I hope this helps you!

      • says

        Hi Rui!

        I’m a total beginner with Arduino, and am trying to adapt your project here to my 4-digit, 7-segment display (which appears to be the same as Ameen’s).

        Unfortunately, I really don’t understand this stuff well enough yet to know what I need to change… even with your last comment there. Would you mind giving a little more guidance?

  2. says

    Hi Maciunio, I would like to build a wireless thermometer with the arduino board. interessting for me is which Hardware do you use for the wireless temperature sensor.
    Thanks in Advance

    • Rui Santos says

      It depends on how you want to read the temperature and where you want the temperature to be displayed.
      You can’t do that using a bluetooth module and receive that data.
      Or you can use an wireless shield or ethernet shield and display the temp on a webserver, (in a html page)
      And then you can acess all that information with your computer/smartphone.
      I hope I’ve anwesered your question!
      Good Luck

      • says

        Hi Rui, thanks for your quick response. The Plan is to record the temperatur with some kind of wireless temerature sensor. And this sensor transferred the Datas over approximate 10meters to the Arduino Board where the temperatur should be displayed.
        So my questions is which sensor could I use. Perfect would be a sensor without power supply just using batteries. But this is not a “Must Have”.
        Many Thanks.
        Bye Marvin

        • Rui Santos says

          Actually the best and cheap way that I thought It was possible to do that (I recommend you to do more research about this) was with a RF signal and you will need two arduino boards.
          One arduino board will read the temperature (for example with this temp sensor LM335Z) and It will send the data via RF
          to the other arduino that will receive the data via RF. And then with that you can display the temperature.

          this guy made an awesome tutorial not about what you want but it explains how RF works…

    • Rui Santos says

      Hi Dave,
      I’m sorry for some of my content being locked.
      But you don’t need any social networking.
      simply go to this page: enter your email and you’ll receive access to a secret page that I update everytime I release a new project. so you can download everything in just one place and you don’t need to share anything.

      And btw in few days I’ll remove that feature. and I’ll my code will be available in my posts.
      I just need to finish some projects first.

      Sorry for that.
      All the best,
      Rui Santos

  3. Baron says

    I’ve wired everything up the way you have and for some reason i only get all the segments lighting up so it read “8888”, i hooked a potentiometer in place of the thermometer and the digits flicker when i change the voltage.
    Am i missing a library or something?
    thanks for your help

    • Rui Santos says

      Hi Baron,
      Thanks for trying my project.
      Just a quick question is your Display a Common Anode?
      Did you insert the transistor and the Shift Register in the right way?
      You don’t need any library… If you’re sure you’ve wired everything properly I don’t know exactly what can be wrong then :S

      Let’s see if it’s one of those problems I’ve mentioned above,

  4. Baron says

    also the shift register is correct i am sure, if i flip the arduino looses all power… the 7 segment display is common anode i am sure
    thanks again

    • Rui Santos says

      Seems to me that you’ve did everything correct…
      I have no idea what else can be wrong. I just tested this circuit again it works fine for me and for everyone who messaged me :S

      Sorry, I would need to be with the circuit on hands to see what’s missing.

      • baron says

        thanks for the help, what does the display show if you remove the temperature sensor? do they all light up or is it blank?

        • Rui Santos says

          That’s a really good question… I’m not sure though.
          It will all depend on which values are you sending to the function that prints on the 7 Segments.

          If you upload exactly my code and remove the temperature sensor, it will output random values on the 7 segments.

          If you want to debug your project and be sure that your temperature sensor is working properly it’s easy.
          Simply insert some: Serial.println(“your values”);
          and you’ll see if your sensor is working or not…

  5. ali says

    Hi Rui!
    DUDE you are a freaking life saver!! I love the you have described everything so perfectly in this tutorial. I have but a couple of questions though. I am trying the same project with a load cell in stead of the temperature sensor. For my project I need to input an 8 bit pressure value from the computer, the ardiuno needs to read it and then adjust the load cell accordingly. Now using serial communication I know I can send data to the Ardiuno. How ever the data is going to be in ASCII. So how do I convert it to binary so I can display it on the 7 segment display and also use the data value to adjust the pressure being applied on the load cell accordingly.( i have a feeling its got something to do with the byte() function.
    My second question is the sensor is powered from an external power supply. As far as my understanding goes, the out put from the load cell can be connected directly to the analog pin and ground and it should work fine. But I would appreciate it if you could confirm this.
    Thanks alot for your help bro!! you are doing a great job. Please keep it up =D

    • Rui Santos says

      Thanks Ali,
      I’m glad you found my tutorial useful!
      first question:
      that’s true you’re sending and reading ASCII values from the arduino IDE serial monitor.
      One way to turn ASCII into binary as you said is by creating a new function that will do exactly what you want.7
      The Arduino supports some functions that might help you, It’s called atoi(). and it basically converts any string you receive into a number.
      or this one might also be useful:

      second question:
      you’re right.. It should work just fine, but you need to be sure how much voltage/current is going through the sensor.
      And then change the function that reads the analog pin and calculates the temperature.

      I hope this helps!
      More tutorials coming soon,
      stay tuned!

  6. ali says

    thanks Rui for that informative reply!
    I was successful in writing a conversion for ascii to binary.
    I was going through your code again and wanted to ask a few quick questions about the code you have written.
    1. you have defined flag=0 and soft_scaler = 0 but have not used them any where in the code. why is that.
    2. secondly you have inverted the bits in the code using ~. why do you do that?
    3. you have done conversions for Fahrenheit and Celsius. but which one is it that you display in your final display? and how do you chose which one to display!
    greatly appreciate your help!!

    • Rui Santos says

      I’m glad I could help.
      1) Those variables aren’t necessary, you can delete them and the code will work just fine. They weren’t necessary in the end, but I forgot to delete them.
      2) which lines of my code are you exactly referring to?

  7. ali says

    ignore the third silly question. lol just realized the Fahrenheit display is in the form of a comment. please if you could answer the first two that would be just awesome! thanks!!

  8. ali says

    Hi Rui!
    the lines of the code I am referring to are
    shiftOut(dataPin, clockPin, MSBFIRST,~(digit[digitBuffer[digitScan]] | B10000000)); else

    shiftOut(dataPin, clockPin, MSBFIRST, ~digit[digitBuffer[digitScan]]);

    you have used “~” symbol. isnt it used to invert the bits?

    • Rui Santos says

      Yes it works inverted!
      I don’t recall exactly why is like that… I think is because I’m using a common anode 4 Digit 7 segment .

      • ali ashraf says

        hahaha! well it works like a charm! so I cant thank you enough for your public service 😉
        btw with regards to the flickering display. Smoothing the values (averaging them and then displaying them) might give you a better display!! :)

  9. Ard says

    which part of your program should i use if i want to display say 3489 on a common cathode segment display??

  10. Ard says

    Please help me out with the code for a common cathode. Instead of having 1 digit lit up at time im getting 3 digits… please help

  11. apurva vedak says

    Hey…Thank you so much this is helping me a lot…The problem is I am using a & segment display with 14 pins. /could that be the reason it could not be working?

    • Rui Santos says

      Please send me a link to your Display… I have no idea which display you’re using apurva…
      If you’re using a different Display how are you wiring the circuit?

  12. Robert K says

    Hello Rui! :) i have a question…the Temperature Sensor doesn’t have to connect to the ground? Because i see that the middle pin of it is connected to the + and tot he arduino…

  13. Skully Fourbery says

    Thank you a buncch ffor sharing this with all of us you actujally recognize
    what you’re speaking about! Bookmarked.

  14. Yariv says

    Great job!
    Though I would like to add some comments,
    The code is quite complex for a beginner, so I had really to debug, please add more comments, especially in the function you add (we are used to have only void setup and void loop….;-). The diagram is also something you should more comment since it is not clear from the picture.
    I am using instead of the temp sensor a sonar and it works perfect, but how do i get rid of the flickering? I tried to put delays between the readings but understood that it just delays the digits writings to the display.
    Thanks for sharing, I will keep following your projects

  15. Admiral.Amos says

    hello bro Rui.
    acctually i need your help. i want to change the temperature sensor with Load Cell sensor which is to measure the mass of an object. so which part should i change the coding part?

    thank you,

  16. bruce says

    Hi Rui ,
    Im newbie in Arduino. Thank you for your sharing about Temperature Displayed on 4 Digit 7 segment.

    But I can not understand what means with your fritzing file.

    Im using 4 Digit 7 segment(SMA420564)、74HC595N and LM35

    But I dont know how to fixed them in breadboard.
    For example, there are 12pins(6pins for one side) in my display(SMA420564) but it seems 20 pins(10pins for one side) in your fritzing file.

    Can you tell me how to fix in my breadboard with SMA420564、74HC595N and LM35?

    Thank you so much!

    • bruce says

      Sorry I mean following your fritzing file and code but it does not work :(

      Can you tell me where is a problem?

      I check my circuit and code. it is not different with you.

      thank you very much!!!

  17. says

    Hi there!
    I have a similar thermometer project like this. Instead of LM335Z Temp Sensor, I’m using THERMISTOR and applying voltage divider :)

    +5V o——-/\/\/\/\——–|——–/\/\/\/\—–|I- ground
    ( Thermistor) | ( Resistor)
    10k ohms | 10k ohms
    (Analog pin)

    1.) Would this circuit be applicable as a replacement of the LM335Z temp sensor?
    2.) How to eliminate flickers on the display?

    • says

      Hi Julyle,
      1) Yes, you can replace the LM335Z with a thermistor, you just need to change that part of code that reads the sensor.
      2) No… I have always new projects coming up, so unfortunately I’ve never had a change to fix that problem…
      Thanks for trying my project!

  18. Galactik56Prog says

    Hi ! Thanks you so much for this !! I just have a question, i’m using a 4 digits 7 segments display but with common cathode, what did i have to change in the program or in the wiring ?
    Thanks you again !

  19. Michael harris says

    Is there any way you can send me an eagle schematics for this project. i cannot import a fritzing file into my eagle and am doing my senior design and my professors are not teaching me anything they expect me to know everything am having a severe depression help me out please!

    • says

      Hi Michael,
      Sorry I don’t have time to draw the circuit for you, but it should be really easy.
      There are plenty of tutorials using Eagle on the Internet

  20. Ronald says

    Hai Rui,

    Thanks a lot for this post, it helped me a lot to create my own thermometer. The approach that I took was interrupt-driven displaying and sampling of the sensor. You can find my code at

    Best regards!


Leave a Reply

Your email address will not be published. Required fields are marked *