// for temperature & humidity sensor.
#include <dht.h>
dht DHT;
#define DHT11_PIN 7
// for RGB backlight LCD.
#include <Wire.h>
#include "rgb_lcd.h"
rgb_lcd lcd;
const int colorR = 0;
const int colorG = 0;
const int colorB = 0;
int lastTemp;
int dataTemp;
////////////////////////////
void setup(){
Serial.begin(9600);
}
void LCDcolor( int dataHumi){
if (dataHumi < 40) {
lcd.begin(16, 2);
lcd.print("Temp&Humi:");
lcd.setRGB(0, 0, 100);
} else if (dataHumi >= 40 && dataHumi < 50) {
lcd.begin(16, 2);
lcd.print("Temp&Humi:");
lcd.setRGB(colorR, colorG, colorB);
} else if (dataHumi >= 50 && dataHumi < 70) {
lcd.begin(16, 2);
lcd.print("=^_^= Papa loveU");
lcd.setRGB(255, 255, 0);
} else if (dataHumi >= 70 && dataHumi < 85) {
lcd.begin(16, 2);
lcd.print("=^o^= umbrella");
lcd.setRGB(100, 0, 0); delay(500);
lcd.setRGB(255, 100, 150); delay(2000);
} else if (dataHumi >= 85) {
lcd.begin(16, 2);
lcd.print("^o^!! raining");
lcd.setRGB(100, 0, 0);
} else {
lcd.begin(16, 2);
lcd.print("Temp&Humi:");
lcd.setRGB(0, 0, 0);
}
}
void loop(){
int chk = DHT.read11(DHT11_PIN);
int dataTemp = DHT.temperature;
int dataHumi = DHT.humidity;
Serial.print("currentTemp =");
Serial.println(dataTemp);
Serial.println();
LCDcolor( dataHumi );
lcd.setCursor(0, 1);
lcd.print(dataTemp); lcd.print("c");
lcd.print("..");
lcd.print(dataHumi); lcd.print("%");
delay(3000);
}
2017-10-11
Arduino, DHT11 (Temperature, Humidity) & LCD indicator.
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言