DHT11 Temperature and Humidity Sensor Arduino Code with LCD
Article Summary
Introduction
The DHT11 temperature and humidity sensor is commonly used in Arduino projects to measure environmental conditions. In this article, we will provide a detailed guide on how to connect the DHT11 sensor to an Arduino board and display the temperature and humidity readings on an LCD display.
Arduino Code
To start, we need to write the Arduino code that will read data from the DHT11 sensor and send it to the LCD display. Below is a sample code snippet:
#include
#include
#define DHTPIN 2
#define DHTTYPE DHT11
dht DHT;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.begin(16, 2);
}
void loop() {
int chk = DHT.read11(DHTPIN);
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(DHT.temperature);
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(DHT.humidity);
lcd.print("%");
delay(2000);
}
LCD Connections
To connect the LCD display to the Arduino board, follow the steps below:
- Connect the SDA pin of the LCD display to the SDA pin on the Arduino board.
- Connect the SCL pin of the LCD display to the SCL pin on the Arduino board.
- Connect the VCC pin of the LCD display to the 5V pin on the Arduino board.
- Connect the GND pin of the LCD display to the GND pin on the Arduino board.
Sensor Connections
To connect the DHT11 sensor to the Arduino board, follow the steps below:
- Connect the positive (VCC) pin of the DHT11 sensor to the 5V pin on the Arduino board.
- Connect the negative (GND) pin of the DHT11 sensor to the GND pin on the Arduino board.
- Connect the data pin of the DHT11 sensor to a digital pin (e.g., pin 2) on the Arduino board.
Final Thoughts
In this tutorial, we have learned how to use the DHT11 temperature and humidity sensor with an Arduino board and display the readings on an LCD display. By following the provided code and connections, you can easily build your own temperature and humidity monitoring system. Have fun experimenting with the DHT11 sensor in your Arduino projects!