中国からだといつ届くかわからないこの意外性が贈り物みたいでいいですね。
このセンサー精度がどうとかいう記述があって、迷っていたのですが結局買ってしまいました。
いいですね。きちんと動きます。Arduino のおかげです。書き込みが多くて世界中の人間が使っているのが分かります。
ピン配置は左から Vcc, Data, NC, GND です。5k ほどのプルアップ抵抗が必要です。
ライブラリをダウンロードして、読み込むときちんと表示されました。もちろん、配線を間違えると動きません。アナログ入力ピンなどとつなぐとだめです。
このハードルの低さ。情報の多さ、完成度の高さ。Arduino ですね。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <dht.h> | |
#include <SPI.h> | |
#include <Wire.h> | |
#include <Adafruit_GFX.h> | |
#include <Adafruit_SSD1306.h> | |
#define OLED_RESET 4 | |
Adafruit_SSD1306 display(OLED_RESET); | |
dht DHT; | |
#define DHT11_PIN 5 | |
void setup() { | |
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); | |
display.clearDisplay(); | |
display.setTextSize(1); | |
display.setTextColor(WHITE); | |
display.setCursor(0, 0); | |
} | |
void loop() { | |
display.setCursor(0, 0); | |
int chk = DHT.read11(DHT11_PIN); | |
if (chk == DHTLIB_OK) | |
{ | |
display.clearDisplay(); | |
display.println("Humidity: " + String(DHT.humidity) + " %"); | |
display.println("Temperature: " + String(DHT.temperature) + " C"); | |
} | |
else | |
{ | |
display.println("Hello DHT11"); | |
} | |
display.display(); | |
delay(2000); | |
} |
ブレッドボードでは心もとないので、DHTモジュールをつくっておきました。あとはいつもの百均ケースで収まってくれました。