Lesson 26: Introduction to the DHT11 Temperature and Humidity Sensor: Arduino Step-by-Step Course
In this lecture, we learn how to use the HT16K33 4-digit display with Arduino. This is a very versatile display. You can use and display data in unlimited ways, including integers like 245, decimal values such as 25.6, or hexadecimal values such as FAB1.
522-Lesson 26: Introduction to the DHT11 Temperature and Humidity Sensor, Arduino Step-by-Step Course
语言: C++
++
/*
* Robojax Arduino Step-by-Step Course
* Lesson 26 Introduction to DHT11 Temperature and Humidity sensor
* This is the Arduino code for the DHT11 module to read temperature and humidity.
* This code can display temperature 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 purposes 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 downloaded 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;
}
}
资源与参考
-
外部DHT11 手册 (PDF)robojax.com
-
外部GitHub上的DHT11库github.com
文件📁
没有可用的文件。