This repository has been archived by the owner before Nov 9, 2022. It is now read-only.
Permalink
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
DHTesp/examples/DHT_ESP8266/DHT_ESP8266.ino
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…new version number 1.18
44 lines (36 sloc)
1.15 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "DHTesp.h" // Click here to get the library: http://librarymanager/All#DHTesp | |
| #ifdef ESP32 | |
| #pragma message(THIS EXAMPLE IS FOR ESP8266 ONLY!) | |
| #error Select ESP8266 board. | |
| #endif | |
| DHTesp dht; | |
| void setup() | |
| { | |
| Serial.begin(115200); | |
| Serial.println(); | |
| Serial.println("Status\tHumidity (%)\tTemperature (C)\t(F)\tHeatIndex (C)\t(F)"); | |
| String thisBoard= ARDUINO_BOARD; | |
| Serial.println(thisBoard); | |
| // Autodetect is not working reliable, don't use the following line | |
| // dht.setup(17); | |
| // use this instead: | |
| dht.setup(17, DHTesp::DHT22); // Connect DHT sensor to GPIO 17 | |
| } | |
| void loop() | |
| { | |
| delay(dht.getMinimumSamplingPeriod()); | |
| float humidity = dht.getHumidity(); | |
| float temperature = dht.getTemperature(); | |
| Serial.print(dht.getStatusString()); | |
| Serial.print("\t"); | |
| Serial.print(humidity, 1); | |
| Serial.print("\t\t"); | |
| Serial.print(temperature, 1); | |
| Serial.print("\t\t"); | |
| Serial.print(dht.toFahrenheit(temperature), 1); | |
| Serial.print("\t\t"); | |
| Serial.print(dht.computeHeatIndex(temperature, humidity, false), 1); | |
| Serial.print("\t\t"); | |
| Serial.println(dht.computeHeatIndex(dht.toFahrenheit(temperature), humidity, true), 1); | |
| delay(2000); | |
| } | |