• 강의
  • 커뮤니티
  • 북마크
GCR

자료실

코딩자료 | 온습도센서와 LED

최고관리자
2019.12.09 11:14 42 0
  • - 첨부파일 : DHT-lib.zip (10.7K) - 다운로드

본문

코딩자료 | 온습도센서와 LED

#include <DHT_SimpleLib.h>
#define LIGHTON_TEMP 25
#define LIGHTON_HUMI 40
#define LED_TEMP 2
#define LED_HUMI 3
#define dht_dpin 7 //no ; here. Set equal to channel sensor is on

dht DHT;
 
void setup(){
  pinMode(dht_dpin, INPUT);
  Serial.begin(9600);
  delay(300);//Let system settle
  Serial.println("Humidity and temperature\n\n");
  delay(700);//Wait rest of 1000ms recommended delay before
}

void loop(){
  DHT.read11(dht_dpin);
  Serial.print("Current humidity = ");
  Serial.print(DHT.humidity);
  Serial.print("% ");
  Serial.print("temperature = ");
  Serial.print(DHT.temperature);
  Serial.println("C ");
  showLEDtemp();
  showLEDhumi();
  delay(3000);//Don't try to access too frequently... in theory
}

void showLEDtemp(){
  if (DHT.temperature > LIGHTON_TEMP)
  digitalWrite(LED_TEMP, HIGH);
  else
  digitalWrite(LED_TEMP, LOW);
}

void showLEDhumi(){
  if (DHT.humidity > LIGHTON_HUMI)
  digitalWrite(LED_HUMI, HIGH);
  else
  digitalWrite(LED_HUMI, LOW);
}

댓글목록 0

등록된 댓글이 없습니다.