Arduino Temperature Detector Prototype

In this article, we are going to read the environment’s temperature, its humidity and show it on a LCD display.

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

  1. #include < LiquidCrystal.h > #include < DHT.h >  
  2. /* 
  3. Title: Temperature Detector 
  4. Author: ABhishek Kumar Ravi 
  5. @greenSyntax 
  6. Date: 13th May 2015 
  7. Modules Used: 
  8. # DHT11 
  9. # LCD 1602 Display 
  10. */  
  11. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);  
  12. #define PIN 8#define TYPE DHT11  
  13. // Prototype Declartion  
  14. DHT dht(PIN, TYPE);  
  15. void setup() {  
  16.     Serial.begin(9600);  
  17.     lcd.begin(16, 2);  
  18.     lcd.clear();  
  19.     //Start  
  20.     dht.begin();  
  21. }  
  22. void loop() {  
  23.     // Maitain a diffrence of 2 seconds  
  24.     float humidity = dht.readHumidity();  
  25.     float temp_cel = dht.readTemperature(); // in Clecius  
  26.     float temp_farh = dht.readTemperature(true);  
  27.     // Id Failed to Read Data  
  28.     if (isnan(humidity) || isnan(temp_cel) || isnan(temp_farh)) {  
  29.         //isnan = is NOT A NUMBER which return true when it is not a number  
  30.         Serial.println("# Sorry, Failed to Read Data From DHT Module");  
  31.         return;  
  32.     } else {  
  33.         // For Humidity  
  34.         Serial.print("Humidity : ");  
  35.         Serial.print(humidity);  
  36.         Serial.println(" % ");  
  37.         lcd.setCursor(0, 0);  
  38.         lcd.print("Humidity: ");  
  39.         lcd.print(humidity);  
  40.         // For Temprature   
  41.         Serial.print("Temparture : ");  
  42.         Serial.print(temp_cel);  
  43.         Serial.print(" C - ");  
  44.         Serial.print(temp_farh);  
  45.         Serial.println(" F ");  
  46.         lcd.setCursor(0, 1);  
  47.         lcd.print("Temp. : ");  
  48.         lcd.print(temp_cel);  
  49.     }  
  50.     delay(5000);  
  51. }

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.