带RGB LED的DHT传感器

时间:2017-01-09 23:36:43

标签: rgb led arduino-ide temperature

我有一台输出温度和湿度值的DHT11。我根据设定的温度条件尝试Serial.print光的颜色。到目前为止,我只获得了10 s。如何将这些整数值更改为输出字符串REDGREENBLUE?这是可能的还是我只需要在每个循环中使用Serial.print("RED");来完成它?

代码

#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);
  pinMode(redPin, OUTPUT);// Sets the pins as output for RGB LED  
  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
}

如果能得到一些帮助,我将不胜感激。谢谢!

0 个答案:

没有答案