{"id":661,"date":"2013-04-15T21:16:55","date_gmt":"2013-04-15T21:16:55","guid":{"rendered":"http:\/\/randomnerdtutorials.com\/?p=661"},"modified":"2019-04-02T10:23:39","modified_gmt":"2019-04-02T10:23:39","slug":"arduino-temperature-displayed-on-4-digit-7-segment","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/arduino-temperature-displayed-on-4-digit-7-segment\/","title":{"rendered":"Arduino &#8211; Temperature Displayed on 4 Digit 7 segment (common anode)"},"content":{"rendered":"<p>In this project I&#8217;ll display the temperature in a 4 digit 7 segment display (common anode).<!--more--><\/p>\n<p><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-982\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/07\/temp-thumb.jpg?resize=1200%2C896&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"1200\" height=\"896\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/07\/temp-thumb.jpg?w=2592&amp;quality=100&amp;strip=all&amp;ssl=1 2592w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/07\/temp-thumb.jpg?resize=300%2C224&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/07\/temp-thumb.jpg?resize=1024%2C764&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/07\/temp-thumb.jpg?w=2400&amp;quality=100&amp;strip=all&amp;ssl=1 2400w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<p>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. <a href=\"https:\/\/randomnerdtutorials.com\/circuits-7-segment-displays\/\">You can also read more about 7 segment displays in this post.<\/a><\/p>\n<p><a href=\"https:\/\/randomnerdtutorials.com\/circuits-7-segment-displays\/\"><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter wp-image-672\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/04\/new.jpg?resize=324%2C242&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"new\" width=\"324\" height=\"242\" \/><\/a><\/p>\n<p><strong>This project is great to learn more about:<\/strong><\/p>\n<ul>\n<li>Reading sensors (in this case temperature)<\/li>\n<li>7 segment displays (4 digit 7 segment displays)<\/li>\n<li>8 bit Shift Registers (74HC595)<\/li>\n<li>Pratice wiring<\/li>\n<\/ul>\n<h2>Parts required<\/h2>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter wp-image-673\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/04\/IMG_02871.jpg?resize=331%2C248&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"IMG_0287\" width=\"331\" height=\"248\" \/><\/p>\n<ul>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/compatible-arduino-uno-r3-board\/\" target=\"_blank\" rel=\"noopener noreferrer\">Arduino UNO<\/a>\u00a0\u2013 read\u00a0<a href=\"https:\/\/makeradvisor.com\/best-arduino-starter-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">Best Arduino Starter Kits<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/lm335lm35dz-temperature-sensor\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x Temperature Sensor (I\u2019m using the LM335Z)<\/a><\/li>\n<li>1x 4 Digit 7 Segment Display (common anode)<\/li>\n<li>1x 74HC595 8 Bit Shift Register<\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">8x 220 Ohm Resistors<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x 4700 ohm Resistor<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x Breadboard (or\u00a0 two)<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noopener noreferrer\">Jumper Wires<\/a><\/li>\n<\/ul>\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n<h2>Schematics<\/h2>\n<p style=\"text-align: center;\"><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/04\/circuit-diagram1.png?quality=100&#038;strip=all&#038;ssl=1\" rel=\"nofollow\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"wp-image-688 aligncenter\" title=\"\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/04\/circuit-diagram1.png?resize=430%2C353&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"circuit diagram\" width=\"430\" height=\"353\" \/><\/a><\/p>\n<p>This can also help you wiring because the Schematics I\u2019ve made using fritizing turned out a bit confusing. This is the 7 segment display internal circuit diagram<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-669\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/04\/images.jpg?resize=154%2C160&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"images\" width=\"154\" height=\"160\" \/><\/p>\n<p><strong><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/04\/7-segment-4-digit-common-anode.png?quality=100&#038;strip=all&#038;ssl=1\" rel=\"nofollow\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-668\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/04\/7-segment-4-digit-common-anode.png?resize=399%2C156&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"7 segment 4 digit common anode\" width=\"399\" height=\"156\" \/><\/a><\/strong><\/p>\n<p>Basically \u00a0the pin 11 connects to the QA, the pin 7 to the QB and so one&#8230;<\/p>\n<h2>Upload the code below<\/h2>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n * Temperature Sensor Displayed on 4 Digit 7 segment common anode\n * Created by Rui Santos, http:\/\/randomnerdtutorials.com\n*\/\n\nconst int digitPins[4] = {\n  4,5,6,7};                 \/\/4 common anode pins of the display\nconst int clockPin = 11;    \/\/74HC595 Pin 11 \nconst int latchPin = 12;    \/\/74HC595 Pin 12\nconst int dataPin = 13;     \/\/74HC595 Pin 14\nconst int tempPin = A0;     \/\/temperature sensor pin\nconst byte digit[10] =      \/\/seven segment digits in bits\n{\n  B00111111, \/\/0\n  B00000110, \/\/1\n  B01011011, \/\/2\n  B01001111, \/\/3\n  B01100110, \/\/4\n  B01101101, \/\/5\n  B01111101, \/\/6\n  B00000111, \/\/7\n  B01111111, \/\/8\n  B01101111  \/\/9\n};\nint digitBuffer[4] = {\n  0};\nint digitScan = 0, flag=0,  soft_scaler = 0;\n;\nfloat tempK, tempC, tempF, temp;\n \nvoid setup(){                \n  for(int i=0;i&lt;4;i++)\n  {\n    pinMode(digitPins[i],OUTPUT);\n  }\n  pinMode(tempPin, INPUT);\n  pinMode(latchPin, OUTPUT);\n  pinMode(clockPin, OUTPUT);\n  pinMode(dataPin, OUTPUT);  \n  pinMode(tempPin, INPUT);\n}\n \n\/\/writes the temperature on display\nvoid updateDisp(){\n  for(byte j=0; j&lt;4; j++)  \n    digitalWrite(digitPins[j], LOW);\n \n  digitalWrite(latchPin, LOW);  \n  shiftOut(dataPin, clockPin, MSBFIRST, B11111111);\n  digitalWrite(latchPin, HIGH);\n \n  delayMicroseconds(100);\n  digitalWrite(digitPins[digitScan], HIGH); \n \n  digitalWrite(latchPin, LOW);  \n  if(digitScan==2)\n    shiftOut(dataPin, clockPin, MSBFIRST, ~(digit[digitBuffer[digitScan]] | B10000000)); \/\/print the decimal point on the 3rd digit\n  else\n    shiftOut(dataPin, clockPin, MSBFIRST, ~digit[digitBuffer[digitScan]]);\n \n  digitalWrite(latchPin, HIGH);\n  digitScan++;\n  if(digitScan&gt;3) digitScan=0; \n}\n \nvoid loop(){ \n  tempK = (((analogRead(tempPin)\/ 1023.0) * 5.0) * 100.0);  \n  \/\/Converts Kelvin to Celsius minus 2.5 degrees error\n  tempC = tempK - 273.0;   \n  tempF = ((tempK - 2.5) * 9 \/ 5) - 459.67;\n  \/\/Celsius temperature display\n  tempC = int(tempC*100);\n  digitBuffer[3] = int(tempC)\/1000;\n  digitBuffer[2] = (int(tempC)%1000)\/100;\n  digitBuffer[1] = (int(tempC)%100)\/10;\n  digitBuffer[0] = (int(tempC)%100)%10;\n  updateDisp();\n  delay(2);\n \n  \/*\n  \/\/Fahrenheit temperature display\n  tempF = int(tempF*100);\n  digitBuffer[3] = int(tempF)\/1000;\n  digitBuffer[2] = (int(tempF)%1000)\/100;\n  digitBuffer[1] = (int(tempF)%100)\/10;\n  digitBuffer[0] = (int(tempF)%100)%10;\n  updateDisp();\n  delay(2);\n  *\/\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Temperature_Displayed_on_4_Digit_7_segment_common_anode.c\" target=\"_blank\">View raw code<\/a><\/p>\n<h2>Watch the video demonstration<\/h2>\n<p style=\"text-align:center\"><iframe width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/qYK6By37-Oo?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>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\u00a0<a href=\"https:\/\/www.facebook.com\/RandomNerdTutorials?ref=hl\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Facebook Page.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this project I&#8217;ll display the temperature in a 4 digit 7 segment display (common anode).<\/p>\n","protected":false},"author":1,"featured_media":982,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[303,2,267,264,10],"tags":[14,241,32,47,48,61,71,78,116,122,134,152],"class_list":["post-661","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-arduino","category-arduino","category-arduino-project","category-project","category-a-tutorials","tag-4-digit-7-segment-display","tag-arduino","tag-beginner","tag-code-download","tag-common-anode","tag-easy","tag-free","tag-hc595-shift-register","tag-portugal","tag-projects","tag-rui-santos","tag-temperature-sensor"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2013\/07\/temp-thumb.jpg?fit=2592%2C1936&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/661","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=661"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/661\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/982"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}