Back to Arduino Step By Step Course

Lesson 26: Introduction to DHT11 Temperature and Humidity Sensor| Arduino Step by Step Course

If you don't like to see ads while video is being played you can purchase this course for $200 from Udemy

Please download required files for this code

Part 2: LCD, LED and OLED Screens

In this lecture we learn how to use HT16K33 4 digit display with Arduino. This is the king of all displays. you can use and display in unlimited possible way including integer like 245 or decimal value such as 25.6 or hex value such as FAB1.


 
 /*
 * Robojax Arduino Step By Step Course
 * Lesson 26 Introduction to DHT11 Temperature and Humidity sensor 
 
 * This is the Arduino code for  DHT11 module to read temprature and humidity
 * This code can display temprature in:
 * C is used to get Celsius
 * F is used to get fahrenheit
 * K is used for Kelvin
 * Watch the video https://youtu.be/0o5jKR7u8ts
 *  * 
 * Written by Ahmad Shamshiri for Robojax Video
 * Date: Jan 04, 2018, in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: this code is "AS IS" and for educational purpose only.

 
   Please watch video instruction here https://youtu.be/0o5jKR7u8ts
 This code is available at http://robojax.com/course1/?vid=lecture11
 
with over 100 lectures Free On  YouTube Watch it here http://robojax.com/L/?id=338
Get the code for the course: http://robojax.com/L/?id=339 
* 
 * Code is available at http://robojax.com/learn/arduino

 * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been download from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>. 

*/

// header file from GetHub: https://github.com/adidax/dht11
#include <dht11.h>

dht11 DHT11; // create object of DHT11
#define dhtpin 2 // set the pin to connect to DHT11

void setup() {
    Serial.begin(9600);// setting up serial monitor

}

void loop() {
  DHT11.read(dhtpin);// initialize the reading
  //code for Robojax.com video
  int humidity = DHT11.humidity;// get humidity

   Serial.print(getTemp('C'));
   Serial.print("C ");
   Serial.print(getTemp('F'));
   Serial.print("F ");
   Serial.print(getTemp('K'));
   Serial.print("K ");
   Serial.print(" humidity:");
   Serial.print (humidity);
   Serial.println("% ");
   Serial.println();
 delay(500);
}


/*
 * getTemp(char type)
 * type character of upper case 
 * C is used to get Celsius
 * F is used to get fahrenheit
 * K is used for Kelvin
 */
float getTemp(char type) {
    float temp = (float)DHT11.temperature;//get temp
  if(type =='F')
  {
    return temp * 1.8 + 32;// convert to fahrenheit
  }else if(type =='K')
  {
    return temp + 274.15;// convert to Kelvin
  }else{
   return temp; 
  }
  
}

   

If you found this tutorial helpful, please support me so I can continue creating content like this. support me via PayPal