{"id":4001,"date":"2011-11-06T19:40:24","date_gmt":"2011-11-07T00:40:24","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=4001"},"modified":"2012-07-30T09:29:14","modified_gmt":"2012-07-30T13:29:14","slug":"revised-version-of-lm35-based-digital-temperature-meter","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/revised-version-of-lm35-based-digital-temperature-meter\/","title":{"rendered":"Revised version of LM35 based digital temperature meter"},"content":{"rendered":"<p>This is a revised version of my <strong><a href=\"http:\/\/embedded-lab.com\/blog\/?p=916\" target=\"_blank\">LM35 based digital thermometer<\/a><\/strong>\u00a0project that I posted last year. Although it is one of the simplest projects, it is very popular among newbies who are just starting to learn microcontrollers. There was a little flaw in the original project as pointed by some readers. I was using a 1.2 V reference for A\/D conversion with PIC16F688 microcontroller. However, the PIC16F688 datasheet says Vref should be equal to or higher than 2.2 V to ensure 1 LSB accuracy of A\/D conversion. Here, I am rewriting the same project but this time I am using a MCP1525 IC to generate a precise 2.5 V reference for A\/D conversion. This will improve the accuracy of temperature measurements.<\/p>\n<div id=\"attachment_4003\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/LM35_OP.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4003\" class=\"size-full wp-image-4003\" title=\"LM35_OP\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/LM35_OP.jpg\" alt=\"\" width=\"560\" height=\"353\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/LM35_OP.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/LM35_OP-550x346.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-4003\" class=\"wp-caption-text\">Interfacing LM35 temperature sensor with a PIC microcontroller<\/p><\/div>\n<p><!--more--><\/p>\n<p><strong>Theory<\/strong><\/p>\n<p>The LM35 series of analog temperature sensors are produced by National Semiconductor Corporation and are rated to operate over a -55\u00a0\u00b0C to 150 \u00b0C temperature range. These sensors do not require any external calibration. The output voltage is proportional to the temperature, and the temperature-to-voltage conversion factor is 10 mV per\u00a0\u00b0C. The sensor does not have any DC offset output voltage (which means the output is 0V at 0 \u00b0C temperature) and therefore, a negative voltage source is required in order to measure temperatures below 0 \u00b0C. For simplicity, the setup shown here is made to measure temperatures above 0 \u00b0C only. The PIC16F688 microcontroller reads the analog output voltage from the sensor through one of its ADC channel and derives the temperature information out of it.<\/p>\n<p>For the maximum temperature value of 150 \u00b0C, the output voltage of the sensor would be 150 x 10 mV = 1. 5 V. If we use Vref = 5.0 V (power supply voltage) for A\/D conversion, the resolution would be poor as the input signal goes only up to 1.5 V. Besides, if the supply voltage is not stable, it won&#8217;t be a good idea to use it as\u00a0 Vref for A\/D conversion. Using a lower and more stable Vref voltage can improve both the resolution and the accuracy of A\/D measurements. However, the datasheet of PIC16F688 microcontroller recommends to use reference voltage above 2.2 V to ensure 1 LSB accuracy of A\/D conversion. The MCP1525 IC from Microchip provides a precise output voltage of 2.5 V, which could serve this purpose. This device is also available in TO-92 package, and therefore, it can be wired on a breadboard too.<\/p>\n<p><strong>Circuit diagram<\/strong><\/p>\n<p>The revised circuit diagram of the project is shown below. All the connections remain the same, except the two diodes and a resistor in the original circuit are replaced by a MCP1525 device.<\/p>\n<div id=\"attachment_4009\" style=\"width: 560px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/RevisedLM35Circuit.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4009\" class=\"size-medium wp-image-4009\" title=\"RevisedLM35Circuit\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/RevisedLM35Circuit-550x366.jpg\" alt=\"\" width=\"550\" height=\"366\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/RevisedLM35Circuit-550x366.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/RevisedLM35Circuit.jpg 853w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><p id=\"caption-attachment-4009\" class=\"wp-caption-text\">Revised circuit diagram (click the image to enlarge)<\/p><\/div>\n<div id=\"attachment_4004\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/LM35_Setup.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4004\" class=\"size-full wp-image-4004\" title=\"LM35_Setup\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/LM35_Setup.jpg\" alt=\"\" width=\"560\" height=\"422\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/LM35_Setup.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/LM35_Setup-550x414.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-4004\" class=\"wp-caption-text\">MCP1525 used as a precision voltage reference for A\/D conversion<\/p><\/div>\n<p>The whole setup of this project is shown below. For illustrative purpose, I am using the LCD display from my <a title=\"DIY I\/O board for experimenters\" href=\"http:\/\/embedded-lab.com\/blog\/?p=3596\" target=\"_blank\"><strong>I\/O board project<\/strong><\/a> here. Don&#8217;t get confused with all the LEDs and tact switches on the board, they should be disregarded. I am only using the LCD part of it.<\/p>\n<div id=\"attachment_4005\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/WholeSetup.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4005\" class=\"size-full wp-image-4005\" title=\"WholeSetup\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/WholeSetup.jpg\" alt=\"\" width=\"570\" height=\"299\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/WholeSetup.jpg 570w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/WholeSetup-550x288.jpg 550w\" sizes=\"auto, (max-width: 570px) 100vw, 570px\" \/><\/a><p id=\"caption-attachment-4005\" class=\"wp-caption-text\">Complete circuit setup of the project<\/p><\/div>\n<p><strong>Software<\/strong><\/p>\n<p>With Vref = 2.5 V, the resolution of 10-bit A\/D conversion would be 2.5\/1024 ? 2.44 mV\/count. Which means,<\/p>\n<p><strong><span style=\"color: #073dd8;\">Resolution of temperature measurement = 2.44 mV\/(10 mV\/\u00b0C) = 0.244 \u00b0C<\/span><\/strong><\/p>\n<p><strong><span style=\"color: #073dd8;\">I\/P analog voltage = 2.44 x 10-bit count (mV)<\/span><\/strong><\/p>\n<p><strong><span style=\"color: #073dd8;\">Measured temperature = I\/P voltage (mV)\/(10 mV\/\u00b0C) = 2.44 x 10-bit count\/10 (\u00b0C)<\/span><\/strong><\/p>\n<p><strong><span style=\"color: #073dd8;\">Or, <em>T (\u00b0C) = 0.244 x 10-bit Count<\/em><br \/>\n<\/span><\/strong><\/p>\n<p>Floating point math can be avoided in programming to simplify the arithmetic. The complete program (source and HEX files) written in mikroC Pro for PIC can be downloaded from the following link.<\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/uploads\/HexFiles\/PIC16F688\/RevisedLM35Thermometer.zip\"><strong>Download mikroC source and HEX files\u00a0<\/strong><\/a><\/p>\n<p>The following snapshot of the <strong>Project Edit<\/strong> window from mikroC editor shows the configuration bit setting for this project.<\/p>\n<div id=\"attachment_4023\" style=\"width: 560px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/ConfigWord.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4023\" class=\"size-medium wp-image-4023\" title=\"ConfigWord\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/ConfigWord-550x351.jpg\" alt=\"\" width=\"550\" height=\"351\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/ConfigWord-550x351.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/ConfigWord.jpg 799w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><p id=\"caption-attachment-4023\" class=\"wp-caption-text\">Configuration bit settings for PIC16F688<\/p><\/div>\n<div id=\"attachment_4003-2\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/LM35_OP.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-4003-2\" class=\"size-full wp-image-4003\" title=\"LM35_OP\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/LM35_OP.jpg\" alt=\"\" width=\"560\" height=\"353\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/LM35_OP.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/11\/LM35_OP-550x346.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-4003-2\" class=\"wp-caption-text\">Digital thermometer using PIC16F688 and LM35<\/p><\/div>\n<p><strong>Additional Tip<\/strong><\/p>\n<p>The <a href=\"http:\/\/www.national.com\/ds\/LM\/LM61.pdf\" target=\"_blank\">LM61 sensor<\/a> is more\u00a0convenient\u00a0to use for measuring negative temperatures. Unlike LM35 (which has zero DC offset), the LM61 sensor has a DC offset of 600 mV, which allows reading negative temperatures without the need for a negative supply.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a revised version of my LM35 based digital thermometer\u00a0project that I posted last year. Although it is one of the simplest projects, it is very popular among newbies who are just starting to learn microcontrollers. There was a little flaw in the original project as pointed by some readers. I was using a 1.2 V reference for A\/D conversion with PIC16F688 microcontroller. However, the PIC16F688 datasheet says Vref should be equal to or higher than 2.2 V to ensure 1 LSB accuracy of A\/D conversion. Here, I am rewriting the same project but this time I am using<\/p>\n","protected":false},"author":1,"featured_media":4003,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[245,4],"tags":[306,92,372,370,20,371],"class_list":["post-4001","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-embedded-lab-projects","category-pic-projects","tag-digital-thermometer","tag-lm35","tag-lm61","tag-mcp1525","tag-pic16f688","tag-precision-voltage-reference"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/4001","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=4001"}],"version-history":[{"count":17,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/4001\/revisions"}],"predecessor-version":[{"id":5712,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/4001\/revisions\/5712"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/4003"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=4001"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=4001"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=4001"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}