{"id":4915,"date":"2012-06-15T09:50:04","date_gmt":"2012-06-15T13:50:04","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=4915"},"modified":"2013-04-23T21:34:52","modified_gmt":"2013-04-24T01:34:52","slug":"chipkit-project-1-digital-thermometer-using-an-lm34-sensor","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/chipkit-project-1-digital-thermometer-using-an-lm34-sensor\/","title":{"rendered":"chipKIT Project 1: Digital thermometer using an LM34 sensor"},"content":{"rendered":"<p>In <a href=\"http:\/\/embedded-lab.com\/blog\/?p=4802\" target=\"_blank\">Tutorial 3<\/a>, we learnt how to use chiKIT ADC channels to read an external analog voltage and convert it into a digital number. We also discussed about interfacing a standard Hitachi 44780-based character LCD to the chipKIT Uno32 board in <a href=\"http:\/\/embedded-lab.com\/blog\/?p=4831\" target=\"_blank\">Tutorial 4<\/a>. Now it&#8217;s time to implement the knowledge we have gained so far to make our first practical application using chipKIT, which is a digital thermometer. Since temperature is a non-electrical entity, the first thing we need is a transducer or sensor to convert it into an electrical signal. In this project, we will use the LM34 sensor to do that, which converts the surrounding temperature into an analog electrical voltage. The sensor\u2019s analog output is fed to an ADC channel of the chipKIT Uno32, which then process the signal and displays the temperature on LCD, in both degree Celsius and Fahrenheit scales.<\/p>\n<div id=\"attachment_4921\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/P1_OP2.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4921\" class=\"size-full wp-image-4921\" title=\"P1_OP2\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/P1_OP2.jpg\" alt=\"\" width=\"570\" height=\"437\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/P1_OP2.jpg 570w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/P1_OP2-550x421.jpg 550w\" sizes=\"auto, (max-width: 570px) 100vw, 570px\" \/><\/a><p id=\"caption-attachment-4921\" class=\"wp-caption-text\">Digital thermometer project<\/p><\/div>\n<p><!--more--><\/p>\n<p><strong>Circuit setup<\/strong><\/p>\n<p>The circuit diagram of this project is pretty simple and is shown below. The LM34 is a precision temperature sensor that provides an analog output voltage which is linearly proportional to the Fahrenheit temperature. It does not require any external calibration and is rated to operate over -50\u00b0F to 300\u00b0F. The temperature-to-voltage conversion factor is 10mV\/\u00b0F.\u00a0This means it gives an output of 750 mV at 75\u00b0F temperature. The LM34 output is connected to analog channel A0 of Uno32 for A\/D conversion. The ADC output is manipulated by the chipKIT processor to derive the temperature information, which is later displayed on a standard HD44780-based character LCD. The LCD connection pins are also described in the circuit diagram.<\/p>\n<div id=\"attachment_4918\" style=\"width: 584px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/Circuit1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4918\" class=\"size-full wp-image-4918\" title=\"Circuit1\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/Circuit1.png\" alt=\"\" width=\"574\" height=\"430\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/Circuit1.png 574w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/Circuit1-550x412.png 550w\" sizes=\"auto, (max-width: 574px) 100vw, 574px\" \/><\/a><p id=\"caption-attachment-4918\" class=\"wp-caption-text\">LM34 connected to chipKIT UNO32 board<\/p><\/div>\n<div id=\"attachment_4919\" style=\"width: 584px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/Circuit2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4919\" class=\"size-full wp-image-4919\" title=\"Circuit2\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/Circuit2.png\" alt=\"\" width=\"574\" height=\"393\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/Circuit2.png 574w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/Circuit2-550x376.png 550w\" sizes=\"auto, (max-width: 574px) 100vw, 574px\" \/><\/a><p id=\"caption-attachment-4919\" class=\"wp-caption-text\">LCD connections to chipKIT UNO32<\/p><\/div>\n<div id=\"attachment_4923\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/P1_SetUp.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4923\" class=\"size-full wp-image-4923\" title=\"P1_SetUp\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/P1_SetUp.jpg\" alt=\"\" width=\"570\" height=\"427\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/P1_SetUp.jpg 570w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/P1_SetUp-550x412.jpg 550w\" sizes=\"auto, (max-width: 570px) 100vw, 570px\" \/><\/a><p id=\"caption-attachment-4923\" class=\"wp-caption-text\">Circuit setup on a breadboard<\/p><\/div>\n<p><strong>Writing sketch<\/strong><\/p>\n<p>As mentioned earlier, the LM34 gives analog output voltage linearly proportional to temperature with scale factor of 10mV\/\u00b0F. The reference voltage used in this project for A\/D conversion is the supply voltage, which is 3.3V. Therefore, with 10-bit ADC, the resolution of A\/D conversion becomes 3.3\/1024 = 3.2mV\/count. What this means is you can calculate the input analog voltage (in millivolts) back from an ADC count by multiplying the count by 3.2. Finally, to get Fahrenheit temperature, you need to divide the analog voltage (in millivolts) by 10. So, the overall equation to compute the Fahrenheit temperature from a 10-bit ADC count is,<\/p>\n<h3 style=\"text-align: center;\">T(\u00b0F) = 3.2 * ADC Count\/10<\/h3>\n<p>The Fahrenheit to\u00a0Celsius\u00a0conversion is straightforward. The following sketch displays the measured temperature on the LCD in both\u00a0\u00b0F and\u00a0\u00b0C scales.<\/p>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"c\" style=\"font-family:monospace;\"><span style=\"color: #808080; font-style: italic;\">\/*\n  Project 1:  Digital thermometer using LM34 sensor \n  Description: The analog output voltage from the LM34\n               temperature sensor is converted into C and F scale\n               temperature and is displayed on LCD.\n  Board: chipKIT UNO32\n *\/<\/span>\n&nbsp;\n&nbsp;\n<span style=\"color: #666666; font-style: italic;\">\/\/ Include the LiquidCrystal library<\/span>\n<span style=\"color: #339933;\">#include &lt;LiquidCrystal.h&gt;<\/span>\n&nbsp;\n<span style=\"color: #666666; font-style: italic;\">\/\/ Initialize the LCD interface pins in the following sequence<\/span>\n<span style=\"color: #666666; font-style: italic;\">\/\/ RS, E, D4, D5, D6, D7<\/span>\n&nbsp;\nLiquidCrystal lcd<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">9<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">8<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">7<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">6<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">5<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">4<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #993333;\">int<\/span> ADC_OUTPUT<span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #993333;\">float<\/span> tempF<span style=\"color: #339933;\">,<\/span> tempC<span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #993333;\">void<\/span> setup<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n  <span style=\"color: #666666; font-style: italic;\">\/\/ Define the number of columns and rows of the LCD <\/span>\n  lcd.<span style=\"color: #202020;\">begin<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">16<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">2<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #009900;\">&#125;<\/span>\n&nbsp;\n<span style=\"color: #993333;\">void<\/span> loop<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n  lcd.<span style=\"color: #202020;\">setCursor<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">2<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span> \n  lcd.<span style=\"color: #202020;\">print<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #ff0000;\">&quot;Thermometer&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>  \n  lcd.<span style=\"color: #202020;\">setCursor<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>  \n  ADC_OUTPUT <span style=\"color: #339933;\">=<\/span> analogRead<span style=\"color: #009900;\">&#40;<\/span>A0<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  tempF <span style=\"color: #339933;\">=<\/span> ADC_OUTPUT<span style=\"color: #339933;\">*<\/span><span style=\"color:#800080;\">3.2<\/span><span style=\"color: #339933;\">\/<\/span><span style=\"color:#800080;\">10.0<\/span><span style=\"color: #339933;\">;<\/span>  <span style=\"color: #666666; font-style: italic;\">\/\/ Temperature in degree C<\/span>\n  tempC <span style=\"color: #339933;\">=<\/span> <span style=\"color:#800080;\">5.0<\/span><span style=\"color: #339933;\">*<\/span><span style=\"color: #009900;\">&#40;<\/span>tempF<span style=\"color: #339933;\">-<\/span><span style=\"color:#800080;\">32.0<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">\/<\/span><span style=\"color:#800080;\">9.0<\/span><span style=\"color: #339933;\">;<\/span> <span style=\"color: #666666; font-style: italic;\">\/\/ Temperature in degre F<\/span>\n  lcd.<span style=\"color: #202020;\">print<\/span><span style=\"color: #009900;\">&#40;<\/span>tempF<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  lcd.<span style=\"color: #202020;\">print<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #993333;\">char<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #0000dd;\">223<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>         <span style=\"color: #666666; font-style: italic;\">\/\/ Print degree symbol<\/span>\n  lcd.<span style=\"color: #202020;\">print<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #ff0000;\">&quot;F &quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  lcd.<span style=\"color: #202020;\">print<\/span><span style=\"color: #009900;\">&#40;<\/span>tempC<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  lcd.<span style=\"color: #202020;\">print<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #993333;\">char<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #0000dd;\">223<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>         <span style=\"color: #666666; font-style: italic;\">\/\/ Print degree symbol<\/span>\n  lcd.<span style=\"color: #202020;\">print<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #ff0000;\">&quot;C&quot;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  delay<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">2000<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #009900;\">&#125;<\/span><\/pre><\/td><\/tr><\/table><\/div>\n\n<p><strong><a href=\"http:\/\/www.embedded-lab.com\/uploads\/chipKIT\/P1_Thermometer.zip\">Download the sketch file<\/a><\/strong><\/p>\n<p><strong>Output<\/strong><\/p>\n<p>The temperature is displayed on the LCD and is refreshed every 2 seconds.<\/p>\n<div id=\"attachment_4922\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/p1_OP3.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4922\" class=\"size-full wp-image-4922\" title=\"p1_OP3\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/p1_OP3.jpg\" alt=\"\" width=\"570\" height=\"428\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/p1_OP3.jpg 570w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/04\/p1_OP3-550x412.jpg 550w\" sizes=\"auto, (max-width: 570px) 100vw, 570px\" \/><\/a><p id=\"caption-attachment-4922\" class=\"wp-caption-text\">Temperature measurement displayed on LCD<\/p><\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Tutorial 3, we learnt how to use chiKIT ADC channels to read an external analog voltage and convert it into a digital number. We also discussed about interfacing a standard Hitachi 44780-based character LCD to the chipKIT Uno32 board in Tutorial 4. Now it&#8217;s time to implement the knowledge we have gained so far to make our first practical application using chipKIT, which is a digital thermometer. Since temperature is a non-electrical entity, the first thing we need is a transducer or sensor to convert it into an electrical signal. In this project, we will use the LM34 sensor<\/p>\n","protected":false},"author":1,"featured_media":4918,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[401],"tags":[402,432,46],"class_list":["post-4915","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chipkit","tag-chipkit-uno32","tag-lm34","tag-thermometer"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/4915","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/comments?post=4915"}],"version-history":[{"count":16,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/4915\/revisions"}],"predecessor-version":[{"id":6258,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/4915\/revisions\/6258"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/4918"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=4915"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=4915"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=4915"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}