DHT11 & LCD JHD 162A

Hi!

I am a newcomer to this area. I copied the test code DHT11, and in it wrote the code for displaying on the LCD. Now I work humidity sensor problems, because my feeling shows insufficient moisture. Is there any additional line that shows me the 2 decimal moisture and temperature? I attach the log.

#define dht_dpin 14 //no ; here. Set equal to channel sensor is on,
//where if dht_dpin is 14, sensor is on digital line 14, aka analog 0
//Other digital lines can be used, e.g. D2

#include <LiquidCrystal.h>

// LiquidCrystal display based on JHD659 FN/JG
// ATMEGA // LCD
// GND // 1
// +5v // 2
int RS = 12; // 4
//int RW = GND; // 5
int ENABLE = 11;// 6
int d4 = 5; // 11
int d5 = 4; // 12
int d6 = 3; // 13
int d7 = 2; // 14

const int numRows = 2;
const int Humidity = 16;

LiquidCrystal lcd(RS, ENABLE, d4, d5, d6, d7);
int backLight = 15; // pin 15 will control the backlight

byte bGlobalErr;//for passing error code back from complex functions.
byte dht_dat[4];//Array to hold the bytes sent from sensor.

void setup(){
InitDHT();//Does what’s necessary to prepare for reading DHT
Serial.begin(9600);
delay(300);//Let system settle
Serial.println(“Humidity and temperature\n\n”);
delay(700);//Wait rest of 1000ms recommended delay before
//accessing sensor
//end “setup()”

pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace ‘HIGH’ with ‘LOW’ to turn it off.
lcd.begin(16, 2); // rows, columns. use 8,1 for a 16x2 LCD, etc.
lcd.clear(); // start with a blank screen
lcd.setCursor(0,0); // set cursor to column 0, row 10
}

void loop(){
ReadDHT();//This is the “heart” of the program.
//Fills global array dht_dpin, and bGlobalErr, which
//will hold zero if ReadDHT went okay.
//Must call InitDHT once (in “setup()” is usual) before
//call ReadDHT.
switch (bGlobalErr){
case 0:
lcd.setCursor(0,0);
lcd.print(“Hum = “);
lcd.setCursor(8,0);
lcd.print(dht_dat[0], DEC);
lcd.print(”.”);
lcd.print(dht_dat[1], DEC);
lcd.setCursor(13,0);
lcd.print("% ");
lcd.setCursor(0,1);
lcd.print(“Temp = “);
lcd.setCursor(8,1);
lcd.print(dht_dat[2], DEC);
lcd.print(”.”);
lcd.print(dht_dat[3], DEC);
lcd.setCursor(13,1);
lcd.println("C ");
break;
case 1:
Serial.println(“Error 1: DHT start condition 1 not met.”);
break;
case 2:
Serial.println(“Error 2: DHT start condition 2 not met.”);
break;
case 3:
Serial.println(“Error 3: DHT checksum error.”);
break;
default:
Serial.println(“Error: Unrecognized code encountered.”);
break;
}//end “switch”
delay(1000);//Don’t try to access too frequently… in theory
//should be once per two seconds, fastest,
//but seems to work after 0.8 second.
}// end loop()

/Below here: Only “black box” elements which can just be plugged
unchanged into programs. Provide InitDHT() and ReadDHT(), and a function
one of them uses.
/

void InitDHT(){
pinMode(dht_dpin,OUTPUT);
digitalWrite(dht_dpin,HIGH);
}//end InitDHT

