{"id":1884,"date":"2013-04-04T08:57:06","date_gmt":"2013-04-03T23:57:06","guid":{"rendered":"http:\/\/www.pinewell.jp\/wordpress\/?p=1884"},"modified":"2013-04-04T08:57:06","modified_gmt":"2013-04-03T23:57:06","slug":"arduino%e3%81%ae%e3%82%b9%e3%82%b1%e3%83%83%e3%83%81%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.pinewell.jp\/wordpress\/?p=1884","title":{"rendered":"arduino\u306e\u30b9\u30b1\u30c3\u30c1\u3002"},"content":{"rendered":"<p>arduino\u3092LS-GL\u306b\u53ce\u7d0d\u3059\u308b\u524d\u306b\u3002<br \/>\narduinoIDE\u306e\u8a2d\u5b9a\u3002<br \/>\narduinoIDE\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305flibraries\u30d5\u30a9\u30eb\u30c0\u306b\u4ee5\u4e0b\u306e4\u30d5\u30a1\u30a4\u30eb\u3092\u5c55\u958b\u3059\u308b\u3002<br \/>\nOneWire.zip (DHT22\u3067\u4f7f\u7528)<br \/>\nDHT-sensor-library-master.zip(DHT22\u7528)<br \/>\nArduino-Temperature-Control-Library-master.zip(DS18B20\u7528)<br \/>\nI2CLiquidCrystal-1.1.zip(I2C\u6db2\u6676)<br \/>\n\u5b9f\u969b\u306b\u306fArduinoIDE\u8d77\u52d5\u6642\u306b\u30d5\u30a9\u30eb\u30c0\u540d\u304c\u30e4\u30d0\u304f\u3066\u4f7f\u3048\u306a\u3044\u65e8\u8868\u793a\u3055\u308c\u308b\u306e\u3067\u9069\u5ea6\u306b\u30d5\u30a9\u30eb\u30c0\u540d\u3092\u5909\u66f4\u3002<\/p>\n<p>\u4ee5\u4e0b\u304c\u3001\u30b9\u30b1\u30c3\u30c1\u3002<br \/>\n[crayon]<br \/>\n\/\/<br \/>\n\/\/ \u6e29\u6e7f\u5ea6\u30bb\u30f3\u30b5 DHT22(StraberryLinux\u54c1\u756a:RHT03 \u30e1\u30fc\u30ab\u30fc\u54c1\u756a\uff1aSEN-10167)<br \/>\n\/\/ \u3068\u3001DS18B20\u3092\u7528\u3044\u3066\u6e29\u6e7f\u5ea6\u30fb\u6e29\u5ea6\u3092\u53d6\u5f97\u3059\u308b\u30b9\u30b1\u30c3\u30c1\u3002<br \/>\n\/\/ \u30bf\u30af\u30c8\u30b9\u30a4\u30c3\u30c1\u306e\u52d5\u4f5c\u3067LED\u7167\u660eON\u3001\u30b7\u30ea\u30a2\u30eb\u30dd\u30fc\u30c8\u306b\u73fe\u5728\u6e29\u5ea6\u51fa\u529b<br \/>\n\/\/ 2013\/03\/29 Ver1.0<br \/>\n\/\/<br \/>\n\/\/<br \/>\n\/\/ I2CLCD\u306fA4(SDA)\u3068A5(SCL)\u306b\u63a5\u7d9a<br \/>\n\/\/ DHT22 \u306f 2pin<br \/>\n\/\/<br \/>\n#include &#8220;DHT.h&#8221;<br \/>\n#include <I2CLiquidCrystal.h><br \/>\n#include <Wire.h><\/p>\n<p>#include <OneWire.h><br \/>\n#include <DallasTemperature.h><\/p>\n<p>#define ONE_WIRE_BUS 10             \/\/DS18B20\u306e\u63a5\u7d9a\u30d4\u30f3<br \/>\n#define TEMPERATURE_PRECISION 9     \/\/         \u5206\u89e3\u80fd?<\/p>\n<p>#define DHTPIN 2     \/\/ what pin we&#8217;re connected to<br \/>\n#define DHTTYPE DHT22   \/\/ DHT 22  (AM2302)<\/p>\n<p>#define LEDINT 10   \/\/LED\u7167\u660e\u306e\u70b9\u706f\u3057\u3066\u3044\u308b\u6642\u9593<br \/>\n#define MAXWRITECOUNT 50   \/\/\u30b7\u30ea\u30a2\u30eb\u30dd\u30fc\u30c8\u306b\u51fa\u529b\u3059\u308b\u56de\u6570<\/p>\n<p>\/\/DHT\u306e\u521d\u671f\u5316<br \/>\nOneWire oneWire(ONE_WIRE_BUS);<br \/>\n\/\/ Pass our oneWire reference to Dallas Temperature.<br \/>\nDallasTemperature sensors(&#038;oneWire);<br \/>\n\/\/ arrays to hold device addresses<br \/>\n\/\/\u30bb\u30f3\u30b5\u30fc\u306e\u5b9a\u7fa9\u3000\u3000\u30a4\u30f3\u30b5\u30a4\u30c9\u3001\u30a2\u30a6\u30c8\u30b5\u30a4\u30c9<br \/>\nDeviceAddress insideThermometer, outsideThermometer;<\/p>\n<p>int sensCnt = 0;         \/\/DHT22\u4ee5\u5916\u306eDS18B20\u306e\u30bb\u30f3\u30b5\u30fc\u6570 (\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u6642\u306b\u81ea\u52d5\u3067\u691c\u51fa\u3055\u308c\u308b)<br \/>\nfloat temp0 = 99.9;<br \/>\nfloat temp1 = 99.9;<br \/>\nfloat h = 99.9;<br \/>\nfloat t = 99.9;<\/p>\n<p>const int ledPin = 3;          \/\/LED<br \/>\nconst int buttonPin  = 13;     \/\/\u52d5\u4f5c\u30b9\u30a4\u30c3\u30c1<\/p>\n<p>int i = 0;                   \/\/LED\u7167\u660e\u306e\u70b9\u706f\u6642\u9593\u7528<br \/>\nint buttonState = 0;         \/\/ variable for reading the pushbutton status<br \/>\nboolean ledSts = false;<\/p>\n<p>int writecnt = 0;            \/\/\u30b7\u30ea\u30a2\u30eb\u30dd\u30fc\u30c8\u306b\u6e29\u5ea6\u30fb\u6e7f\u5ea6\u3092\u51fa\u529b\u3059\u308b\u56de\u6570\u7528<\/p>\n<p>DHT dht(DHTPIN, DHTTYPE);<\/p>\n<p>I2CLiquidCrystal lcd(30, true);<br \/>\n\/\/I2CLiquidCrystal lcd(20, false);<br \/>\n                  \/\/  |    +&#8212; set true if the power suply is 5V, false if it is 3.3V<br \/>\n                  \/\/  +&#8212;&#8212;&#8211; contrast (0-63)<\/p>\n<p>void setup() {<br \/>\n  Serial.begin(9600);<br \/>\n  pinMode(ledPin, OUTPUT);<br \/>\n  pinMode(buttonPin, INPUT);<br \/>\n  digitalWrite(buttonPin,LOW);<\/p>\n<p>  dht.begin();<br \/>\n  lcd.begin(16, 2);<\/p>\n<p>  \/\/ Start up the library<br \/>\n  \/\/ \u7e4b\u304c\u3063\u3066\u3044\u308bDS18B20\u306e\u6570\u3092\u691c\u51fa<br \/>\n  sensors.begin();<br \/>\n  sensCnt=sensors.getDeviceCount();<br \/>\n  switch (sensCnt) {<br \/>\n\t\/\/\u30bb\u30f3\u30b5\u30fc\u306e\u30a2\u30c9\u30ec\u30b9\u3092\u53d6\u5f97<br \/>\n      case 0:<br \/>\n        break;<br \/>\n      case 1:<br \/>\n        sensors.getAddress(insideThermometer,0);<br \/>\n        sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);<br \/>\n        break;<br \/>\n      case 2:<br \/>\n        sensors.getAddress(insideThermometer,0);<br \/>\n        sensors.getAddress(outsideThermometer,1);<br \/>\n        sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);<br \/>\n        sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);<br \/>\n        break;<br \/>\n      default:<br \/>\n        break;<br \/>\n  }<br \/>\n}<\/p>\n<p>void loop() {<\/p>\n<p>    \/\/ proc light (on || off)<br \/>\n  if (i == 0) {<br \/>\n    \/\/ turn LED off:<br \/>\n    \/\/ LED\u6d88\u706f<br \/>\n    digitalWrite(ledPin,LOW);<\/p>\n<p>     \/\/\u30b9\u30a4\u30c3\u30c1\u306e\u72b6\u614b\u3092\u53d6\u5f97<br \/>\n    buttonState = digitalRead(buttonPin);<br \/>\n    if (buttonState == HIGH) {<br \/>\n        \/\/ turn LED on:<br \/>\n\t \/\/ LED\u306e\u70b9\u706f<br \/>\n        ledSts = true;<\/p>\n<p>        digitalWrite(ledPin, HIGH);<br \/>\n        i++;<br \/>\n     } <\/p>\n<p>  } else {<br \/>\n    if (ledSts) {<br \/>\n       \/\/LED\u304c\u70b9\u706f\u3057\u3066\u3044\u308b<br \/>\n\t\/\/\u30b9\u30a4\u30c3\u30c1\u304c\u62bc\u3055\u308c\u3066LED\u304c\u70b9\u706f\u3057\u3066\u3044\u308b\u9593\u306f<br \/>\n\t\/\/\u30b7\u30ea\u30a2\u30eb\u30dd\u30fc\u30c8\u306b\u73fe\u5728\u6e29\u5ea6\u3068\u6e7f\u5ea6\u3092\u51fa\u529b<br \/>\n      i++;<br \/>\n      if (isnan(t)) { t=99.99;}<br \/>\n      if (isnan(h)) { h=99.99;}<br \/>\n      Serial.print(&#8220;H:&#8221;);<br \/>\n      Serial.print(h);<br \/>\n      Serial.print(&#8220;%\\t&#8221;);<br \/>\n      Serial.print(&#8220;T0:&#8221;);<br \/>\n      Serial.println(t);<\/p>\n<p>      if (i> LEDINT ) {<br \/>\n\t \/\/\u8a2d\u5b9a\u3057\u305fLED\u306e\u70b9\u706f\u6642\u9593\u304c\u904e\u304e\u305f\u3089\u6d88\u706f<br \/>\n        \/\/ turn LED off:<br \/>\n        ledSts=false;<br \/>\n        i=0;<br \/>\n        digitalWrite(ledPin,LOW);<\/p>\n<p>      }<br \/>\n    }<br \/>\n  }<\/p>\n<p>  \/\/DHT22\u304b\u3089\u6e29\u5ea6\u3001\u6e7f\u5ea6\u3092\u53d6\u5f97<br \/>\n  h=99.9;<br \/>\n  t=99.9;<br \/>\n  h = dht.readHumidity();<br \/>\n  t = dht.readTemperature();<br \/>\n    if (isnan(t) || isnan(h)) {<br \/>\n      lcd.setCursor(0,0);<br \/>\n      lcd.print(&#8220;Failed to read&#8221;);<br \/>\n    } else {<br \/>\n      lcd.setCursor(0,0);<br \/>\n      lcd.print(&#8220;H:&#8221;);<br \/>\n      lcd.print(h);<br \/>\n      lcd.print(&#8220;%&#8221;);<br \/>\n      lcd.print(&#8220;T:&#8221;);<br \/>\n      lcd.print(t);<br \/>\n      lcd.print(&#8220;C&#8221;);<br \/>\n    }<\/p>\n<p>  \/\/\u30bb\u30f3\u30b5\u30fc\u306e\u6570\u5206\u3001DS18B20\u304b\u3089\u6e29\u5ea6\u3092\u53d6\u5f97<br \/>\n  switch (sensCnt) {<br \/>\n      case 0:<br \/>\n        break;<br \/>\n      case 1:<br \/>\n        sensors.requestTemperatures();<br \/>\n        temp0=sensors.getTempC(insideThermometer);<br \/>\n        lcd.setCursor(0,1);<br \/>\n        lcd.print(temp0);<br \/>\n        lcd.print(&#8220;C&#8221;);<br \/>\n        break;<br \/>\n      case 2:<br \/>\n        sensors.requestTemperatures();<br \/>\n        temp0=sensors.getTempC(insideThermometer);<br \/>\n        temp1=sensors.getTempC(outsideThermometer);<br \/>\n        lcd.setCursor(0,1);<br \/>\n        lcd.print(temp0);<br \/>\n        lcd.print(&#8220;C \/ &#8220;);<br \/>\n        lcd.print(temp1);<br \/>\n        lcd.print(&#8220;c&#8221;);<br \/>\n        break;<br \/>\n      default:<br \/>\n        break;<br \/>\n  }              <\/p>\n<p>  int inputchar;             \/\/\u30b7\u30ea\u30a2\u30eb\u30dd\u30fc\u30c8\u304b\u3089\u306e\u6307\u793a<br \/>\n  inputchar = Serial.read(); \/\/\u30b7\u30ea\u30a2\u30eb\u304b\u3089\u306e\u5024\u3092\u8aad\u307f\u8fbc\u3080<br \/>\n  if(inputchar != -1) {      \/\/\u5024\u304c\u5165\u3063\u3066\u3044\u305f\u3089<br \/>\n        switch(inputchar){<br \/>\n           case &#8216;i&#8217;:        \/\/init<\/p>\n<p>               sensors.begin();<br \/>\n               sensCnt=sensors.getDeviceCount();<br \/>\n                switch (sensCnt) {<br \/>\n                \t\/\/\u30bb\u30f3\u30b5\u30fc\u306e\u30a2\u30c9\u30ec\u30b9\u3092\u53d6\u5f97<br \/>\n                  case 0:<br \/>\n                    break;<br \/>\n                  case 1:<br \/>\n                    sensors.getAddress(insideThermometer,0);<br \/>\n                    sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);<br \/>\n                    break;<br \/>\n                  case 2:<br \/>\n                    sensors.getAddress(insideThermometer,0);<br \/>\n                    sensors.getAddress(outsideThermometer,1);<br \/>\n                    sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);<br \/>\n                    sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);<br \/>\n                    break;<br \/>\n                  default:<br \/>\n                    break;<br \/>\n              }<br \/>\n           case &#8216;s&#8217;:         \/\/<br \/>\n                lcd.begin(16, 2);<br \/>\n                break;<br \/>\n           case &#8216;a&#8217;:         \/\/<br \/>\n                break;<br \/>\n           case &#8216;r&#8217;:        \/\/<br \/>\n                break;<br \/>\n           case &#8216;g&#8217;:        \/\/\u6e29\u5ea6\u53d6\u5f97<br \/>\n                writecnt=1;<br \/>\n                break;<br \/>\n           case &#8216;l&#8217;:        \/\/ON light<br \/>\n                ledSts = true;<br \/>\n                digitalWrite(ledPin, HIGH);<br \/>\n                i++;<br \/>\n                break;<br \/>\n        }<br \/>\n  }<\/p>\n<p>  if (writecnt >0 ) {<br \/>\n     \/\/\u30b7\u30ea\u30a2\u30eb\u30dd\u30fc\u30c8\u306b\u6e29\u6e7f\u5ea6\u3092\u51fa\u529b<br \/>\n    if (isnan(t)) { t=99.99;}<br \/>\n    if (isnan(h)) { h=99.99;}<br \/>\n    Serial.print(&#8220;H:&#8221;);<br \/>\n    Serial.print(h);<br \/>\n    Serial.print(&#8220;%\\t&#8221;);<br \/>\n    Serial.print(&#8220;T0:&#8221;);<br \/>\n    Serial.print(t);<\/p>\n<p>    switch(sensCnt) {<br \/>\n      case 0:<br \/>\n        Serial.println(&#8220;&#8221;);<br \/>\n        break;<br \/>\n      case 1:<br \/>\n        Serial.print(&#8220;\\t&#8221;);<br \/>\n        Serial.print(&#8220;T1:&#8221;);<br \/>\n        Serial.println(temp0);<br \/>\n        break;<br \/>\n      case 2:<br \/>\n        Serial.print(&#8220;\\t&#8221;);<br \/>\n        Serial.print(&#8220;T1:&#8221;);<br \/>\n        Serial.print(temp0);<br \/>\n        Serial.print(&#8220;\\t&#8221;);<br \/>\n        Serial.print(&#8220;T2:&#8221;);<br \/>\n        Serial.println(temp1);<br \/>\n    }<br \/>\n    writecnt++;<br \/>\n    if(writecnt > MAXWRITECOUNT) {<br \/>\n      writecnt=0;<br \/>\n    }<br \/>\n  }<br \/>\n}<br \/>\n[\/crayon]<br \/>\n\u30bd\u30fc\u30b9\u3067\u306f\u30bf\u30af\u30c8\u30b9\u30a4\u30c3\u30c1\u306b\u9023\u52d5\u3057\u3066LED\u3092\u70b9\u706f\uff08\u5b9f\u969b\u306fPOWER-MOS-FET\u3067\u30ea\u30ec\u30fc\u3057\u306612V\u306eLED\u7167\u660e\uff09\u3067\u304d\u308b\u3088\u3046\u306b<br \/>\n\u3057\u3066\u3044\u308b\u304c\u3001\u3042\u307e\u308a\u4f7f\u7528\u983b\u5ea6\u304c\u7121\u3044\u306e\u3067\u5272\u611b\u3002\u30bd\u30fc\u30b9\u306f\u305d\u306e\u307e\u307e\u3067\u3082\u554f\u984c\u7121\u3057\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>arduino\u3092LS-GL\u306b\u53ce\u7d0d\u3059\u308b\u524d\u306b\u3002 arduinoIDE\u306e\u8a2d\u5b9a\u3002 arduinoIDE\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305flibraries\u30d5\u30a9\u30eb\u30c0\u306b\u4ee5\u4e0b\u306e4\u30d5\u30a1\u30a4\u30eb\u3092\u5c55\u958b\u3059\u308b\u3002 OneWire.zip (DHT22\u3067\u4f7f\u7528) DH [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-1884","post","type-post","status-publish","format-standard","hentry","category-11"],"views":35419,"_links":{"self":[{"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1884","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1884"}],"version-history":[{"count":0,"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1884\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pinewell.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}