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.

new

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

Schematics

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

images

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

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.

Comments

  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()
        {
        sensors.requestTemperatures();
        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!

  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
    Marvin

    • Rui Santos says

      Hi,
      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

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

    Hi
    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,
      Rui

  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

        Hi
        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.
      http://www.cplusplus.com/reference/cstdlib/atoi/
      or this one might also be useful:
      http://arduino.cc/en/Reference/BitRead

      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!
      Rui

  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!!
    thanks
    Regards

    • 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!
    cheers!
    the lines of the code I am referring to are
    if(digitScan==2)
    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?
    Regards
    Ali

    • 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
    Y3G

Trackbacks

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>