{"id":164,"date":"2015-05-21T23:20:00","date_gmt":"2015-05-21T13:20:00","guid":{"rendered":"http:\/\/stevoz.com\/myweatherblog\/?p=164"},"modified":"2015-05-29T21:28:10","modified_gmt":"2015-05-29T11:28:10","slug":"fun-with-the-arduino","status":"publish","type":"post","link":"https:\/\/stevoz.com\/myweatherblog\/2015\/05\/fun-with-the-arduino\/","title":{"rendered":"Fun with the Arduino"},"content":{"rendered":"<p>I have had my weather station reporting to my website via a Raspberry Pi for seventeen months now and I enjoyed tinkering with it over that time. In addition to the Raspberry Pi, I have seen references to the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Arduino\">Arduino<\/a> which is a microcontroller and I&#8217;m intrigued by that as well. It looks very promising for setting up other sensors around the place that I can monitor. One project that comes to mind is monitoring the water level in my tank.<\/p><p>The other day I bit the bullet and bought a <a href=\"http:\/\/www.freetronics.com.au\/collections\/kits\/products\/experimenters-kit-for-arduino\">Freetronics Experimenters Kit for Arduino<\/a>. The heart of the kit is the <a href=\"http:\/\/www.freetronics.com.au\/collections\/arduino\/products\/eleven\">Freetronics Eleven<\/a> which is an Arduino Uno clone. I also grabbed a <a href=\"http:\/\/www.freetronics.com.au\/collections\/modules\/products\/humidity-and-temperature-sensor-module\">Humidity and Temperature Sensor Module (DHT22)<\/a> while I was there.<\/p><p>I was playing with the arduino tonight and set up a simple circuit with the humidity and temperature sensor and a couple of LEDs. I also discovered the <a href=\"http:\/\/fritzing.org\">Fritzing<\/a> programme which enables me to draw a schematic of my circuit and show the breadboard layout. So much fun to be had!<\/p><p>What you have to do is set up your circuit, connect it to your PC and then upload a sketch to it. The sketch is the code that you write to control the Arduino. This code is based on the C language.<\/p><p>Anyway, for the sake of having a play, I thought a simple experiment I could do is measure the humidity and temperature, output the results to the screen and also set up a couple of LEDs so that if the temperature is greater or equal to 25&#176;C, then a red LED lights but if the temperature falls below 25&#176;C then a green LED lights.<\/p><p>Here is my circuit:<\/p><p><a href=\"http:\/\/stevoz.com\/homeandgarden\/wp-content\/uploads\/sites\/4\/2015\/05\/DHT22_bb.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/stevoz.com\/homeandgarden\/wp-content\/uploads\/sites\/4\/2015\/05\/DHT22_bb-745x1024.jpg\" alt=\"DHT22_bb\" width=\"625\" height=\"859\" class=\"aligncenter size-large wp-image-133\" \/><\/a><\/p><p><a href=\"http:\/\/stevoz.com\/homeandgarden\/wp-content\/uploads\/sites\/4\/2015\/05\/DHT22_schem.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/stevoz.com\/homeandgarden\/wp-content\/uploads\/sites\/4\/2015\/05\/DHT22_schem-881x1024.jpg\" alt=\"DHT22_schem\" width=\"625\" height=\"726\" class=\"aligncenter size-large wp-image-134\" \/><\/a><\/p><p>Here is the sketch which I put together based on some examples I found:<\/p>\n<pre class=\"brush: cpp; gutter: true; title: ; wrap-lines: false; notranslate\" title=\"\">\r\n#include &quot;DHT.h&quot;\r\n\r\n#define DHTPIN 2     \/\/ what pin we're connected to\r\n\r\n#define DHTTYPE DHT22   \/\/ DHT 22  (AM2302)\r\n\r\nDHT dht(DHTPIN, DHTTYPE);\r\n\r\nint redLed = 9;\r\nint greenLed = 11;\r\nfloat time;\r\n\r\nvoid setup() {\r\n  Serial.begin(9600);\r\n  Serial.println(&quot;DHT test&quot;);\r\n\r\n  dht.begin();\r\n  \r\n  pinMode(redLed, OUTPUT);\r\n  pinMode(greenLed, OUTPUT);  \r\n}\r\n\r\nvoid loop() {\r\n  \/\/ Reading temperature or humidity takes about 250 milliseconds!\r\n  \/\/ Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)\r\n  float h = dht.readHumidity();\r\n  float t = dht.readTemperature();\r\n\r\n  \/\/ check if returns are valid, if they are NaN (not a number) then something went wrong!\r\n  if (isnan(t) || isnan(h)) {\r\n    Serial.println(&quot;Failed to read from DHT&quot;);\r\n  } else {\r\n    Serial.print(&quot;Time: &quot;);\r\n    time = millis()\/1000;\r\n    Serial.print(time);\r\n    Serial.print(&quot; secs\\t&quot;);\r\n    Serial.print(&quot;Humidity: &quot;);\r\n    Serial.print(h);\r\n    Serial.print(&quot; %\\t&quot;);\r\n    Serial.print(&quot;Temperature: &quot;);\r\n    Serial.print(t);\r\n    Serial.println(&quot; *C&quot;);\r\n  }\r\n  \/\/ Turn red LED on and green LED off if the temperature is 25 degrees or more.\r\n  \/\/ Turn green LED on and red LED off if the temperature is less than 25 degrees.\r\n  if (t &gt;= 25) {\r\n    digitalWrite(redLed, HIGH);\r\n    digitalWrite(greenLed, LOW);\r\n  }\r\n  else {\r\n    digitalWrite(redLed, LOW);\r\n    digitalWrite(greenLed, HIGH);\r\n  }\r\n  \/\/ Wait 5 seconds before starting the next reading.\r\n  delay(5000);\r\n}\r\n<\/pre><p>And finally, the results as printed to the screen:<br \/>\n<a href=\"http:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/05\/dev-ttyACM0_005.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/05\/dev-ttyACM0_005.png\" alt=\"-dev-ttyACM0_005\" width=\"589\" height=\"344\" class=\"aligncenter size-full wp-image-166\" srcset=\"https:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/05\/dev-ttyACM0_005.png 589w, https:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/05\/dev-ttyACM0_005-300x175.png 300w\" sizes=\"auto, (max-width: 589px) 100vw, 589px\" \/><\/a><\/p><p>The water tank level indicator idea has been running through my head and I reckon I know how to do it. I have ordered a heap of parts from eBay so once they turn up I will get into it. Think ultrasonic sensor, solar powered transmitter, received by the Raspberry Pi, uploaded to a database and displayed on the web. I will be posting my progress (good or bad) on here so stay tuned&#8230; \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have had my weather station reporting to my website via a Raspberry Pi for seventeen months now and I enjoyed tinkering with it over that time. In addition to the Raspberry Pi, I have seen references to the Arduino which is a microcontroller and I&#8217;m intrigued by that as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":166,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-164","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/stevoz.com\/myweatherblog\/wp-content\/uploads\/sites\/2\/2015\/05\/dev-ttyACM0_005.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5uBIO-2E","_links":{"self":[{"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/posts\/164","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/comments?post=164"}],"version-history":[{"count":2,"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/posts\/164\/revisions"}],"predecessor-version":[{"id":170,"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/posts\/164\/revisions\/170"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/media\/166"}],"wp:attachment":[{"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/media?parent=164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/categories?post=164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stevoz.com\/myweatherblog\/wp-json\/wp\/v2\/tags?post=164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}