[Lab] LCD 20x4 colour, DHT22 Tempature sensor, Arduino Uno

Bruce Harding bsharding at rogers.com
Fri Nov 14 12:16:23 EST 2014


Need some help.

Lets assume that I've got all the pinning right. And further assume for the 
time being that the problem is with the code.  Can anyone see why I'm not 
seeing a print out on my LCD for temperature information from my sensor 
(DHT22). I've just run a the DHT.test code and confirm it is working and pinned 
properly. I'm trying to get this working with my Arduino Uno.



Project I'm Trying to Copy-ish
http://mchp.blogspot.ca/2014/08/arduino-pocket-hygrometerthermometer.html



adafruit instructions
https://learn.adafruit.com/character-lcds/wiring-a-character-lcd



LCD Specs
http://www.adafruit.com/datasheets/WH2004A-CFH-JT%23.pdf



The CODE:

#include <LiquidCrystal.h> //lcd library
#include "DHT.h"  //sensor library
#define DHTPIN 2   //  pin 32 (TQFP-32)
#define DHTTYPE DHT22   // type of sensor DHT 22  (AM2302)
byte degreeChar[8] = 
{ B01100,
  B10010,
  B10010,
  B01100,
  B00000,
  B00000,
  B00000,
  B00000, };
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); //we need 6 pins: RS, EN, D7, D6, D5, 
and D4 to talk to the LCD
unsigned int bat = 0; // ADC value
byte volt = 0;  // battery %

void setup() {
  lcd.begin(16, 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);
    lcd.print("Battery");
  for(byte i=0; i<=10; i++)  
  {
   bat=analogRead(1); //  battery sensor pin 17 (TQFP-32)
   if (bat<=800)
      {  bat = 800;  }
   if (bat>=900)
      {  bat = 900;  }
    volt = bat-800;
    lcd.setCursor(0,1); 
    lcd.print(volt);
    lcd.print("%"); 
    delay(200);  
  }
    ADCSRA = 0; // Disable ADC 
}
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,0);
    lcd.print("T");
    lcd.print(t);
    lcd.createChar(0, degreeChar);
    lcd.setCursor(6,0);
    lcd.write(byte(0));
    lcd.print("C");
    lcd.setCursor(0,1);
    lcd.print("H");
    lcd.print(h);
    lcd.print(" %");
 }
  delay(2000); 
 if (millis()>=8000)
   {   digitalWrite(13, LOW);  } // backlight off
 if (millis()>=16000)
   {   digitalWrite(0, LOW);  } // power off 
}

-- 
bruce



More information about the Lab mailing list