{"id":5727,"date":"2019-08-27T04:34:42","date_gmt":"2019-08-27T04:34:42","guid":{"rendered":"https:\/\/max-drake.cc\/?p=5727"},"modified":"2019-08-30T03:49:01","modified_gmt":"2019-08-30T03:49:01","slug":"raspberry-pi-and-temperature-sensor-ds1820","status":"publish","type":"post","link":"https:\/\/max-drake.cc\/?p=5727","title":{"rendered":"Raspberry Pi and temp sensor DS18B20 part 1"},"content":{"rendered":"\n<p>I&#8217;ve been keen to do some temperature monitoring. This is IoT basics 101. I thought of a use case for my Beer Brewing. <\/p>\n\n\n\n<p> Jaycar  had DS18B20  temperature sensors at  $7.90$ NZ each. They are cheaper than the  DH11 &amp; DH22 which are more expensive as they do humidity as well.<\/p>\n\n\n\n<p>So I thought I&#8217;d start off with these units. So found a couple of tutorials online: <\/p>\n\n\n\n<p>Tutorial 1-<strong><a rel=\"noreferrer noopener\" aria-label=\"Measuring Temperature with a Raspberry Pi Temperature Sensor (1-Wire)  (opens in a new tab)\" href=\"https:\/\/tutorials-raspberrypi.com\/raspberry-pi-temperature-sensor-1wire-ds18b20\/\" target=\"_blank\">Measuring Temperature with a Raspberry Pi Temperature Sensor (1-Wire) <\/a><\/strong>and <\/p>\n\n\n\n<p>Tutorial 2- <strong><a rel=\"noreferrer noopener\" aria-label=\"DS18B20+ One Wire Digital Temperature Sensor and the Raspberry Pi (opens in a new tab)\" href=\"https:\/\/thepihut.com\/blogs\/raspberry-pi-tutorials\/ds18b20-one-wire-digital-temperature-sensor-and-the-raspberry-pi\" target=\"_blank\">DS18B20+ One Wire Digital Temperature Sensor and the Raspberry Pi<\/a><\/strong>. <\/p>\n\n\n\n<p>Tutorial 3- <strong><a href=\"http:\/\/www.projects.privateeyepi.com\/home\/temperature-sensor-project-using-ds18b20\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Temperature Sensor Project using DS18B20 (opens in a new tab)\">Temperature Sensor Project using DS18B20<\/a><\/strong>.<\/p>\n\n\n\n<p>The interactive RPi<a rel=\"noreferrer noopener\" aria-label=\" pinout for gpio (opens in a new tab)\" href=\"https:\/\/pinout.xyz\/#\" target=\"_blank\"> <strong>pinout for gpio<\/strong><\/a> is quite handy.<\/p>\n\n\n\n<p>I have since found the <a rel=\"noreferrer noopener\" aria-label=\"data sheet of the DS1820 (opens in a new tab)\" href=\"https:\/\/www.jaycar.co.nz\/medias\/sys_master\/images\/9292327976990\/XC3700-dataSheetMain.pdf\" target=\"_blank\">dat<strong>a sheet of the DS18B20<\/strong><\/a>. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Part 1- Abject failure-breaking the temperature sensors<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"768\" height=\"1024\" data-src=\"https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190827_161632_resized_20190827_041918673-768x1024.jpg\" alt=\"\" class=\"wp-image-5728 lazyload\" data-srcset=\"https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190827_161632_resized_20190827_041918673-768x1024.jpg 768w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190827_161632_resized_20190827_041918673-225x300.jpg 225w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190827_161632_resized_20190827_041918673-100x133.jpg 100w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190827_161632_resized_20190827_041918673-75x100.jpg 75w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190827_161632_resized_20190827_041918673-480x640.jpg 480w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190827_161632_resized_20190827_041918673-640x853.jpg 640w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190827_161632_resized_20190827_041918673-576x768.jpg 576w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190827_161632_resized_20190827_041918673-810x1080.jpg 810w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190827_161632_resized_20190827_041918673.jpg 864w\" data-sizes=\"(max-width: 768px) 100vw, 768px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 768px; --smush-placeholder-aspect-ratio: 768\/1024;\" \/><\/figure>\n\n\n\n<p>To begin with I looked on YouTube but got confused with some of their setups and they were not using breadboards, or had LED screens which increased the complexity of the wiring. So I looked at the first tutorial and sort of looked at the breadboard\/wiring layout and followed that (but missed the black wire to GPIO 6, so when I came to look in the <em>\/<strong>sys\/bus\/w1\/devices\/<\/strong><\/em> directory there were no files there. <\/p>\n\n\n\n<p>So I went on to tutorial 2 and tried to wire up to that one. I had all the wires but then started to reverse them and the temperature sensor started to get hot. I had 2 temp sensors and basically have moggerdored them both. I think I&#8217;ve burned them out. <\/p>\n\n\n\n<p>The 2nd tutorial at least used Live\/Ground and after reviewing the data sheet I can see NOW which pin should have gone where. <\/p>\n\n\n\n<p>So for the time being an expensive mistake. $16 NZ down the drain and nothing to show for it. <\/p>\n\n\n\n<p>I have ordered a multi sensor pack online to play with but that wont come for a few weeks, so I have time to dwell on being a bit less cavalier about the wiring. <\/p>\n\n\n\n<p>Things to think about: <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>See if I can understand the wiring diagram first in relation to the sensors before buggering them up. <\/li><li>Do some testing with the breadboard or get thicker wires. Some of the wiring seemed very loose so I thought that there was not a circuit. <\/li><li>Maybe get some LED&#8217;s to put in part of the circuit to check that the connections do work. <\/li><li>Try tutorial 3 above. This one does not use breadboard but will be the final wiring for the sensors. Its also good for 2 or more sensors. So may be worth pursuing. <\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Now I have to wait for some more sensors and proceed more slowly<\/h2>\n\n\n\n<p>Maybe I was over confident with proceeding, although I did turn the Pi off while I did the first wiring up. I had such easy success with the camera module. Now I&#8217;m $16NZ poorer and no further ahead.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">New sensors Friday 30th August<\/h3>\n\n\n\n<p>I bought a couple of   DS18B20  online from a NZ outlet, they looked quite reasonable, they were the bare bones temperature sensor, a black blob with 3 wires sticking out, but I got done on delivery prices, so in the end not much less than what I could have got in Jaycar, these ones were about $6.50 with out the board and LED light. Ce la vie.<\/p>\n\n\n\n<p>I ended up wiring the first one up wrong AGAIN. I seem to be dyslexic with the pins for some reason, anyway, if it gets hot and smells, its the wrong way around. <\/p>\n\n\n\n<p>This time it created a sub-directory after adding the extra line in the config.txt file but it did not initially have the sensor directory. So that took a few re-boots to get those to work, but I finally got there. <\/p>\n\n\n\n<p>I finally used a bit of a sticker to mark the Ground prong from the thermometer sensor and things went fine after that. <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"1024\" height=\"720\" data-src=\"https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/00073727-1024x720.jpg\" alt=\"\" class=\"wp-image-5733 lazyload\" data-srcset=\"https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/00073727-1024x720.jpg 1024w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/00073727-300x211.jpg 300w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/00073727-768x540.jpg 768w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/00073727-100x70.jpg 100w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/00073727-142x100.jpg 142w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/00073727-910x640.jpg 910w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/00073727-640x450.jpg 640w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/00073727-1093x768.jpg 1093w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/00073727-1536x1080.jpg 1536w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/00073727.jpg 1885w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/720;\" \/><\/figure>\n\n\n\n<p>I now have 2 sensors working in parallel sending results to files w1_slave in the specific sensor directory. <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"1024\" height=\"768\" data-src=\"https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190830_153700_resized_20190830_033732173-1024x768.jpg\" alt=\"\" class=\"wp-image-5734 lazyload\" data-srcset=\"https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190830_153700_resized_20190830_033732173-1024x768.jpg 1024w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190830_153700_resized_20190830_033732173-300x225.jpg 300w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190830_153700_resized_20190830_033732173-768x576.jpg 768w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190830_153700_resized_20190830_033732173-100x75.jpg 100w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190830_153700_resized_20190830_033732173-133x100.jpg 133w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190830_153700_resized_20190830_033732173-853x640.jpg 853w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190830_153700_resized_20190830_033732173-640x480.jpg 640w, https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190830_153700_resized_20190830_033732173.jpg 1152w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/768;\" \/><figcaption>2 sensors- I&#8217;m using a sticker to make sure I know which one is Ground. <\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">End comment<\/h3>\n\n\n\n<p>That took a lot of breakages to get a couple of temperature sensors working. I can only get their output by interrogating the file, so it is a live temp. It is not saving any data anywhere at this point. <\/p>\n\n\n\n<p>The next part of the process is to explore methods to log the data over time, say, take a reading every minute\/5 minutes etc and store that data somewhere. <\/p>\n\n\n\n<p>Also to send the data to another computer using MQTT or something similar. Initially I might use the cloud to act as a broker, then later install the broker on the RPi. <\/p>\n\n\n\n<p>Overall a success for the first step, but it was not as simple as I thought. <strong>Lessons learnt? <\/strong>Be very careful about pins on sensors &amp; wiring things up. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been keen to do some temperature monitoring. This is IoT basics 101. I thought of a use case for my Beer Brewing. Jaycar had DS18B20 temperature sensors at $7.90$ NZ each. They are cheaper than the DH11 &amp; DH22 which are more expensive as they do humidity as well. So I thought I&#8217;d start [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5728,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[204,443],"tags":[],"class_list":["post-5727","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-automation","category-iot-internet-of-things"],"featured_image_src":"https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190827_161632_resized_20190827_041918673.jpg","featured_image_src_square":"https:\/\/max-drake.cc\/wp-content\/uploads\/2019\/08\/IMG_20190827_161632_resized_20190827_041918673.jpg","author_info":{"display_name":"Max Drake","author_link":"https:\/\/max-drake.cc\/?author=1"},"_links":{"self":[{"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/posts\/5727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5727"}],"version-history":[{"count":0,"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/posts\/5727\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/media\/5728"}],"wp:attachment":[{"href":"https:\/\/max-drake.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}