{"id":5453,"date":"2012-07-13T18:50:36","date_gmt":"2012-07-13T22:50:36","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=5453"},"modified":"2012-11-06T13:38:39","modified_gmt":"2012-11-06T18:38:39","slug":"chipkit-project-2-temperature-and-relative-humidity-logger","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/chipkit-project-2-temperature-and-relative-humidity-logger\/","title":{"rendered":"chipKIT Project 2: Temperature and relative humidity logger"},"content":{"rendered":"<p>This project is about building a PC-based temperature and relative humidity logger using the chipKIT Uno32 board and the DHT11 sensor. The project setup requires no additional wires (other than the USB cable) and components; the DHT11 sensor is directly plugged into four I\/O pins of the Uno32 board and the project is ready to go. This could be a handy and an easiest way to setup an ambient room monitoring system for a server room. The Uno32 reads the temperature and relative humidity from the DHT11 sensor at preset interval and sends the data to PC through the USB-UART interface. A PC application is developed using the open-source Processing programming platform to log data onto an ASCII file. The PC application also displays the real-time temperature and relative humidity on computer screen.<\/p>\n<div id=\"attachment_5465\" style=\"width: 575px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/06\/P2_TRH_Title.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5465\" class=\"size-full wp-image-5465\" title=\"P2_TRH_Title\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/06\/P2_TRH_Title.jpg\" alt=\"\" width=\"565\" height=\"320\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/06\/P2_TRH_Title.jpg 565w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/06\/P2_TRH_Title-550x311.jpg 550w\" sizes=\"auto, (max-width: 565px) 100vw, 565px\" \/><\/a><p id=\"caption-attachment-5465\" class=\"wp-caption-text\">PC-based logger for temperature and relative humidity<\/p><\/div>\n<p><!--more--><strong>Theory<\/strong><\/p>\n<p>DHT11 is an inexpensive sensor that provides calibrated digital outputs for ambient temperature and relative humidity. It\u00a0comes in a single row 4-pin package and\u00a0operates from 3 to 5.5V power supply. It can measure temperature from 0-50 \u00b0C with an accuracy of \u00b12\u00b0C and relative humidity ranging from 20-95% with an accuracy of \u00a0\u00b15%. It has got its own proprietary 1-wire protocol, and therefore, the communication between the sensor and a microcontroller is not possible through a direct interface with any of its peripherals. The protocol must be implemented in the firmware of the MCU through bit-banging of an I\/O pin. Please read<br \/>\n<strong><a href=\"http:\/\/embedded-lab.com\/blog\/?p=4333\"> Measurement of temperature and relative humidity using DHT11 sensor and PIC microcontroller<\/a><\/strong> for more details on the DHT11 communication protocol. The following picture describes the four pins of the DHT11 sensor.<\/p>\n<div id=\"attachment_5600\" style=\"width: 526px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/07\/DHT11_Pins.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5600\" class=\"size-full wp-image-5600\" title=\"DHT11_Pins\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/07\/DHT11_Pins.png\" alt=\"\" width=\"516\" height=\"378\" \/><\/a><p id=\"caption-attachment-5600\" class=\"wp-caption-text\">DHT11 pins<\/p><\/div>\n<p style=\"text-align: left;\">In this project, four pins of the DHT11 sensor is directly inserted into four I\/O pins (7, 6, 5, and 4) of the Uno32 board. The power supply (1), data (2), and ground (4) pins of DHT11 go to I\/O pins 7, 6, and 5 of the Uno32, respectively. The Uno32 pins 7 and 4 are configured as output pins and are set to <strong>High (3.3V)<\/strong> and <strong>Low (Gnd)<\/strong>, respectively, through software to power the DHT11 sensor. Note that an I\/O pin of Uno32 can source up to 18mA current that is sufficient to power the DHT11 sensor, which only requires less than 5mA during data conversion and transfer. Pin 3 of DHT11 is unused. Temperature and humidity bytes are read through I\/O pin 6 of the Uno32.<\/p>\n<div id=\"attachment_5602\" style=\"width: 575px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/07\/InsertDHT11.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5602\" class=\"size-full wp-image-5602\" title=\"InsertDHT11\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/07\/InsertDHT11.jpg\" alt=\"\" width=\"565\" height=\"427\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/07\/InsertDHT11.jpg 565w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/07\/InsertDHT11-550x415.jpg 550w\" sizes=\"auto, (max-width: 565px) 100vw, 565px\" \/><\/a><p id=\"caption-attachment-5602\" class=\"wp-caption-text\">Inserting DHT11 on to I\/O pins 7-4 of Uno32<\/p><\/div>\n<div id=\"attachment_5466\" style=\"width: 575px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/06\/P2_TRHSetup.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5466\" class=\"size-full wp-image-5466\" title=\"P2_TRHSetup\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/06\/P2_TRHSetup.jpg\" alt=\"\" width=\"565\" height=\"442\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/06\/P2_TRHSetup.jpg 565w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/06\/P2_TRHSetup-550x430.jpg 550w\" sizes=\"auto, (max-width: 565px) 100vw, 565px\" \/><\/a><p id=\"caption-attachment-5466\" class=\"wp-caption-text\">Complete setup of the project<\/p><\/div>\n<p><strong>chipKIT sketch<\/strong><\/p>\n<p>Writing firmware is easier with the use of the DHT11 library available for Arduino or chipKIT platform. The DHT11 library for Arduino was originally written by George Hadjikyriacou and was later modified by other people. Make sure you include the library in your chipKIT sketch. The following sketch is for Uno32 to read the temperature and relative humidity data (two bytes) from the DHT11 and send them over the serial port. The sampling interval is set to 2 seconds.<\/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 2:   PC-based temperature and humidity logger\n  Description: The DHT11 sensor is used to measure the ambient\n               temperature and relative humidity. The measured\n               values are displayed on a PC and logged into a ASCII\n               file through an application written using Processing.\n  Board: chipKIT UNO32\n *\/<\/span>\n<span style=\"color: #339933;\">#include &quot;dht11.h&quot;<\/span>\n&nbsp;\n<span style=\"color: #339933;\">#define VCCPIN      7<\/span>\n<span style=\"color: #339933;\">#define DHT11PIN    6<\/span>\n<span style=\"color: #339933;\">#define GNDPIN      4<\/span>\ndht11 DHT11<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>\n<span style=\"color: #009900;\">&#123;<\/span>\n  Serial.<span style=\"color: #202020;\">begin<\/span><span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">9600<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  pinMode<span style=\"color: #009900;\">&#40;<\/span>VCCPIN<span style=\"color: #339933;\">,<\/span> OUTPUT<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  pinMode<span style=\"color: #009900;\">&#40;<\/span>GNDPIN<span style=\"color: #339933;\">,<\/span> OUTPUT<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  digitalWrite<span style=\"color: #009900;\">&#40;<\/span>VCCPIN<span style=\"color: #339933;\">,<\/span> HIGH<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  digitalWrite<span style=\"color: #009900;\">&#40;<\/span>GNDPIN<span style=\"color: #339933;\">,<\/span> LOW<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #009900;\">&#125;<\/span><span style=\"color: #808080; font-style: italic;\">\/*--(end setup )---*\/<\/span>\n&nbsp;\n<span style=\"color: #993333;\">void<\/span> loop<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span>\n<span style=\"color: #009900;\">&#123;<\/span>\n  <span style=\"color: #993333;\">int<\/span> chk <span style=\"color: #339933;\">=<\/span> DHT11.<span style=\"color: #202020;\">read<\/span><span style=\"color: #009900;\">&#40;<\/span>DHT11PIN<span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  Serial.<span style=\"color: #202020;\">write<\/span><span style=\"color: #009900;\">&#40;<\/span>DHT11.<span style=\"color: #202020;\">humidity<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n  Serial.<span style=\"color: #202020;\">write<\/span><span style=\"color: #009900;\">&#40;<\/span>DHT11.<span style=\"color: #202020;\">temperature<\/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><a href=\"http:\/\/www.embedded-lab.com\/uploads\/chipKIT\/P2_TRHlogger.zip\"><strong>Download the complete chipKIT sketch and library files<\/strong><\/a><\/p>\n<p>On PC\u2019s side, the open source programming language Processing is used to develop an graphical application to display the received temperature and humidity information. <strong><a href=\"http:\/\/processing.org\/\" target=\"_blank\">Processing<\/a><\/strong>\u00a0is an open-source software development environment designed for simplifying the process of creating digital images, animations and interactive graphical applications. It is free to\u00a0<strong><a href=\"http:\/\/processing.org\/download\/\" target=\"_blank\">download<\/a><\/strong>\u00a0and operates on Mac, Windows, and Linux platforms. I have written a simple application here that\u00a0receives the temperature and humidity bytes sent by the Uno32 board through the serial port, and display those information on a graphical window. The data logging part records the temperature and humidity samples plus date and time stamps on an ASCII file. The date and time are based on the PC&#8217;s RTC.<\/p>\n<p>You should import the Processing Serial library first before accessing the serial port. This can be done by,<\/p>\n<pre>import processing.serial.*;<\/pre>\n<p>Next, you can open a serial port as<\/p>\n<pre>Dev_Board = new Serial(this, \"COM12\", 9600);<\/pre>\n<p>In my case the USB-UART module on Uno32 board appears as COM12. You should find the right COM number to make it work for you. In Windows machine, you can find this information from the Device Manager tool.<\/p>\n<p>A clickable Start\/Stop button is provided on the display window. The\u00a0<em>Processing Mouse<\/em> functions are used to detect a mouse press over the button. When the Start is pressed, data logging begins and the label on the button changes to \u2018Stop\u2019. If Stop is pressed, the data logging is paused. The temperature samples are recorded along with the date and time stamp (from PC) into an ASCII file. Every time the Start is pressed, the program creates a new ASCII log file. The name of the file contains the current system date and time so that there won\u2019t be any overwriting of files. However, the data are temporarily stored into the PC\u2019s RAM and are transferred to the ASCII file on the hard drive only after pressing the Stop button.<\/p>\n<p><strong><a href=\"http:\/\/www.embedded-lab.com\/uploads\/Processing\/P2_DHT11_logger.zip\">Download the Processing source and applications<\/a><\/strong><\/p>\n<p>The following picture is a screenshot of the output window on PC.<\/p>\n<div id=\"attachment_5464\" style=\"width: 503px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/06\/P2_TRH_OP.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5464\" class=\"size-full wp-image-5464\" title=\"P2_TRH_OP\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/06\/P2_TRH_OP.png\" alt=\"\" width=\"493\" height=\"419\" \/><\/a><p id=\"caption-attachment-5464\" class=\"wp-caption-text\">Output on computer screen<\/p><\/div>\n<p>Here&#8217;s a sample of the output ASCII file where the temperature and relative humidity information are logged along with the time stamps.<\/p>\n<div id=\"attachment_5606\" style=\"width: 487px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/07\/OP_TextFile.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-5606\" class=\"size-full wp-image-5606\" title=\"OP_TextFile\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2012\/07\/OP_TextFile.jpg\" alt=\"\" width=\"477\" height=\"354\" \/><\/a><p id=\"caption-attachment-5606\" class=\"wp-caption-text\">Output record file<\/p><\/div>\n<p>The data from the log file can be read and plotted to generate graph using applications like MS Excel, or even the given Processing code can be modified further to plot the temperature and relative humidity vs time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This project is about building a PC-based temperature and relative humidity logger using the chipKIT Uno32 board and the DHT11 sensor. The project setup requires no additional wires (other than the USB cable) and components; the DHT11 sensor is directly plugged into four I\/O pins of the Uno32 board and the project is ready to go. This could be a handy and an easiest way to setup an ambient room monitoring system for a server room. The Uno32 reads the temperature and relative humidity from the DHT11 sensor at preset interval and sends the data to PC through the USB-UART<\/p>\n","protected":false},"author":1,"featured_media":5463,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[401,245],"tags":[1314,16,392,1313,435],"class_list":["post-5453","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chipkit","category-embedded-lab-projects","tag-chipkit","tag-data-logger","tag-dht11","tag-processing","tag-uno32"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/5453","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=5453"}],"version-history":[{"count":19,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/5453\/revisions"}],"predecessor-version":[{"id":6253,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/5453\/revisions\/6253"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/5463"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=5453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=5453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=5453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}