void ReadDHT(){
/Uses global variables dht_dat[0-4], and bGlobalErr to pass
“answer” back. bGlobalErr=0 if read went okay.
Depends on global dht_dpin for where to look for sensor.
/
bGlobalErr=0;
byte dht_in;
byte i;
// Send “start read and report” command to sensor…
// First: pull-down I/O pin for 23000us
digitalWrite(dht_dpin,LOW);
delay(23);
/*aosong.com datasheet for DHT22 says pin should be low at least
500us. I infer it can be low longer without any]
penalty apart from making “read sensor” process take
longer. */
//Next line: Brings line high again,
// second step in giving “start read…” command
digitalWrite(dht_dpin,HIGH);
delayMicroseconds(40);//DHT22 datasheet says host should
//keep line high 20-40us, then watch for sensor taking line
//low. That low should last 80us. Acknowledges “start read
//and report” command.

//Next: Change Arduino pin to an input, to
//watch for the 80us low explained a moment ago.
pinMode(dht_dpin,INPUT);
delayMicroseconds(40);

dht_in=digitalRead(dht_dpin);

if(dht_in){
bGlobalErr=1;//dht start condition 1 not met
return;
}//end “if…”
delayMicroseconds(80);

dht_in=digitalRead(dht_dpin);

if(!dht_in){
bGlobalErr=2;//dht start condition 2 not met
return;
}//end “if…”

/After 80us low, the line should be taken high for 80us by the
sensor. The low following that high is the start of the first
bit of the forty to come. The routine “read_dht_dat()”
expects to be called with the system already into this low.
/
delayMicroseconds(80);
//now ready for data reception… pick up the 5 bytes coming from
// the sensor
for (i=0; i<5; i++)
dht_dat = read_dht_dat();
//Next: restore pin to output duties
pinMode(dht_dpin,OUTPUT);
//Next: Make data line high again, as output from Arduino
digitalWrite(dht_dpin,HIGH);
//Next see if data received consistent with checksum received
byte dht_check_sum =

  • dht_dat[0]+dht_dat[1]+dht_dat[2]+dht_dat[3];*
    /*Condition in following “if” says "if fifth byte from sensor
    _ not the same as the sum of the first four…"*/_
    if(dht_dat[4]!= dht_check_sum)
  • {bGlobalErr=3;}//DHT checksum error*
    };//end ReadDHT()
    byte read_dht_dat(){
    //Collect 8 bits from datastream, return them interpreted
    //as a byte. I.e. if 0000.0101 is sent, return decimal 5.
    //Code expects the system to have recently entered the
    //dataline low condition at the start of every data bit’s
    //transmission BEFORE this function is called.
  • byte i = 0;*
  • byte result=0;*
  • for(i=0; i< 8; i++){*
  • //We enter this during the first start bit (low for 50uS) of the byte*
  • //Next: wait until pin goes high*
  • while(digitalRead(dht_dpin)==LOW);*
  • //signalling end of start of bit’s transmission.*
  • //Dataline will now stay high for 27 or 70 uS, depending on*
  • //whether a 0 or a 1 is being sent, respectively.*
  • delayMicroseconds(30);//AFTER pin is high, wait further period, to be*
  • //into the part of the timing diagram where a 0 or a 1 denotes*
  • //the datum being send. The “further period” was 30uS in the software*
  • //that this has been created from. I believe that a higher number*
  • //(45?) might be more appropriate.*
  • //Next: Wait while pin still high*
  • if (digitalRead(dht_dpin)==HIGH)*
  • result |=(1<<(7-i));// “add” (not just addition) the 1*
  • //to the growing byte*
  • //Next wait until pin goes low again, which signals the START*
  • //of the NEXT bit’s transmission.*
  • while (digitalRead(dht_dpin)==HIGH);*
  • }//end of “for…”*
  • return result;*
    }//end of “read_dht_dat()”[/quote]
    Thanks,
    best regards
    F.

Would you please modify your post, and change the word quote in the to code? In [ code ][ /code ] tags, things like [ i ] are not interpreted as formatting tags. In [ quote ][ /quote ] blocks, they are. It is hard to follow your code when the [ i ] stuff is missing.

As an example, it is hard to tell what this:

for (i=0; i<5; i++)
   dht_dat = read_dht_dat();

is supposed to be doing. It looks like [ i ] might be missing.

Is there any additional line that shows me the 2 decimal moisture and temperature?

It appears as though ReadDHT() is setting 4 global values - the integer portion of the temperature, the decimal portion as an integer (multiplied by 100), the integer portion of the humidity, and the decimal portion of the humidity (multiplied by 100).

You are printing these now, to the LCD, with decimal points in appropriate places, so it is not clear what your question is. There is a problem with the way you are printing them. 29.03 degrees will be returned as 29 and 3, which you print as 29.3.

There's further information on using a DHT11 at....

http://sheepdogguides.com/arduino/ar3ne1humDHT11.htm