temp thumb

Arduino – Temperature Displayed on 4 Digit 7 segment (common anode)

515 Flares 515 Flares ×

In this project I’ll display the temperature in a 4 digit 7 segment display (common anode).

new

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

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:

Download it here for free

Thanks So much for sharing my content.

 

Watch how it works:

 

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.

67 Comments

  • maciunio

    Reply Reply May 1, 2013

    hi, can you share the fritzing file? :)

    • ruisantos16

      Reply Reply May 1, 2013

      hi, sure!
      you can download here
      https://www.box.com/s/psktp3z6u7h000v64dcq

      • maciunio

        Reply Reply May 1, 2013

        thnx :)
        I’m trying to use your project as a part of mine – wireless themrometer with display, but as usual I have problems with displaying the numbers :D
        tomorrow morning I’ll try to fixup some wires ;)

        • ruisantos16

          Reply Reply May 1, 2013

          Good luck!
          if you have any troubles that I can help you with, just let me know

      • miguel

        Reply Reply May 21, 2013

        Friend need a program to help me on and off 2 leds with arduino, android and bluetooth module can help me?

        • Rui Santos

          Reply Reply May 22, 2013

          if you’re portuguese you can comment in portuguese.
          Tell me what you really want to do and what arduino, bluetooth module you have…

      • Ard

        Reply Reply March 3, 2014

        i tried to use your program for display on a common cathode, but it is not working even though i switch 0 to 1 and 1 to 0, any help….

  • maciunio

    Reply Reply May 2, 2013

    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

      Reply Reply May 2, 2013

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

      • maciunio

        Reply Reply May 3, 2013

        Could that loop has any delays?

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

        • Rui Santos

          Reply Reply May 3, 2013

          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

      • maciunio

        Reply Reply May 3, 2013

        I think that delay is from that I’m using digital Dallas 18B20 temp sensor… How do you think?

        • Rui Santos

          Reply Reply May 3, 2013

          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.

  • Ameen Al Abadi

    Reply Reply May 2, 2013

    good work
    i have a problem and i hope you help me , in the Schematics i cant understand which pin linked with resistors withe 7 segment 4 digit display and do you use this 7 segment 4 digit (see the link)

    http://image.made-in-china.com/2f0j00RsUTuDaIBpkz/7-Segment-LED-Display-4-Digits-Common-Anode-High-Light-Red-KHN40561-.jpg

    • Rui Santos

      Reply Reply May 2, 2013

      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!

  • Marvin

    Reply Reply May 17, 2013

    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

      Reply Reply May 19, 2013

      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

      • Marvin

        Reply Reply May 19, 2013

        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

          Reply Reply May 19, 2013

          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…

          • Ubirajara Cortes

            September 24, 2013

            Wrong reply place.

          • Rui

            September 25, 2013

            What you mean?
            Thanks for commenting…

  • Imam Moeslim

    Reply Reply September 17, 2013

    hi.. Rui .

    how about if im using LM35DZ ?

    thank you :)

    • Rui

      Reply Reply September 19, 2013

      They will both work just fine I guess!
      but I’ve searched a bit and I found this:

      “The difference between an LM335 and LM34 and LM35 temperature sensors is the LM335 sensor gives out the temperature in degrees Kelvin, while the LM35 sensor gives out the temperature in degrees Celsius and the LM34 sensor gives out the temperature in degrees Fahrenheit. ”

      source: http://www.learningaboutelectronics.com/Articles/LM335-temperature-sensor-circuit.php

      I hope this helps! Good Luck with your project!

      • Imam Moeslim

        Reply Reply October 2, 2013

        thanks… i’ll try and work :)

        • Rui

          Reply Reply October 2, 2013

          Awesome! Thanks for commenting! Let me know if it worked for you!

  • esmail

    Reply Reply October 9, 2013

    hi i want to use this segment with HY-srf05 ultrasound sensor to displayed the distance

  • Dave

    Reply Reply November 17, 2013

    Too bad so much content is locked, defeats purpose of tutorials for those of us that don’t do social networking…

    • Rui Santos

      Reply Reply November 17, 2013

      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

  • wiratama

    Reply Reply December 5, 2013

    thank’s for this tutorial. i’ll try it.

    • Rui Santos

      Reply Reply December 5, 2013

      Thanks for taking the time to leave a comment!
      Cheers,
      Rui

  • Baron

    Reply Reply December 19, 2013

    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

      Reply Reply December 19, 2013

      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

      • Baron

        Reply Reply December 20, 2013

        Hi
        Thanks for the quick response, i dont see a transistor in the schematic? That may be the problem…
        Where does it go?

        • Rui Santos

          Reply Reply December 22, 2013

          You’re right there’s no transistor I was confused with another project! sorry :S

  • Baron

    Reply Reply December 20, 2013

    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

      Reply Reply December 22, 2013

      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

        Reply Reply December 25, 2013

        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

          Reply Reply December 26, 2013

          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…

  • almc

    Reply Reply December 28, 2013

    may i know the code for the temp sensor

    • Rui Santos

      Reply Reply December 28, 2013

      The code is all in this page almc…
      Please click the like button or another sharing button and the code will unlock.
      you can also download all my project for free here:
      http://randomnerdtutorials.com/download

      Thanks for taking the time to leave a comment

  • ali

    Reply Reply January 21, 2014

    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

      Reply Reply January 22, 2014

      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

  • ali

    Reply Reply January 24, 2014

    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

      Reply Reply January 27, 2014

      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?

  • ali

    Reply Reply January 25, 2014

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

  • ali

    Reply Reply January 27, 2014

    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

      Reply Reply January 29, 2014

      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

        Reply Reply January 30, 2014

        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!! :)

        • Rui Santos

          Reply Reply January 30, 2014

          Thanks ali!
          Might try that when I have more free time!

          All the best,
          Rui

    • Rui Santos

      Reply Reply January 29, 2014

      That’s what happens when we don’t comment every line, now I don’t remember exactly why I did that xD

  • Ard

    Reply Reply March 3, 2014

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

  • Ard

    Reply Reply March 3, 2014

    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

    • Rui Santos

      Reply Reply March 4, 2014

      How are you wiring the circuit?
      You need to tell me a bit more about what you’re doing…

  • apurva vedak

    Reply Reply March 4, 2014

    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

      Reply Reply March 4, 2014

      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?

  • Enrico Sadlowski

    Reply Reply April 15, 2014

    Thanks for this great tutorial.

    Is it possible with the contribution http://randomnerdtutorials.com/arduino-temperature-displayed-on-4-digit-7-segment/ the 4 common anode must be connected to a shift register to save even more Pns on Arduino?

    How should look like the sketch?

    It would be great if you could help me there

    • Rui Santos

      Reply Reply April 18, 2014

      Hi Enrico,
      I’m already using a shift register… what you exactly mean?
      Use another one?

      • Enrico Sadlowski

        Reply Reply April 18, 2014

        You have connected the common cathode on Arduino, not to the 74HC595. It is possible to connect the common cathode to the 74HC595?

        • Rui Santos

          Reply Reply April 25, 2014

          Yeah I think so… but it wouldn’t only save you an extra pin I think.
          But that’s something that you can try

  • Robert K

    Reply Reply May 3, 2014

    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…

    • Robert K

      Reply Reply May 3, 2014

      sorry i said somehing stupid..haha…i mean its connected to the ground and + too..but..the first pin is not connected anywhere..

    • Rui Santos

      Reply Reply May 3, 2014

      Hi Robert,
      Take a look at this schematic:
      http://i0.wp.com/randomnerdtutorials.com/wp-content/uploads/2013/11/Schematics1.png

      It might be easier to understand. It’s also a temperature sensor that 3 leg part!
      Yes you’re right it’s also connected to the ground with the black wire.
      And you don’t need to connect the other sensor pin to anything :)
      I hope this helps.

      • Robert K

        Reply Reply May 5, 2014

        Thank you! :D yes…it helped! :D

  • Skully Fourbery

    Reply Reply May 4, 2014

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

Leave A Response

* Denotes Required Field