Software & Tools
Arduino IDE
Project description
Code
Display data on 20x4 LCD
arduino
1//Interface the DHT11 Temp & Humidity sensor and display humidity and temperature 2//in Celsius, Fahrenheit, and Kelvin on a 20x4 character LCD 3 4#include <dht.h> 5#include <LiquidCrystal.h> 6 7//variable declarations 8dht DHT; 9double tempF = 0; 10double tempK = 0; 11const int RS = 2, EN = 3, D4 = 4, D5 = 5, D6 = 6, D7 = 7; 12 13LiquidCrystal lcd(RS,EN,D4,D5,D6,D7); //set Uno pins that are connected to LCD, 4-bit mode 14 15void setup() { 16 lcd.begin(20,4); //set 20 columns and 4 rows of 16x2 LCD 17 18} 19 20void loop() { 21 int readDHT = DHT.read11(8); //grab the 40-bit data packet from DHT sensor 22 23 tempF = DHT.temperature*9/5 + 32; //convert temp to Fahrenheit 24 tempK = DHT.temperature + 273.15; //convert temp to Kelvin 25 lcd.print("Temp: "); 26 lcd.print(DHT.temperature); //display temp in C on LCD 27 lcd.print("C"); 28 29 lcd.setCursor(0,1); 30 lcd.print("Temp: "); 31 lcd.print(tempF); //display temp in F on LCD 32 lcd.print("F"); 33 34 lcd.setCursor(0,2); 35 lcd.print("Temp: "); 36 lcd.print(tempK); //display temp in Kelvin on LCD 37 lcd.print("K"); 38 39 lcd.setCursor(0,3); 40 lcd.print("Humidity: "); 41 lcd.print(DHT.humidity); 42 lcd.print("%"); 43 lcd.setCursor(0,0); 44 delay(2000); 45 46}
Display data on 16x2 LCD
arduino
1//Interface the DHT11 Temp & Humidity sensor and display humidity and temperature 2//in Celsius on a 16x2 character LCD 3 4#include <dht.h> 5#include <LiquidCrystal.h> 6 7dht DHT; 8const int RS = 2, EN = 3, D4 = 4, D5 = 5, D6 = 6, D7 = 7; 9LiquidCrystal lcd(RS,EN,D4,D5,D6,D7); //set Uno pins that are connected to LCD, 4-bit mode 10 11void setup() { 12 lcd.begin(16,2); //set 16 columns and 2 rows of 16x2 LCD 13 14} 15 16void loop() { 17 int readDHT = DHT.read11(8); //grab 40-bit data packet from DHT sensor 18 lcd.setCursor(0,0); 19 lcd.print("Temp: "); 20 lcd.print(DHT.temperature); 21 //lcd.print((char)223); //used to display degree symbol on display 22 //lcd.write(0xdf); //another way to display degree symbol 23 lcd.print("C"); 24 lcd.setCursor(0,1); 25 lcd.print("Humidity: "); 26 lcd.print(DHT.humidity); 27 lcd.print("%"); 28 delay(3000); 29 30}
Display data on 16x2 LCD
arduino
1//Interface the DHT11 Temp & Humidity sensor and display humidity and 2 temperature 3//in Celsius on a 16x2 character LCD 4 5#include <dht.h> 6#include 7 <LiquidCrystal.h> 8 9dht DHT; 10const int RS = 2, EN = 3, D4 = 4, D5 = 5, D6 11 = 6, D7 = 7; 12LiquidCrystal lcd(RS,EN,D4,D5,D6,D7); //set Uno pins that are 13 connected to LCD, 4-bit mode 14 15void setup() { 16 lcd.begin(16,2); //set 17 16 columns and 2 rows of 16x2 LCD 18 19} 20 21void loop() { 22 int readDHT 23 = DHT.read11(8); //grab 40-bit data packet from DHT sensor 24 lcd.setCursor(0,0); 25 26 lcd.print("Temp: "); 27 lcd.print(DHT.temperature); 28 //lcd.print((char)223); 29 //used to display degree symbol on display 30 //lcd.write(0xdf); //another 31 way to display degree symbol 32 lcd.print("C"); 33 lcd.setCursor(0,1); 34 35 lcd.print("Humidity: "); 36 lcd.print(DHT.humidity); 37 lcd.print("%"); 38 39 delay(3000); 40 41}
Downloadable files
Wiring LCD and DHT11 to Arduino Uno
Wiring LCD and DHT11 to Arduino Uno

Wiring LCD and DHT11 to Arduino Uno
Wiring LCD and DHT11 to Arduino Uno

Comments
Only logged in users can leave comments