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!