{"id":563,"date":"2012-11-18T20:10:49","date_gmt":"2012-11-18T18:10:49","guid":{"rendered":"http:\/\/lallafa.de\/blog\/?p=563"},"modified":"2012-11-18T20:10:49","modified_gmt":"2012-11-18T18:10:49","slug":"build-an-arduino-based-temperature-logger","status":"publish","type":"post","link":"https:\/\/lallafa.de\/blog\/2012\/11\/build-an-arduino-based-temperature-logger\/","title":{"rendered":"Build an Arduino-based Temperature Logger"},"content":{"rendered":"<p>Ok, this time its no retro project, but a rather useful tool to measure your temperatue at home over a longer period of time. I had trouble with my heating devices at home and so I wanted to record and present temperature curves of various rooms to show that something is wrong&#8230;<\/p>\n<p>This was a friday night project and done in a few hours (some might call it a hardware hack &#8211; but it works fairly stable for weeks now!). All you need is an Arduino 2009 Board, a Logger Shield, a push button, 2 1k resistors, and a DS18S20 temperature sensor. With these ingredients I was able to build the following compact temperature logger:<\/p>\n<div id=\"attachment_564\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/datalog.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-564\" data-attachment-id=\"564\" data-permalink=\"https:\/\/lallafa.de\/blog\/2012\/11\/build-an-arduino-based-temperature-logger\/datalog\/\" data-orig-file=\"https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/datalog.jpg?fit=640%2C528&amp;ssl=1\" data-orig-size=\"640,528\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;Canon EOS 650D&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1353262574&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;37&quot;,&quot;iso&quot;:&quot;1000&quot;,&quot;shutter_speed&quot;:&quot;0.016666666666667&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"datalogger\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;Arduino and Logger Shield&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/datalog.jpg?fit=300%2C247&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/datalog.jpg?fit=584%2C482&amp;ssl=1\" class=\"size-medium wp-image-564\" title=\"datalogger\" src=\"https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/datalog-300x247.jpg?resize=300%2C247\" alt=\"\" width=\"300\" height=\"247\" srcset=\"https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/datalog.jpg?resize=300%2C247&amp;ssl=1 300w, https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/datalog.jpg?resize=150%2C123&amp;ssl=1 150w, https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/datalog.jpg?resize=400%2C330&amp;ssl=1 400w, https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/datalog.jpg?w=640&amp;ssl=1 640w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-564\" class=\"wp-caption-text\">Arduino and Logger Shield: Temperature Logger<\/p><\/div>\n<p>The logger samples the temperature every 10s and gives you a digital temperature value with +\/-0.5 degree Celsius precision. It has a RTC (real-time-clock) on board that time stamps every measurement. Addionally, the SD card allows you to store the temperature samples in log files.<\/p>\n<p>The logger has two modes of operation: Either directly read the temperature via a Mac\/PC connected via the virtual serial port available on USB or write a temperature log onto the SD card. The latter mode allows you to use the device stand alone in any room without the need to directly connect your computer.<\/p>\n<p>Read on for the full build and usage instructions&#8230;<\/p>\n<h3><!--more-->1. Hardware<\/h3>\n<p>You need:<\/p>\n<ul>\n<li>an Arduino board (I use an <a href=\"http:\/\/www.arduino.cc\/en\/Main\/ArduinoBoardDuemilanove\">Arduino 2009<\/a> but UNO will be fine, too)<\/li>\n<li>an <a href=\"http:\/\/www.ladyada.net\/make\/logshield\/\">Adafruit Logger Shield<\/a><\/li>\n<li>a push button (to toggle SD card recording)<\/li>\n<li>a DS18S20 digital temperature sensor<\/li>\n<li>2 1k resistors<\/li>\n<\/ul>\n<p>Use the prototyping area of the Logger Shield to attach the push button and the DS18S20. The following <a href=\"http:\/\/fritzing.org\/\">fritzing.org<\/a> schematic shows you the required connections:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/datalog.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"565\" data-permalink=\"https:\/\/lallafa.de\/blog\/2012\/11\/build-an-arduino-based-temperature-logger\/datalog-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/datalog.png?fit=480%2C473&amp;ssl=1\" data-orig-size=\"480,473\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"datalog\" data-image-description=\"&lt;p&gt;Temperature Logger Schematic&lt;\/p&gt;\n\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/datalog.png?fit=300%2C295&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/datalog.png?fit=480%2C473&amp;ssl=1\" class=\"aligncenter size-full wp-image-565\" title=\"datalog\" src=\"https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/datalog.png?resize=480%2C473\" alt=\"\" width=\"480\" height=\"473\" srcset=\"https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/datalog.png?w=480&amp;ssl=1 480w, https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/datalog.png?resize=300%2C295&amp;ssl=1 300w, https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/datalog.png?resize=150%2C147&amp;ssl=1 150w, https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/datalog.png?resize=400%2C394&amp;ssl=1 400w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/a>Note: the LEDs and the associated resistors are already available on the logger shield. You only have to connect them to the Arduino on DIGITAL 3 and DIGITAL 4 pins. The LED pins have connectors right beside the two DIGITAL ports. So two small wire bridges will connect them. The push button is connected to DIGITAL 2 and the temperature sensors data channel to DIGITAL 7. The temperate one-wire bus needs a 1k pull up to 5V while the push button uses a 1k pull down resistor.<\/p>\n<p>Here is a summary of the connected digital ports:<\/p>\n<ul>\n<li>DIGITAL 2: push button input<\/li>\n<li>DIGITAL 3: LED (green) output<\/li>\n<li>DIGITAL 4: LED (red) output<\/li>\n<li>DIGITAL 7: temperature sensors DS18S20 DQ data channel<\/li>\n<\/ul>\n<p>That&#8217;s it for the hardware&#8230; and don&#8217;t forget to add a battery for the RTC (real time clock).<\/p>\n<h3>2. Software<\/h3>\n<h4>2.1 Firmware<\/h4>\n<p>The firmware is hosted on my github site:<\/p>\n<ul>\n<li>GitHub: <a href=\"https:\/\/github.com\/cnvogelg\/ardu\">ardu.git<\/a><\/li>\n<li>\n<pre>git clone git:\/\/github.com\/cnvogelg\/ardu.git<\/pre>\n<\/li>\n<\/ul>\n<p>Simply clone this repository and have a look in the <strong>datalog<\/strong> directory:<\/p>\n<p>The file <strong>datalog.ino<\/strong> is an <a href=\"http:\/\/arduino.cc\/en\/Main\/Software\">Arduino IDE<\/a> sketch you can directly open there.<\/p>\n<p><strong>Note:<\/strong> the sketch requires the RTC and SD FAT FS library that is available at Ladyada for the Logger Shield: see the <a href=\"http:\/\/www.ladyada.net\/make\/logshield\/download.html\">Logger Shied Download<\/a> page for details and install the libraries first!<\/p>\n<p>Open the sketch and flash it on your device&#8230;<\/p>\n<h4>2.2 Configuration<\/h4>\n<p>Before you can use the data logger you have to configure it:<\/p>\n<ul>\n<li>In the Arduino IDE open the <strong>serial monitor<\/strong> (Tools -&gt; Serial Monitor) with <strong>57000 Baud<\/strong> and Line Ending <strong>Both NL+CR<\/strong><\/li>\n<li>Insert a FAT formatted SD card and power the device<\/li>\n<li>If the green LED is enabled then everything is fine and SD and temperature sensor was detected. You can see the serial number of your sensor:<\/li>\n<\/ul>\n<pre>DS18S20: 10 83 B4 8D 2 8 0<\/pre>\n<ul>\n<li>If the red LED blinks then an error has occurred:\n<ul>\n<li>Either the sensor was not detected:<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre>FATAL: ADDR?\r\n<\/pre>\n<ul>\n<li>\n<ul>\n<li>Or the SD card was not found:<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre>FATAL: SD\r\n<\/pre>\n<ul>\n<li>\n<ul>\n<li>In both cases have a look at your wiring or your card to fix this&#8230;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Now we are ready to set up the RTC (real time clock):<\/p>\n<ul>\n<li>You can enter commands in the Serial Monitor and send them to the device<\/li>\n<li>The following commands are supported:\n<ul>\n<li>&#8216;r&#8217; &#8211; read clock (load time and date from RTC chip and print it)<\/li>\n<li>&#8216;a&#8217; &#8211; adjust clock (save the current values for year, month, day, hour, minutes, seconds to RTC chip)<\/li>\n<li>&#8216;y&#8217; &lt;nnnn&gt; &#8211; set year: 2012 &#8230;<\/li>\n<li>&#8216;m&#8217; &lt;nn&gt; &#8211; set month: 01 .. 12<\/li>\n<li>&#8216;d&#8217; &lt;nn&gt; &#8211; set day of month: 01 .. 31<\/li>\n<li>&#8216;H&#8217; &lt;nn&gt; &#8211; set hour: 00 .. 23<\/li>\n<li>&#8216;M&#8217; &lt;nn&gt; &#8211; set minute: 00 .. 59<\/li>\n<li>&#8216;S&#8217; &lt;nn&gt; &#8211; set seconds: 00 .. 59<\/li>\n<li>&#8216;o&#8217; &#8211; open log on SD card for writing<\/li>\n<li>&#8216;c&#8217; &#8211; close open log on SD card and stop writing<\/li>\n<li>&#8216;D&#8217; &lt;nnnn&gt; &#8211; interval of measurements in seconds. default: 10s<\/li>\n<\/ul>\n<\/li>\n<li>So for setting up the clock to: <strong>28.11.2012 18:34:20<\/strong> you would enter:<\/li>\n<\/ul>\n<pre>y2012\r\nm11\r\nd28\r\nH18\r\nM34\r\nS20\r\na\r\n<\/pre>\n<ul>\n<li>Now your RTC is set up and you should see incoming measurements like this one<\/li>\n<\/ul>\n<pre>t: 2012.11.18 19:39:03 50A93957 +024.50 0189\r\nt: 2012.11.18 19:39:13 50A93961 +024.50 0189\r\nt: 2012.11.18 19:39:23 50A9396B +024.50 0188<\/pre>\n<ul>\n<li>Each line has the following columns:\n<ul>\n<li>date and time<\/li>\n<li>raw date and time in hex<\/li>\n<li>temperature value in degree celsuis<\/li>\n<li>raw temperature value in hex<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>3. Stand-alone operation<\/h3>\n<p>Start Logging:<\/p>\n<ul>\n<li>Detach the Arduino from your Mac\/PC<\/li>\n<li>Use a USB power-supply to power the logger now<\/li>\n<li>Make sure the green LED is enabled after power on (SD card is attached and sensor is OK).<\/li>\n<li>Now <strong>press the push button<\/strong> to start the logging operation<\/li>\n<li>The red LED is enabled and shows you that data is written to SD card<\/li>\n<li>Each time the green LED blinks a measurement is taken and written to the log file<\/li>\n<\/ul>\n<p>End Logging:<\/p>\n<ul>\n<li>After a while stop logging by pressing the push button again<\/li>\n<li>The red LED now is disabled and logging has stopped<\/li>\n<li>Now you can safely remove the SD card and have a look at your data<\/li>\n<li><strong>Note:<\/strong> do never remove the SD card while the red LED is on this might corrupt your data on the card!<\/li>\n<li>On the SD card a data file is always named <strong>yymmdd_s.LOG<\/strong> with yymmdd being the current date and s a letter starting from A that is incremented with every new log<\/li>\n<\/ul>\n<h3>4. Plot a Temperature Graph<\/h3>\n<p>You can now use your favorite spread sheet application or graphing tool to convert the data log files from the SD card to pictures.<\/p>\n<p>In my code repository I have written a small Python script that uses <a href=\"http:\/\/oss.oetiker.ch\/rrdtool\/\">rrdtool<\/a> to plot the graphs (see <a href=\"https:\/\/github.com\/cnvogelg\/ardu\/blob\/master\/datalog\/tools\/plot_log.py\">datalog\/tools\/plot_log.py<\/a>):<\/p>\n<p>Run it as follows:<\/p>\n<pre>python2.7 plot_log.py .\/plot_log.py 121104_A.LOG out.png<\/pre>\n<p>This will create an image like this:<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/out2.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"568\" data-permalink=\"https:\/\/lallafa.de\/blog\/2012\/11\/build-an-arduino-based-temperature-logger\/out2\/\" data-orig-file=\"https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/out2.png?fit=847%2C259&amp;ssl=1\" data-orig-size=\"847,259\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"out2\" data-image-description=\"&lt;p&gt;Temperate Graph created with RRDTool&lt;\/p&gt;\n\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/out2.png?fit=300%2C91&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/out2.png?fit=584%2C179&amp;ssl=1\" class=\"aligncenter size-medium wp-image-568\" title=\"out2\" src=\"https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/out2-300x91.png?resize=584%2C177\" alt=\"\" width=\"584\" height=\"177\" srcset=\"https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/out2.png?resize=300%2C91&amp;ssl=1 300w, https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/out2.png?resize=150%2C45&amp;ssl=1 150w, https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/out2.png?resize=400%2C122&amp;ssl=1 400w, https:\/\/i0.wp.com\/lallafa.de\/blog\/wp-content\/uploads\/2012\/11\/out2.png?w=847&amp;ssl=1 847w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/><\/a><\/p>\n<p>Now, have fun building your own device and inspecting your home&#8217;s temperature \ud83d\ude42<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ok, this time its no retro project, but a rather useful tool to measure your temperatue at home over a longer period of time. I had trouble with my heating devices at home and so I wanted to record and &hellip; <a href=\"https:\/\/lallafa.de\/blog\/2012\/11\/build-an-arduino-based-temperature-logger\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"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":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[8,6,1],"tags":[],"class_list":["post-563","post","type-post","status-publish","format-standard","hentry","category-hardware","category-mac-stuff","category-misc"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/piBMF-95","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts\/563","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/comments?post=563"}],"version-history":[{"count":5,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts\/563\/revisions"}],"predecessor-version":[{"id":571,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/posts\/563\/revisions\/571"}],"wp:attachment":[{"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/media?parent=563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/categories?post=563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lallafa.de\/blog\/wp-json\/wp\/v2\/tags?post=563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}