Hackster is hosting Hackster Holidays, Finale: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Tuesday!Stream Hackster Holidays, Finale on Tuesday!
rudraksh2008
Published

Temperature and humidity sensor with Arduino

Come in this project and you will learn about Interfacing Temp. and humid. sensor with Arduino!

AdvancedFull instructions provided3,666
Temperature and humidity sensor with Arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
Male to male wires
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
I2C LCD
This is optional because we are using serial monitor in our project.
×1

Software apps and online services

Arduino IDE

Story

Read more

Schematics

This is the connection of DHT11 sensor with Arduino UNO

Connect DHT11 sensor with Arduino using this diagram but this only for reference. You have to make connection as commented in the code.

Code

Connecting DHT11 to Arduino with serial monitor.

C/C++
In this code we are using serial monitor to print temperature and humidity sensor.
#include <dht.h> // You have to download this liibrary. NAME: dht library

dht DHT; 

#define DHT11_PIN 7 // define DHT pin

void setup(){
  Serial.begin(9600); // Start serial communication
}

void loop(){
  int chk = DHT.read11(DHT11_PIN); // check the data coming from the DHT pin
  Serial.print("Temperature = "); // print temperature on the serial monitor
  Serial.println(DHT.temperature);
  Serial.print("Humidity = ");// Print humidity on the serial monitor
  Serial.println(DHT.humidity);
  delay(1000); // delay of 1 second
}


      /*Here are the connections
      
      Take a DHT11 sensor.
      there, in the DHT11 sensor, there are 3 or 4 pins.
      There, on the DHT11 sensor, there is writen S, +, -
      connect "S" on the digital pin 7.
      connect "+" on the 5V pin on Arduino.
      connect "-" on the GND pin on Arduino.
      
      Thank you
      Meet you in the next project.
      */ 

This is the code to print DHT sensor value on the LCD screen

C/C++
This is same code but difference is that we will print DHT sensor value on the I2C LCD.
#include <dht.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd = liquidCrystal_I2C(0x27, 20, 4)

dht DHT;

#define DHT11_PIN 7

void setup(){
  lcd.init(); // initialise I2C LCD
  lcd.backlight(); // Turn On the backlight of the I2C LCD
}

void loop(){
  int chk = DHT.read11(DHT11_PIN);
  lcd.setCursor(0,0); 
  lcd.print("Temp: ");
  lcd.print(DHT.temperature);
  lcd.print((char)223);
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Humidity: ");
  lcd.print(DHT.humidity);
  lcd.print("%");
  delay(1000);
}

Credits

rudraksh2008
4 projects • 1 follower

Comments