DHT22, RGB LCD 20×4 Progress

November 18, 2014 11:58 am

after a few minutes I ended up with this…

Using the following code:

#include //lcd library
#include "DHT.h" //sensor library
#define DHTPIN 2 // pin 32 (TQFP-32)
#define DHTTYPE DHT22 // type of sensor DHT 22 (AM2302)
#define REDLITE 3
#define GREENLITE 5
#define BLUELITE 6
byte degreeChar[8] =
{ B01100,
B10010,
B10010,
B01100,
B00000,
B00000,
B00000,
B00000, };
DHT dht(DHTPIN, DHTTYPE);

// LCD
// LCD RS=7, EN=8, DS4=9, DS5=10, DS6=11, DS7=12
LiquidCrystal lcd( 7, 8, 9, 10, 11, 12 );

// you can change the overall brightness by range 0 -> 255
int brightness = 255;

void setup() {
lcd.begin(20, 4);
analogReference(INTERNAL);
pinMode(0, OUTPUT);
digitalWrite(0, HIGH); // power on
pinMode(13, OUTPUT);
digitalWrite(13, HIGH); // backlight on
dht.begin(); // start sensor
lcd.setCursor(0,0);

pinMode(REDLITE, OUTPUT);
pinMode(GREENLITE, OUTPUT);
pinMode(BLUELITE, OUTPUT);

brightness = 100;
}

void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(t) || isnan(h)) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("SENSOR");
lcd.setCursor(0,1);
lcd.print("ERROR");
}
else {
lcd.clear();
lcd.setCursor(0,1);
lcd.print("TEMPERATURE ");
lcd.print(t);
lcd.createChar(0, degreeChar);
lcd.setCursor(18,1);
lcd.write(byte(0));
lcd.print("C");
lcd.setCursor(0,2);
lcd.print("HUMIDITY ");
lcd.print(h);
lcd.print(" %");
}
if (t < 15)
{
setBacklight(0, 0, 255); // set to blue
}
else if (t < 25)
{
setBacklight(0, 255, 0); // set to green
}
else
{
setBacklight(.255, 0, 0); // set to red
}
}

void setBacklight(uint8_t r, uint8_t g, uint8_t b) {
// normalize the red LED - its brighter than the rest!
r = map(r, 0, 255, 0, 100);
g = map(g, 0, 255, 0, 150);

r = map(r, 0, 255, 0, brightness);
g = map(g, 0, 255, 0, brightness);
b = map(b, 0, 255, 0, brightness);

// common anode so invert!
r = map(r, 0, 255, 255, 0);
g = map(g, 0, 255, 255, 0);
b = map(b, 0, 255, 255, 0);
Serial.print("R = "); Serial.print(r, DEC);
Serial.print(" G = "); Serial.print(g, DEC);
Serial.print(" B = "); Serial.println(b, DEC);
analogWrite(REDLITE, r);
analogWrite(GREENLITE, g);
analogWrite(BLUELITE, b);
}

plant health monitor

June 30, 2014 2:05 pm

How to See Pluto at Opposition as New Horizons Crosses the One Year Out Mark

1:38 pm

M6.7 – 205km SSE of Mata-Utu, Wallis and Futuna 2014-06-29 17:15:08 UTC

11:49 am

Seti New Programs

11:49 am