Project showcase
DHT11 Humidity + Temperature Sensor with 16x2 LCD display

DHT11 Humidity + Temperature Sensor with 16x2 LCD display © GPL3+

A beginner-tier project I hope will help the fellows that are newbies in the Arduino world!

  • 20,917 views
  • 6 comments
  • 39 respects

Components and supplies

About this project

Well, the place where I live is pretty hot and moist, for the whole year mostly. So I was really pissed off a few days ago on why the weather is so messed up, even in mid-September, and came up with this project. Plus, I didn't really have a chance to play around with this sensor for real, so that made a great excuse to do so.

Anyways, I wanted to keep this as simple as I could, hope this'll help you familiarize yourself with programming (and Arduino in general)!

Code

Temperature and Humidity sensor with LCD display.inoArduino
The coding part with explanations
//We'll start by adding our libraries

#include <LiquidCrystal.h>

#include <SimpleDHT.h>

//Declaring digital pin no 6 as the dht11 data pin

int pinDHT11 = 6;
SimpleDHT11 dht11;

//Declaring the lcd pins

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
// Don't forget to choose 9600 at the port screen
  
  Serial.begin(9600);
 
//Telling our lcd to start up
  
  lcd.begin(16, 2);
   
   
}

void loop() {

  //These serial codes are for getting readings on the port screen aswell as the LCD display, since they'll offer us a more detailed interface
  
  
  Serial.println("=================================");
  Serial.println("DHT11 readings...");
  
 
  byte temperature = 0;
  byte humidity = 0;
  int err = SimpleDHTErrSuccess;

  //This bit will tell our Arduino what to do if there is some sort of an error at getting readings from our sensor
  if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
    Serial.print("No reading , err="); Serial.println(err);delay(1000);
    return;
  }
  
  Serial.print("Readings: ");
  Serial.print((int)temperature); Serial.print(" Celcius, ");
  Serial.print((int)humidity); Serial.println(" %");
 
  //Telling our lcd to refresh itself every 0.75 seconds
  lcd.clear();
 
  //Choosing the first line and row
  lcd.setCursor(0,0);
  //Typing Temp: to the first line starting from the first row
  lcd.print("Temp: ");
  //Typing the temperature readings after "Temp: " 
  lcd.print((int)temperature);
  //Choosing the second line and first row
  lcd.setCursor(0,1);
  //Typing Humidity(%): to the second line starting from the first row
  lcd.print("Humidity(%): ");
  //Typing the humidity readings after "Humidity(%): "
  lcd.print((int)humidity);
 
  
  
  
  delay(750);
}
Temperature and Humidity sensor with LCD display.inoArduino
The code with explanations
//We'll start by adding our libraries

#include <LiquidCrystal.h>

#include <SimpleDHT.h>

//Declaring digital pin no 6 as the dht11 data pin

int pinDHT11 = 6;
SimpleDHT11 dht11;

//Declaring the lcd pins

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
// Don't forget to choose 9600 at the port screen
  
  Serial.begin(9600);
 
//Telling our lcd to start up
  
  lcd.begin(16, 2);
   
   
}

void loop() {

  //These serial codes are for getting readings on the port screen aswell as the LCD display, since they'll offer us a more detailed interface
  
  
  Serial.println("=================================");
  Serial.println("DHT11 readings...");
  
 
  byte temperature = 0;
  byte humidity = 0;
  int err = SimpleDHTErrSuccess;

  //This bit will tell our Arduino what to do if there is some sort of an error at getting readings from our sensor
  if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
    Serial.print("No reading , err="); Serial.println(err);delay(1000);
    return;
  }
  
  Serial.print("Readings: ");
  Serial.print((int)temperature); Serial.print(" Celcius, ");
  Serial.print((int)humidity); Serial.println(" %");
 
  //Telling our lcd to refresh itself every 0.75 seconds
  lcd.clear();
 
  //Choosing the first line and row
  lcd.setCursor(0,0);
  //Typing Temp: to the first line starting from the first row
  lcd.print("Temp: ");
  //Typing the temperature readings after "Temp: " 
  lcd.print((int)temperature);
  //Choosing the second line and first row
  lcd.setCursor(0,1);
  //Typing Humidity(%): to the second line starting from the first row
  lcd.print("Humidity(%): ");
  //Typing the humidity readings after "Humidity(%): "
  lcd.print((int)humidity);
 
  
  
  
  delay(750);
}

Schematics

Fritzing stuff
The Fritzing schemes (which I tried to keep as obvious and simple as possible)
temperature_and_humidity_sensor_with_lcd_display_uWMJWSmAG3.fzz

Comments

Similar projects you might like

Arduino DTH22 Humidity Temperature With LCD I2C 16x2 Display

Project tutorial by Team GiftedMedia

  • 28,508 views
  • 5 comments
  • 35 respects

Arduino Temperature - Humidity - Rain Sensor

Project showcase by Rick_Findus

  • 9,754 views
  • 6 comments
  • 17 respects

Temperature + Humidity on LCD

Project showcase by interpeo

  • 19,649 views
  • 11 comments
  • 49 respects

Simple Ultrasonic Distance Measurer With LCD Display

Project showcase by onatto22

  • 5,696 views
  • 4 comments
  • 19 respects

Temperature sensor

Project tutorial by Grant

  • 12,273 views
  • 6 comments
  • 30 respects

Temperature and Humidity Sensor

by Amarantowy

  • 5,167 views
  • 1 comment
  • 15 respects
Add projectSign up / Login