Introduction
In this prototype, we will read the environment's temperature & humidity. After a successful event, we will show it on the LCD display.
Prerequisites
So, we need the following components to complete this project:
- Arduino UNO
- LCD 1602 Display
- DHT11 Temperature Module
- Jumper Wires
- 1 k Ohms Resistor
Background
In my last article, I articulated DHT sensor coding. Whereas in this article we will use the same concept of DHT.h to display the sensor data to the LCD 1602 Display, instead of a serial monitor and you can carry it outdoors and see the various temperatures around.
Before we do anything, ensure you have completed all the connections. Since it's a bit difficult to have an easy connection for the LCD because of 16 pins. Still, have keen eyes while doing it.
Connection Layout
You may say that it's a complex connection, but bear with it. Either buy a compact LCD module or get your LCD on green PCB that will reduce the complexity and bulk of wires.
Note: We will explain the LCD 1602 individually in a future article.
As far as we are concerned about the connection layout, the DHT PIN has a data pin that is connected to PIN8. And the others are the same for the DHT.
Try to follow the mockup.
The following is how it really looks:
Procedures
First, do a connection as shown in the breadboard. Make sure you have correct the data pins with the Vcc and Grounds attached to the same Arduino PIN.
Sketch
- #include < LiquidCrystal.h > #include < DHT.h >
-
-
-
-
-
-
-
-
-
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- #define PIN 8#define TYPE DHT11
-
- DHT dht(PIN, TYPE);
- void setup() {
- Serial.begin(9600);
- lcd.begin(16, 2);
- lcd.clear();
-
- dht.begin();
- }
- void loop() {
-
- float humidity = dht.readHumidity();
- float temp_cel = dht.readTemperature();
- float temp_farh = dht.readTemperature(true);
-
- if (isnan(humidity) || isnan(temp_cel) || isnan(temp_farh)) {
-
- Serial.println("# Sorry, Failed to Read Data From DHT Module");
- return;
- } else {
-
- Serial.print("Humidity : ");
- Serial.print(humidity);
- Serial.println(" % ");
- lcd.setCursor(0, 0);
- lcd.print("Humidity: ");
- lcd.print(humidity);
-
- Serial.print("Temparture : ");
- Serial.print(temp_cel);
- Serial.print(" C - ");
- Serial.print(temp_farh);
- Serial.println(" F ");
- lcd.setCursor(0, 1);
- lcd.print("Temp. : ");
- lcd.print(temp_cel);
- }
- delay(5000);
- }
Apart from the LCD code, we have discussed all the sections of the DHT in our previous article. For the rest, we have used a few new functions, like lcd.print() to print on the LCD and then lcd.setCusor() to point the cursor on the LCD. We have used (0,1) as an argument because that specifies the 0th column and first row.
Since our LCD is of 2 rows and 16 columns, it's given the following name: 16 column x 02 rows, in other words 1602 Display.
Pictures
Conclusion
It's a very fundamental project to do using Arduino. The next article explains all the nuts and bolts of the LCD 1602 Display. And until then, enjoy your very own Temperature Detector. In version 2.0 of this project, I will try to add a Twitter API with this that can send you a tweet when it goes above a certain temperature. Until, then Keep Calm and Love Coding.