TheLostGhost
Published

Weather station with DHT11 Sensor and LCD 1602 display

I find it interesting to enhance the DHT11 temperature and humidity tutorial by adding a LCD display instead of using the serial monitor

BeginnerFull instructions provided9,358
Weather station with DHT11 Sensor and LCD 1602 display

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Alphanumeric LCD, 16 x 2
Alphanumeric LCD, 16 x 2
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1

Story

Read more

Code

Code

C/C++
Make sure that you have installed the <dht_nonblocking.h> and < LiquidCrystal > libraries or re-install them, if necessary. Otherwise, your code won't work.
#include <dht_nonblocking.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11
#include <LiquidCrystal.h>

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);

/*
 * Display fixe text .
 */
void setup( )
{
  lcd.begin(16, 2);
  lcd.print( "T = " );
  lcd.setCursor(10, 0);
  lcd.print( "deg. C" );
  lcd.setCursor(0, 1);
  lcd.print( "H = " );
  lcd.setCursor(10, 1);
  lcd.print( "%" );
}

/*
 * 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 );
}

/*
 * Main program loop.
 */
void loop( )
{
  float temperature;
  float humidity;

  /* Measure temperature and humidity.  If the functions returns
     true, then a measurement is available. */
  if( measure_environment( &temperature, &humidity ) == true )
  {
   /*
    * Display  changing text.
    */
    lcd.setCursor(4, 0);
    lcd.print( temperature );
    lcd.setCursor(4, 1);
    lcd.print( humidity );
        
  }
}

Credits

TheLostGhost
2 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.