絶対湿度計 DHT11 TM1637 4-digit diaplay
Arduinoで湿度計を使って、更に計算し絶対湿度を表示してみましょう。絶対湿度計。計算式はhttp://komorebit.exblog.jp/11774626を参考に。
DHT11は正面向いて右から5V、4ピン、繋がない、GND
TM1637 4-digit displayはVCC、GNDはそのまま。CLKは13ピン、DIOは12ピンにつないだ。
コード
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 "TM1637.h" | |
#include <DHT.h> | |
DHT dht_4_DHT11(4,DHT11); | |
#define CLK 13 | |
#define DIO 12 | |
TM1637 tm1637(CLK,DIO); | |
int hum; | |
int temp; | |
int ghum; | |
void setup() | |
{ | |
tm1637.init(); | |
tm1637.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7; | |
hum = 0; | |
temp = 0; | |
ghum = 0; | |
dht_4_DHT11.begin(); | |
} | |
void loop() | |
{ | |
hum = (int)(dht_4_DHT11.readHumidity()); | |
temp = (int)(dht_4_DHT11.readTemperature()); | |
float E,Ep; | |
int dig; | |
E = 6.11*10*(7.5 * temp /(237.3 + temp)); | |
Ep = E * hum /100; | |
ghum = 217 * Ep / temp; | |
dig = int(ghum); | |
tm1637.display(0,dig/1000); | |
tm1637.display(1,(dig % 1000)/100); | |
tm1637.display(2,((dig % 1000) % 100)/10); | |
tm1637.display(3,((dig % 1000) % 100)%10); | |
delay(3000); | |
} |
Post a Comment