이렇게 작은빵보드를 쓰기 시작했는게 이거면 충분할 것 같다.
16x2 LCD라 딱 두 줄..
PM2.5센서를 받으면 습도 대신 PM2.5 수치를 보여주면 되겠지?
#include <LiquidCrystal_I2C.h> #include<Wire.h> #include <DHT.h> #define DHTTYPE DHT11 #define DHTPIN 11; int HUMITEMP_IN=11; DHT dht(HUMITEMP_IN,DHTTYPE); LiquidCrystal_I2C lcd(0x27, 16,2); void setup() { // put your setup code here, to run once: Serial.begin(9600); Serial.println("DHT testing....."); dht.begin(); lcd.init(); lcd.backlight(); } void loop() { // put your main code here, to run repeatedly: delay(2000); float h=dht.readHumidity(); float t=dht.readTemperature(); if(isnan(h)||isnan(t)){ Serial.println("Fail to read...."); } else{ Serial.print("Hudimity "); Serial.print(h); Serial.println("%"); Serial.print("Temperature "); Serial.print(t); Serial.println("C"); lcd.setCursor(0,0); lcd.print("Humidity "); lcd.setCursor(10,0); lcd.print((int)h); lcd.setCursor(13,0); lcd.print("%"); lcd.setCursor(0,1); lcd.print("Temp "); lcd.setCursor(10,1); lcd.print((int)t); lcd.setCursor(13,1); lcd.print("C"); } } |
이런 코드..
이렇게 쓰고 보니까 LCD에 출력할 내용은 다 모아서 string으로 만드는게 더 편할 것 같다.
온도와 습도를 읽어들일 변수를 float로 설정해서 소숫점까지 나타나는 바람에
(int)를 추가해서 출력값은 정수로 바꿔놓긴 했는데...
아예 처음부터 정수로 불러들여도 별 문제는 없더란 말이다...그리고 DHT11 센서 자체가 0도~50도, 20~90%만 측정할 수 있으니까 더더욱 float는 필요없을 것 같은데
왜 다들 float를 쓰는건지는 잘 모르겠다.
찾아보니까 DHT11은 성능이 씁쓸하고 DHT22만 하더라도 영하40도~80도를 잴 수 있는데다 0.1도 단위로 측정할 수 있다고 하니.. 고성능 센서에 대응하려면 float를 쓰긴 써야할 것 같긴 하다만..
내 센서는 필요없네....
여튼
LCD에 출력하는 것까지 성공했으니까 PM2.5 측정기는 그다지 어렵지 않을 것 같다.
거기에 미세먼지 수치가 얼마 이상이면 LED를 켜게 하면 되겠지?
소리가 나게 했다가는 계속 소리를 들어야 할테니...-_-;;;
아두이노에서 루프를 두 개 돌리는게 가능할까? 그럼 소리로 경고하는 것도 가능할텐데...
이제 다음 차례는 초음파 센서로 거리 재기??? 집에다 키 재는 포인트를 하나 만들어놓을까보다 ㅋㅋ