<온도 습도 값을 읽어 불쾌지수를 계산하여 시리얼통신으로 전송하기>
더보기
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup(){
Serial.begin(9600);
dht.begin();
}
void loop(){
float di = discomfortIndex();
if (di != 0)
{
Serial.print("불쾌지수: ");
Serial.println(di);
}
}
int discomfortIndex()
{
static unsigned long currTime = 0;
static unsigned long prevTime = 0;
currTime = millis();
if (currTime - prevTime >= 2000)
{
prevTime = currTime;
float humi = dht.readHumidity();
float temp = dht.readTemperature();
if (!isnan(humi)|| !isnan(temp))
{
float di = (1.8 * temp) - (0.55 * (1 - humi/100.0)*(1.8 *temp - 26)) + 32;
return di;
}
}
return 0;
}
<온도 습도 값을 읽어 불쾌지수 계산해서 LCD에 표시>
더보기
#include <DHT.h>
#include <DHT_U.h>
#include <LiquidCrystal_I2C.h>
#define DHTPIN 11
#define DHTTYPE DHT11
LiquidCrystal_I2C lcd(0x27, 16, 2);
DHT dht(DHTPIN, DHTTYPE);
int count=0;
void setup(){
Serial.begin(9600);
dht.begin(); //DHT초기화
lcd.begin();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print('230724_DHT');
delay(2000);
lcd.clear();
}
void loop(){
//DHT
delay(2000);QD
int di = discomfortIndex();
if (di != 0)
{
Serial.print("discomfortIndex: ");
Serial.println(di);
lcd.setCursor(0,0);
lcd.print("discomfortIndex:");
lcd.setCursor(0,1);
lcd.print(di);
}
}
int discomfortIndex()
{
static unsigned long currTime = 0;
static unsigned long prevTime = 0;
currTime = millis();
if (currTime - prevTime >= 2000)
{
prevTime = currTime;
float humi = dht.readHumidity();
float temp = dht.readTemperature();
if (!isnan(humi)|| !isnan(temp))
{
float di = (1.8 * temp) - (0.55 * (1 - humi/100.0)*(1.8 *temp - 26)) + 32;
return di;
}
}
return 0;
}
'아두이노' 카테고리의 다른 글
아두이노 피에조부저/LCD/버튼 시리얼통신과 제어하기 (0) | 2023.07.26 |
---|---|
아두이노 시리얼통신으로 제어하기 (0) | 2023.07.25 |
아누이노 CDS조도센서 / 가변저항 + 전등 (0) | 2023.07.24 |
아두이노 IoT 키트 목록 (0) | 2023.07.19 |
아두이노 LCD와 시계 (0) | 2023.07.19 |