Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
10 views3 pages

Interfacing DHT 11 With LCD and Arduino

The document provides an Arduino code for interfacing a DHT11 temperature and humidity sensor with an LCD display. It initializes the sensor and LCD, reads temperature and humidity values, and displays them on the LCD while also printing to the Serial Monitor. Additionally, it controls an LED based on the temperature reading, turning it on if the temperature exceeds 30°C.

Uploaded by

sahoozu567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Interfacing DHT 11 With LCD and Arduino

The document provides an Arduino code for interfacing a DHT11 temperature and humidity sensor with an LCD display. It initializes the sensor and LCD, reads temperature and humidity values, and displays them on the LCD while also printing to the Serial Monitor. Additionally, it controls an LED based on the temperature reading, turning it on if the temperature exceeds 30°C.

Uploaded by

sahoozu567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Interfacing DHT 11 with LCD and Arduino

#include <LiquidCrystal.h>

#include <DHT.h>

// Define LCD pins (RS, E, D4, D5, D6, D7)

LiquidCrystal lcd(7, 6, 5, 4, 3, 8);

// Define DHT sensor parameters

#define DHTPIN 2

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

// Define LED pin

#define LED_PIN 9

void setup() {

Serial.begin(9600);

dht.begin();

lcd.begin(16, 2); // Initialize the 16x2 LCD

lcd.setCursor(0, 0);

lcd.print("DHT11 Sensor");

delay(2000);

lcd.clear();

pinMode(LED_PIN, OUTPUT); // Set LED pin as output

void loop() {

// Wait before taking new readings

delay(2000);

// Read temperature and humidity

float humidity = dht.readHumidity();

float temperature = dht.readTemperature(); // Default is Celsius

// Check if the readings are valid

if (isnan(humidity) || isnan(temperature)) {

lcd.setCursor(0, 0);
lcd.print("Sensor Error!");

Serial.println("Sensor Error!");

return;

// Display Temperature

lcd.setCursor(0, 0);

lcd.print("Temp: ");

lcd.print(temperature);

lcd.print(" C");

// Display Humidity

lcd.setCursor(1, 1);

lcd.print("Hum:");

lcd.print(humidity);

lcd.print("%");

// Print values to Serial Monitor

Serial.print("Temperature: ");

Serial.print(temperature);

Serial.print("°C, ");

Serial.print("Humidity: ");

Serial.print(humidity);

Serial.println("%");

// LED Control: Turn ON if temp > 30°C, otherwise turn OFF

if (temperature > 30) {

digitalWrite(LED_PIN, HIGH);

Serial.println("LED ON: High Temperature!");

} else {

digitalWrite(LED_PIN, LOW);

Serial.println("LED OFF: Normal Temperature.");

You might also like