Components and supplies
Standard LCD - 16x2 White on Blue
Jumper wires (generic)
DHT11 Temperature & Humidity Sensor (4 pins)
Arduino UNO
Project description
Code
Temperature and Humidity sensor with LCD display.ino
arduino
The coding part with explanations
1//We'll start by adding our libraries 2 3#include <LiquidCrystal.h> 4 5#include <SimpleDHT.h> 6 7//Declaring digital pin no 6 as the dht11 data pin 8 9int pinDHT11 = 6; 10SimpleDHT11 dht11; 11 12//Declaring the lcd pins 13 14const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; 15LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 16 17void setup() { 18// Don't forget to choose 9600 at the port screen 19 20 Serial.begin(9600); 21 22//Telling our lcd to start up 23 24 lcd.begin(16, 2); 25 26 27} 28 29void loop() { 30 31 //These serial codes are for getting readings on the port screen aswell as the LCD display, since they'll offer us a more detailed interface 32 33 34 Serial.println("================================="); 35 Serial.println("DHT11 readings..."); 36 37 38 byte temperature = 0; 39 byte humidity = 0; 40 int err = SimpleDHTErrSuccess; 41 42 //This bit will tell our Arduino what to do if there is some sort of an error at getting readings from our sensor 43 if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { 44 Serial.print("No reading , err="); Serial.println(err);delay(1000); 45 return; 46 } 47 48 Serial.print("Readings: "); 49 Serial.print((int)temperature); Serial.print(" Celcius, "); 50 Serial.print((int)humidity); Serial.println(" %"); 51 52 //Telling our lcd to refresh itself every 0.75 seconds 53 lcd.clear(); 54 55 //Choosing the first line and row 56 lcd.setCursor(0,0); 57 //Typing Temp: to the first line starting from the first row 58 lcd.print("Temp: "); 59 //Typing the temperature readings after "Temp: " 60 lcd.print((int)temperature); 61 //Choosing the second line and first row 62 lcd.setCursor(0,1); 63 //Typing Humidity(%): to the second line starting from the first row 64 lcd.print("Humidity(%): "); 65 //Typing the humidity readings after "Humidity(%): " 66 lcd.print((int)humidity); 67 68 69 70 71 delay(750); 72} 73
Temperature and Humidity sensor with LCD display.ino
arduino
The coding part with explanations
1//We'll start by adding our libraries 2 3#include <LiquidCrystal.h> 4 5#include <SimpleDHT.h> 6 7//Declaring digital pin no 6 as the dht11 data pin 8 9int pinDHT11 = 6; 10SimpleDHT11 dht11; 11 12//Declaring the lcd pins 13 14const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; 15LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 16 17void setup() { 18// Don't forget to choose 9600 at the port screen 19 20 Serial.begin(9600); 21 22//Telling our lcd to start up 23 24 lcd.begin(16, 2); 25 26 27} 28 29void loop() { 30 31 //These serial codes are for getting readings on the port screen aswell as the LCD display, since they'll offer us a more detailed interface 32 33 34 Serial.println("================================="); 35 Serial.println("DHT11 readings..."); 36 37 38 byte temperature = 0; 39 byte humidity = 0; 40 int err = SimpleDHTErrSuccess; 41 42 //This bit will tell our Arduino what to do if there is some sort of an error at getting readings from our sensor 43 if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { 44 Serial.print("No reading , err="); Serial.println(err);delay(1000); 45 return; 46 } 47 48 Serial.print("Readings: "); 49 Serial.print((int)temperature); Serial.print(" Celcius, "); 50 Serial.print((int)humidity); Serial.println(" %"); 51 52 //Telling our lcd to refresh itself every 0.75 seconds 53 lcd.clear(); 54 55 //Choosing the first line and row 56 lcd.setCursor(0,0); 57 //Typing Temp: to the first line starting from the first row 58 lcd.print("Temp: "); 59 //Typing the temperature readings after "Temp: " 60 lcd.print((int)temperature); 61 //Choosing the second line and first row 62 lcd.setCursor(0,1); 63 //Typing Humidity(%): to the second line starting from the first row 64 lcd.print("Humidity(%): "); 65 //Typing the humidity readings after "Humidity(%): " 66 lcd.print((int)humidity); 67 68 69 70 71 delay(750); 72} 73
Temperature and Humidity sensor with LCD display.ino
arduino
The code with explanations
1//We'll start by adding our libraries 2 3#include <LiquidCrystal.h> 4 5#include <SimpleDHT.h> 6 7//Declaring digital pin no 6 as the dht11 data pin 8 9int pinDHT11 = 6; 10SimpleDHT11 dht11; 11 12//Declaring the lcd pins 13 14const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; 15LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 16 17void setup() { 18// Don't forget to choose 9600 at the port screen 19 20 Serial.begin(9600); 21 22//Telling our lcd to start up 23 24 lcd.begin(16, 2); 25 26 27} 28 29void loop() { 30 31 //These serial codes are for getting readings on the port screen aswell as the LCD display, since they'll offer us a more detailed interface 32 33 34 Serial.println("================================="); 35 Serial.println("DHT11 readings..."); 36 37 38 byte temperature = 0; 39 byte humidity = 0; 40 int err = SimpleDHTErrSuccess; 41 42 //This bit will tell our Arduino what to do if there is some sort of an error at getting readings from our sensor 43 if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { 44 Serial.print("No reading , err="); Serial.println(err);delay(1000); 45 return; 46 } 47 48 Serial.print("Readings: "); 49 Serial.print((int)temperature); Serial.print(" Celcius, "); 50 Serial.print((int)humidity); Serial.println(" %"); 51 52 //Telling our lcd to refresh itself every 0.75 seconds 53 lcd.clear(); 54 55 //Choosing the first line and row 56 lcd.setCursor(0,0); 57 //Typing Temp: to the first line starting from the first row 58 lcd.print("Temp: "); 59 //Typing the temperature readings after "Temp: " 60 lcd.print((int)temperature); 61 //Choosing the second line and first row 62 lcd.setCursor(0,1); 63 //Typing Humidity(%): to the second line starting from the first row 64 lcd.print("Humidity(%): "); 65 //Typing the humidity readings after "Humidity(%): " 66 lcd.print((int)humidity); 67 68 69 70 71 delay(750); 72} 73
Temperature and Humidity sensor with LCD display.ino
arduino
The code with explanations
1//We'll start by adding our libraries 2 3#include <LiquidCrystal.h> 4 5#include 6 <SimpleDHT.h> 7 8//Declaring digital pin no 6 as the dht11 data pin 9 10int 11 pinDHT11 = 6; 12SimpleDHT11 dht11; 13 14//Declaring the lcd pins 15 16const 17 int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; 18LiquidCrystal lcd(rs, en, 19 d4, d5, d6, d7); 20 21void setup() { 22// Don't forget to choose 9600 at the 23 port screen 24 25 Serial.begin(9600); 26 27//Telling our lcd to start up 28 29 30 lcd.begin(16, 2); 31 32 33} 34 35void loop() { 36 37 //These 38 serial codes are for getting readings on the port screen aswell as the LCD display, 39 since they'll offer us a more detailed interface 40 41 42 Serial.println("================================="); 43 44 Serial.println("DHT11 readings..."); 45 46 47 byte temperature = 0; 48 49 byte humidity = 0; 50 int err = SimpleDHTErrSuccess; 51 52 //This bit will 53 tell our Arduino what to do if there is some sort of an error at getting readings 54 from our sensor 55 if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) 56 != SimpleDHTErrSuccess) { 57 Serial.print("No reading , err="); Serial.println(err);delay(1000); 58 59 return; 60 } 61 62 Serial.print("Readings: "); 63 Serial.print((int)temperature); 64 Serial.print(" Celcius, "); 65 Serial.print((int)humidity); Serial.println(" 66 %"); 67 68 //Telling our lcd to refresh itself every 0.75 seconds 69 lcd.clear(); 70 71 72 //Choosing the first line and row 73 lcd.setCursor(0,0); 74 //Typing Temp: 75 to the first line starting from the first row 76 lcd.print("Temp: "); 77 //Typing 78 the temperature readings after "Temp: " 79 lcd.print((int)temperature); 80 81 //Choosing the second line and first row 82 lcd.setCursor(0,1); 83 //Typing 84 Humidity(%): to the second line starting from the first row 85 lcd.print("Humidity(%): 86 "); 87 //Typing the humidity readings after "Humidity(%): " 88 lcd.print((int)humidity); 89 90 91 92 93 94 delay(750); 95} 96
Downloadable files
Fritzing stuff
The Fritzing schemes (which I tried to keep as obvious and simple as possible)
Fritzing stuff
Comments
Only logged in users can leave comments
onatto22
0 Followers
•0 Projects
Table of contents
Intro
44
0