Back to Arduino Step By Step Course

Lesson 27: Using DHT11 Temperature Sensor with LCD Screen | Arduino Step by Step Course

If you don't like to see ads while video is being played you can purchase this course for $200 from Udemy or purchase YouTube premium Here

Please download required files for this code

Part 3: LCD, LED and OLED Screens

In this lecture we learn how to use DHT11 to measure the temperature and display it on LCD1602 or LCD2004 LCD screen.

 * Robojax Arduino Step By Step Course
 * Lesson 26 DHT11 with LCD1602-I2C display

 * This is the Arduino code for  DHT11 module to read temprature and humidity
 * This code can display temprature in:
 * C is used to get Celsius
 * F is used to get fahrenheit
 * K is used for Kelvin

 *  * 
 * Written by Ahmad Shamshiri for Robojax
 * on Jan 04, 2018

   Please watch video instruction here
 This code is available at
with over 100 lectures Free On  YouTube Watch it here
Get the code for the course: 

 * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been download from
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <>.

// header file from GetHub:
#include <dht11.h>

dht11 DHT11; // create object of DHT11
#define dhtpin 2 // set the pin to connect to DHT11

// start of settings for LCD1602-I2C
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x3F for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x3F, 16, 2);
// end of settings for LCD1602-I2C

void setup() {
    Serial.begin(9600);// setting up serial monitor

  // initialize the LCD, 
  // Turn on the blacklight and print a message.
  lcd.setCursor (0,0); //
  lcd.print("DHT11 Sensor"); 

void loop() {
	//Robojax Step By Step Arduono Course YouTube Watch it here;// initialize the reading
  int humidity = DHT11.humidity;// get humidity

  lcd.clear();// clearn previous values from screen
  lcd.setCursor (0,0); //character zero, line 1
  lcd.print("LCD1602 DHT11"); // print text 

  // print distance in degrees C
  lcd.setCursor (0,1); //character 0, line 2
  lcd.print(getTemp('C'));// print Temperature Celsius
  lcd.setCursor (4,1); //character 5, line 2 
  lcd.print((char)223);// print degree 
  lcd.setCursor (5,1); //character 6, line 2 
  lcd.print("C");// print C
   // print distance degrees F
  lcd.setCursor (7,1); //character 8, line 2
  lcd.print(getTemp('F'));// print distance in cm
  lcd.setCursor (13,1); //character 14, line 2 
  lcd.print((char)223);// print degree 
  lcd.setCursor (14,1); //character 16, line 2 
  lcd.print("F");// print F 
  //code for video
   Serial.print("C ");
   Serial.print("F ");
   Serial.print("K ");
   Serial.print(" humidity:");
   Serial.print (humidity);
   Serial.print("% ");

 * getTemp(char type)
 * type character of upper case 
 * C is used to get Celsius
 * F is used to get fahrenheit
 * K is used for Kelvin
float getTemp(char type) {
	//Robojax Step By Step Arduono Course YouTube Watch it here	
    float temp = (float)DHT11.temperature;//get temp
  if(type =='F')
    return temp * 1.8 + 32;// convert to fahrenheit
  }else if(type =='K')
    return temp + 274.15;// convert to Kelvin
   return temp; 


The least I expect from you is to thumb up the video and subscribe to my channel. I appriciate that. .I have spent months making these lectures and writing code. You don't lose anything by subscribging to my channel. Your subscription is stamp of approval to my videos and more people can find them and in it turn it helps me. Thank you

If you found this tutorial helpful, please support me so I can continue creating content like this. support me via PayPal

**** AFFILIATE PROGRAM **** We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to and affiliated sites.