環境
OS: windows7 64bit
IDE: Arduino 1.6.9
概要
センサの型番は”DHT11″ ??
電圧: 3.3 ~ 5.5V DC
出力: single-bus digital signal
測定範囲:
湿度 20-90% +-5% RH, 温度 0 ~ 50 +-2 ℃
解像度:
湿度 1% RH, 温度 1 ℃
Long-term stability: <± 1% RH / 1年
引用元: https://tkkrlab.nl/wiki/Arduino_KY-015_Temperature_and_humidity_sensor_module
準備
結線
「S側」:シグナル。 下記のサンプルではデジタル8番ピンへ接続。
「中側(middle)」:+5V
「-側」:GND
サンプルコード
参考:https://tkkrlab.nl/wiki/Arduino_KY-015_Temperature_and_humidity_sensor_module
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
//KY015 DHT11 Temperature and humidity sensor int DHpin = 8; byte dat [5]; byte read_data () { byte data; for (int i = 0; i < 8; i ++) { if (digitalRead (DHpin) == LOW) { while (digitalRead (DHpin) == LOW); // wait for 50us delayMicroseconds (30); // determine the duration of the high level to determine the data is '0 'or '1' if (digitalRead (DHpin) == HIGH) data |= (1 << (7-i)); // high front and low in the post while (digitalRead (DHpin) == HIGH); // data '1 ', wait for the next one receiver } } return data; } void start_test () { digitalWrite (DHpin, LOW); // bus down, send start signal delay (30); // delay greater than 18ms, so DHT11 start signal can be detected digitalWrite (DHpin, HIGH); delayMicroseconds (40); // Wait for DHT11 response pinMode (DHpin, INPUT); while (digitalRead (DHpin) == HIGH); delayMicroseconds (80); // DHT11 response, pulled the bus 80us if (digitalRead (DHpin) == LOW); delayMicroseconds (80); // DHT11 80us after the bus pulled to start sending data for (int i = 0; i < 4; i ++) // receive temperature and humidity data, the parity bit is not considered dat[i] = read_data (); pinMode (DHpin, OUTPUT); digitalWrite (DHpin, HIGH); // send data once after releasing the bus, wait for the host to open the next Start signal } void setup () { Serial.begin (9600); pinMode (DHpin, OUTPUT); } void loop () { start_test (); Serial.print ("Current humdity ="); Serial.print (dat [0], DEC); // display the humidity-bit integer; Serial.print ('.'); Serial.print (dat [1], DEC); // display the humidity decimal places; Serial.println ('%'); Serial.print ("Current temperature ="); Serial.print (dat [2], DEC); // display the temperature of integer bits; Serial.print ('.'); Serial.print (dat [3], DEC); // display the temperature of decimal places; Serial.println ('C'); delay (700); } |
その他
参考
Arduino KY-015 Temperature and humidity sensor module – TkkrLabhttps://tkkrlab.nl/wiki/Arduino_KY-015_Temperature_and_humidity_sensor_module
コメント