Temperature Sensor

A temperature sensor is an electrical component that senses the temperature of its surroundings and gives an analog output. There are different temperature sensors available such as LM35, DHT11, etc. We shall use the DHT11 temperature sensor to show the application of the temperature sensor with Arduino.

See live demo of the project- click here to see

arduino-temperature-humidity-display

Components Required :

  • Arduino UNO
  • DHT11 Temperature Sensor
  • Bread Board
  • Jumper Wires
  • 16*2 LCD display.
The DHT11 Temperature Sensor

arduino-dht11-temperature-sensor

The Sensor has three PINS- +, out and -.

Steps for connecting the DHT11 Sensor.

  • Connect the plus pin(+) of the sensor to the 5v pin of the Arduino.
  • Connect the minus pin (-) of the sensor to the GND pin of the Arduino
  • Connect the out pin(middle pin) of the sensor to the pin 2 of the Arduino.

Below, we shall display the humidity and temperature in the Serial Monitor & LCD Display.

Humdity And Temperature in Serial Monitor

What is a Serial Monitor?

Serial Monitor is a software interface integrated inside the Arduino IDE. The Serial Monitor is used so that the output of a program that is using Sensors can be checked without using any hardware display module such as the LCD, TFT display, etc.

Therefore, we shall first see whether the Arduino is using the Senor input and producing the required output.

Edit the below code into your Arduino IDE

#include <dht11.h>
dht11 data;
void setup()
{ 
  Serial.begin(9600);
}
 void loop()
{
   data.read(2);
   Serial.println("The humidity is");
   Serial.print(data.humidity);
   Serial.println("%");
   Serial.println("The temperature is");
   Serial.print(data.temperature);
   Serial.println("C");
   delay(3000);
}

Program Analysis :

  • #include <dht11.h> is used to include the dht11.h header which is inside the DHT11 library.
  • dht11 data; using this, we are telling the compiler that, data is a dht11 type object and the sensor data can be accessed or retrieved using the object.
  • Inside the void setup() function, we have the Serial.begin(9600); which indicates that the Arduino can transmit 9600 bits per second.
  • data.read(2); , this code means read digital data from PIN 2 and store it in the object data.
  • Serial.print(data.humidity);, this line indicates that we are accessing the attribute humidity of the object data.

After the program is verified and uploaded, then its time to check the serial monitor. To open the Serial Monitor, go to the Serial Monitor icon on the top right side of the Sketch Editor.

arduino-serial-monitor

Serial Monitor Output :

arduino-serial-monitor-temp-output

Humidity & Temperature in LCD Display

We shall use the 16*2 LCD Display to show the temperature and the humidity output.

arduino-16by2-lcd

Connecting the LCD Pins into the Arduino :

  • Connect the Anode Pin of the LCD into the GND of the Arduino.
  • Connect the Cathode Pin of the LCD into the 5V Pin of the Arduino.
  • Connect the PIN D7 of the LCD into the PIN 13 of the Arduino.
  • Connect the PIN D6 of the LCD into the PIN 12 of the Arduino.
  • Connect the PIN D5 of the LCD into the PIN 11 of the Arduino.
  • Connect the PIN D4 of the LCD into the PIN 10 of the Arduino.
  • Connect Vss PIN of the LCD into the GND of the Arduino.
  • Connect the VDD pin of the LCD into the 5v pin of the Arduino.
  • Connect the Contrast pin of the LCD into the GND pin of the Arduino via a 10K ohm Resistor or a 10K potentiometer.
  • Connect the RS pin of the LCD to the PIN 4 of the Arduino.
  • Connect the RW pin of the LCD to the GND of the Arduino.
  • Connect the Enable pin of the Arduino to the PIN 6 of the Arduino.

Connecting the DHT11 Sensor to the Arduino :

  • Connect the minus(-) pin into the GND of the Arduino.
  • Connect the plus(+) pin into the 5v of the Arduino.
  • Connect the (out) pin of the sensor into PIN 2 of the Arduino.

Edit the following code into the Arduino Editor :

#include <dht11.h>
#include <LiquidCrystal.h>
dht11 data;
define DHT11PIN 2
LiquidCrystal lcd(4, 6, 10, 11, 12, 13);
void setup() {
    lcd.begin(16, 2); // set up the LCD's number of columns and rows: 
    lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner 
    delay(1000); //delay 1000ms
}
void loop() {
    data.read(DHT11PIN);
    lcd.setCursor(0, 0); // set the cursor to column 0, line 0
    lcd.print("Humidity:"); // Print a message of "Humidity: "to the LCD.
    lcd.print((float) data.humidity, 2); // Print a message of "Humidity: "to the LCD.
    lcd.print(" % "); // Print the unit of the centigrade temperature to the LCD.
    lcd.setCursor(0, 1); // set the cursor to column 0, line 0
    lcd.print("Temp:    "); // Print a message of "Temp: "to the LCD.
    lcd.print((float) data.temperature, 2); // Print a centigrade temperature to the LCD. 
    lcd.print(" C "); // Print the unit of the centigrade temperature to the LCD.
    delay(1000);
}

Program Analysis :

  • dht11 data; signifies that a variable data is an object and it can be used to access the DHT11 sensor attribute, which is the temperature and the humidity.
  • define DHT11PIN 2; defines a global variable called DHT11PIN which is assigned the PIN 2.
  • LiquidCrystal lcd(4, 6, 10, 11, 12, 13); means that the Pins 4,6,10,11,12 and 13 are dedicated to the LCD module.
  • The functions lcd.begin() and lcd.clear() are for setting up the LCD's number of rows and columns and and clearing the LCD respectively.
  • delay(1000) is for inducing a delay of 1000 milliseconds, that is 1 second.
  • Inside the void loop() function data.read(DHT11PIN); is to read the data from the DHT11PIN which is assigned to pin 2 of the Arduino.

Program Output :

arduino-temp-humidity

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions