🚀 Hurry! Offer Ends In
00 Days
00 Hours
00 Mins
00 Secs
Enroll Now
X
Questions
























Write a program to interface LCD and DHT11, displaying the value read from sensor DHT on LCD.

Last Updated : 16 Jul 2025

Solution:

#include "DHT.h"
#include <LiquidCrystal.h>

#define DHTPIN 2         // Pin connected to the DHT11 sensor
#define DHTTYPE DHT11   // Define the type of DHT sensor (DHT11)
const int rs = 11;     // RS pin for LCD
const int en = 10;    // EN pin for LCD
const int d4 = 9;     // Data pin 4 for LCD
const int d5 = 8;     // Data pin 5 for LCD
const int d6 = 7;     // Data pin 6 for LCD
const int d7 = 6;     // Data pin 7 for LCD

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);  // Create an LCD object
DHT dht(DHTPIN, DHTTYPE);  // Create a DHT object

void setup(){
    dht.begin();           // Initialize the DHT sensor
    lcd.begin(16, 2);      // Initialize the LCD with 16 columns and 2 rows
    lcd.print("Temp: ");   // Print a label on the LCD
}

void loop(){
    float temp = dht.readTemperature();  // Read the temperature in Celsius

    lcd.setCursor(6, 0);  // Set cursor to column 6, row 0 (right after "Temp: ")
    lcd.print(temp);      // Print the temperature value
    lcd.print(" C");      // Print the temperature unit

    delay(2000);          // Wait for 2 seconds before taking the next reading
}
Report an error

Meanwhile you can watch this video

Watch Video
Latest Updates