{"id":1471,"date":"2020-06-05T06:20:00","date_gmt":"2020-06-05T04:20:00","guid":{"rendered":"https:\/\/pa3csg.nl\/?page_id=1471"},"modified":"2020-06-05T06:31:44","modified_gmt":"2020-06-05T04:31:44","slug":"arduino-temperature-humidity-and-pressure-sketch","status":"publish","type":"page","link":"https:\/\/pa3csg.nl\/?page_id=1471","title":{"rendered":"Arduino temperature, humidity and pressure sketch"},"content":{"rendered":"<p>I wanted to have a temperature and humidity and pressure measurement in the shack. There was a load of information on the net. I went for and BMP280 sensor and added a DHT11 sensor. Adapted the software a bit and there we go.<\/p>\n<p>This time no pics, no schematic just the sketch.<\/p>\n<p>&nbsp;<\/p>\n<p>\/\/https:\/\/create.arduino.cc\/projecthub\/Noshirt\/arduino-weather-station-v1-0-bmp280-050e01<br \/>\n\/\/ Expanded with DHT11 humidity sensor and adapted LCD display by PA3CSG june 2020<\/p>\n<p>#include &lt;LiquidCrystal.h&gt; \/\/Library for the LCD screen<br \/>\n#include &lt;BMP280.h&gt; \/\/ Library for the BMP280 sensor<br \/>\n#include &lt;SimpleDHT.h&gt;<\/p>\n<p>BMP280 bmp; \/\/Initialize your sensor<\/p>\n<p>LiquidCrystal lcd(12, 11, 5, 4, 3, 2); \/*Initialize your LCD, make sure you wired it correctly *\/<\/p>\n<p>#define P0 1013.25 \/\/Standard atmospheric pressure<br \/>\n#define contrast 9 \/\/9 and 10 are the pins where you wire the matching LCD pins<br \/>\n#define brightness 10 \/\/for contrast and brightness regulation<\/p>\n<p>double T = 0; \/\/Starting temperature value<br \/>\ndouble P = 0; \/\/Starting pressure value<br \/>\nchar measure = 0;<\/p>\n<p>\/\/ Initialize humidity sensor.<br \/>\nconst int pinDHT11 = 8;<br \/>\nSimpleDHT11 dht11;<\/p>\n<p>void collectData() {<br \/>\nmeasure = bmp.startMeasurment();<br \/>\nif (measure != 0) {<br \/>\ndelay(measure);<br \/>\nmeasure = bmp.getTemperatureAndPressure(T, P);<br \/>\nif (measure != 0) {<br \/>\nP = P + 17; \/\/ &#8216;+17&#8217; is a correction for the sensor error<br \/>\nT = T &#8211; 0.8; \/\/ like said above<\/p>\n<p>\/\/ Read sensor data and store results<br \/>\n\/\/ in temperature\/humidity variables<br \/>\nbyte temperature = 0;<br \/>\nbyte humidity = 0;<br \/>\ndht11.read(pinDHT11, &amp;temperature, &amp;humidity, NULL);<br \/>\nlcd.clear();<br \/>\nlcd.setCursor(0,0);<br \/>\nlcd.print(&#8221; Temperature: &#8220;);<br \/>\nlcd.setCursor(5,1);<br \/>\nlcd.print(T);<br \/>\nlcd.setCursor(10,1);<br \/>\nlcd.print((char)223);<br \/>\nlcd.print(&#8221; C&#8221;);<br \/>\ndelay (3000);<br \/>\nlcd.clear();<br \/>\nlcd.setCursor(0,0);<br \/>\nlcd.print(&#8221; Pressure: &#8220;);<br \/>\nlcd.setCursor(4,1);<br \/>\nlcd.print(P);<br \/>\nlcd.setCursor(9,1);<br \/>\nlcd.print(&#8221; hPa &#8220;);<br \/>\ndelay (3000);<br \/>\nlcd.clear();<br \/>\nlcd.setCursor(0,0);<br \/>\nlcd.print(&#8221; Humidity:&#8221;);<br \/>\nlcd.setCursor(5,1);<br \/>\nSerial.print(humidity);<br \/>\nlcd.print(humidity);<br \/>\nlcd.setCursor(9,1);<br \/>\nlcd.print(&#8220;%&#8221;);<br \/>\ndelay (3000);<br \/>\n}<br \/>\nelse<br \/>\nlcd.print(&#8220;Error.&#8221;);<br \/>\n}<br \/>\nelse<br \/>\nlcd.print(&#8220;Error.&#8221;);<br \/>\n}<\/p>\n<p>void setup() {<br \/>\nSerial.begin(9600);<br \/>\nlcd.begin(16, 2);<br \/>\npinMode(contrast, OUTPUT);<br \/>\npinMode(brightness, OUTPUT);<br \/>\nanalogWrite(contrast, 100); \/\/ &#8216;100&#8217; and &#8216;255&#8217; are the contrast and brightness<br \/>\nanalogWrite(brightness, 255); \/\/ values I suggest, but you can change them as<br \/>\nif (!bmp.begin()) { \/\/ you prefer<br \/>\ndelay(1000);<br \/>\nlcd.print(&#8220;Init. failed.&#8221;);<br \/>\nlcd.setCursor(0, 1);<br \/>\ndelay(1000);<br \/>\nlcd.print(&#8220;Check wiring.&#8221;);<br \/>\nwhile (1);<br \/>\n}<br \/>\nelse<br \/>\nlcd.print(&#8220;Init. OK.&#8221;);<\/p>\n<p>bmp.setOversampling(4);<br \/>\ndelay(2000);<br \/>\ncollectData();<br \/>\n}<\/p>\n<p>void loop() {<br \/>\ncollectData();<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>I wanted to have a temperature and humidity and pressure measurement in the shack. There was a load of information on the net. I went <a class=\"mh-excerpt-more\" href=\"https:\/\/pa3csg.nl\/?page_id=1471\" title=\"Arduino temperature, humidity and pressure sketch\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":1476,"parent":0,"menu_order":12,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"categories":[29],"tags":[],"_links":{"self":[{"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/pages\/1471"}],"collection":[{"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1471"}],"version-history":[{"count":3,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/pages\/1471\/revisions"}],"predecessor-version":[{"id":1475,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/pages\/1471\/revisions\/1475"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/media\/1476"}],"wp:attachment":[{"href":"https:\/\/pa3csg.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}