LCD not showing temperature and humidity numbers

Hello together,

I am fairly new with Arduino and have a question regarding my setup.

I am using a DHT11 temperature and humidity sensor and just want to print out the numbers on a LCD display. Somehow the display only shows the following

Temp = 0.00
Hum. = 0.00

Temperature and Humidity don't show their value, although if I print it to the serial monitor, I get the real values and not 0.00.

As follows my code:

// include the library code:
#include <LiquidCrystal.h>
#include <dht_nonblocking.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11
static const int DHT_SENSOR_PIN = 2;
DHT_nonblocking dht_sensor( DHT_SENSOR_PIN, DHT_SENSOR_TYPE );

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
Serial.begin( 9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
}

/*

  • Poll for a measurement, keeping the state machine alive. Returns
  • true if a measurement is available.
    */
    static bool measure_environment( float *temperature, float *humidity )
    {
    static unsigned long measurement_timestamp = millis( );

/* Measure once every four seconds. */
if( millis( ) - measurement_timestamp > 3000ul )
{
if( dht_sensor.measure( temperature, humidity ) == true )
{
measurement_timestamp = millis( );
return( true );
}
}

return( false );

}

void loop() {

float temperature;
float humidity;

// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 0);
// print the temperature since reset:
lcd.print("Temp. = ");

lcd.setCursor(8, 0);
lcd.print(temperature);

// print the humidity in second row
lcd.setCursor(0,1);
lcd.print("Humi. = ");

lcd.setCursor(8, 1);
lcd.print(humidity);

/* Measure temperature and humidity. If the functions returns
true, then a measurement is available. */
if( measure_environment( &temperature, &humidity ) == true )
{
Serial.print( "T = " );
Serial.print( temperature,1);
Serial.print( "C, H = " );
Serial.print( humidity, 1 );
Serial.println( "%" );
}

}

Thanks a lot!

Hello SolarLord,
Welcome to the forum.

You are more likely to get helpful, friendly advice if you follow the forum guidelines. Please read 'how to use this forum - please read' (there's a big clue in the title), especially item #7, then go back and modify you post.
Thank you.

In order to display a message on the LCD you must send it a series of binary numbers representing the characters that you wish to appear.

The binary numbers that correspond to each character have been standardized into what is known as the ASCII code.

Example: In order to display the number 27 (which may represent a temperature or humidity) you do not send '27' to the display. Instead you send 00110010 representing the '2', followed by 00110111 representing the '7'.

These binary numbers are more frequently represented by their hexadecimal equivalents 0x32 and 0x37. Note that the original '2' and '7' appear in these hex representations.

Inexperienced programmers, especially those with ten fingers, sometimes use the decimal equivalents to represent the binary numbers but I won't do that here.

What all this means is that you will have to convert the numerical information that you received from your sensor into its ASCII equivalent before sending it to the LCD. You don't have to do that for the serial monitor because the Serial.print() function takes care of the conversion for you.

Don

@Don, you missed the OP's error, because its so very simple. I think your explanation has gone off at a tangent. There's an lcd.print() function, which the OP is already using, so it's just as easy as printing to serial monitor.

@SolarLord, your problem is simple. Your code is doing things in the wrong sequence. It is printing the temp & humidity to the LCD before reading them from the sensor. Then, after taking the readings, it prints them to serial monitor. That's why it's zero on the LCD but correct on serial monitor. Just move the code that prints to the LCD inside the "if" statement that prints to serial monitor.

Or sit down with a nice cup of tea and a biscuit.

Tidy up the program logic so that it is more straightforward.

This is a useful exercise that will help you with other projects too.
And you get a cup of tea as a bonus !!

David.

I guess I should have had my breakfast (or some tea and biscuits) before I sat down to answer questions.

Don