I have a DHT11 that outputs temperature and humidity values to my serial monitor. I'm trying to serial the COLOUR of the light based on the temperature conditions. So far I only get 1
's and 0
's. How can I change these integer values to output string say RED
, GREEN
or BLUE
?
Code
#include <dht.h>
dht DHT;
#define DHT11_PIN A5
int redPin = 10; // Red LED, connected to digital pin 10
int grnPin = 9; // Green LED, connected to digital pin 9
int bluPin = 8; // Blue LED, connected to digital pin 8
void setup() {
Serial.begin(9600);
// Sets the pins as output for RGB LED
pinMode(redPin, OUTPUT);
pinMode(grnPin, OUTPUT);
pinMode(bluPin, OUTPUT);
}
void loop() {
int chk = DHT.read11(DHT11_PIN);
int t = DHT.temperature;
int h = DHT.humidity;
Serial.print("Temperature = ");
Serial.print(t);
Serial.print( "," );
Serial.print("Humidity = ");
Serial.print(h);
Serial.print("\n");
delay(60000);
if((DHT.temperature < 26) && (DHT.temperature >= 23.2)) {
// Writing the LED colour pins HIGH or LOW to set colours
digitalWrite(redPin, HIGH); // yellow
digitalWrite(grnPin, HIGH);
delay(100);
digitalWrite(bluPin, LOW);
}
if((DHT.temperature < 23) && (DHT.temperature > 20.2)) {
digitalWrite(grnPin, HIGH); // green
delay(100);
digitalWrite(redPin, LOW);
digitalWrite(bluPin, LOW);
}
if((DHT.temperature < 20) && (DHT.temperature > 17.2)) {
digitalWrite(grnPin, HIGH); // aqua
digitalWrite(bluPin, HIGH);
delay(100);
digitalWrite(redPin, LOW);
}
if(DHT.temperature <= 17) {
digitalWrite(bluPin, HIGH); // blue
delay(100);
digitalWrite(grnPin, LOW);
digitalWrite(redPin, LOW);
}
delay(1000);
// Sensor shouldn't be read too frequently so delay of 1s
}
I will be grateful if I can get some help. Thanks!