Page 247 - MDP2022-3
P. 247
# 온습도 센서
#include <LiquidCrystal.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 8
#define DHTTYPE DHT11
#define CONTROL 12
DHT dht(DHTPIN,DHTTYPE);
LiquidCrystal lcd(7,6,5,4,3,2);
void setup() {
Serial.begin(9600);
lcd.begin(16,2);
dht.begin();
pinMode(11,OUTPUT);
pinMode(CONTROL,INPUT);
}
void loop() {
int h = dht.readHumidity();
int t = dht.readTemperature();
Serial.print("습도 : ");
Serial.print(h);
Serial.println("%");
Serial.print("온도 : ");
Serial.print(t);
Serial.println("ºC");
lcd.setCursor(0,0);
lcd.print("Temp = ");
lcd.print(t);
lcd.print("C");
lcd.print(" 218");
lcd.setCursor(0,1);