If you want to use the Arduino Development Board drive DHT11 to obtain temperature and humidity, it is recommended to use a third-party library, which can speed up the development of the program, and is not prone to error, the following code I have been transferred to the third-party library. For detailed installation methods, please refer to the Geek Pioneer's blog: The http://www.cnblogs.com/jikexianfeng/p/6290203.html author installs the minimum version (1.0.0). This is for better compatibility.
1 /*********************************2 code function: Temperature and humidity sensor DHT113 using functions:4 Simple_dht11_read (DHT11 sensor pin, storing humidity data address, storing temperature data address, storing 40-bit 01 data address); Obtaining temperature and humidity data functions5 using header files:6 #include <SimpleDHT.h>//need to install the library, specific installation methods see:http://www.cnblogs.com/jikexianfeng/p/6290203.html7 creation time: 2017*1*188 Author Email: [Email protected]9 ********************************/Ten#include <SimpleDHT.h> One intPinDHT11 =2; A - voidSetup () - { theSerial.begin (115200); - } - - voidLoop () + { -Serial.println ("================================="); +Serial.println ("Sample DHT11 ..."); A byteTemperatyre =0;//Temperature at byteHumidity =0;//Humidity - bytedata[ +]; - if(Simple_dht11_read (PinDHT11, &temperatyre, &humidity, data)) { -Serial.print ("Read DHT11 failed."); - return; - } inSerial.print ("Humidity (%):"); - serial.println (humidity); toSerial.print ("Temperatyre (OC)"); + serial.println (Temperatyre); -Serial.print ("Temperatyre (OF)"); the serial.println (Fahrenheit (Temperatyre)); *Serial.print ("Temperatyre (k)"); $ serial.println (Kelvin (Temperatyre));Panax NotoginsengSerial.print ("Dew Point (OC):"); - serial.println (Dewpoint (temperatyre,humidity)); the //serial.print ("Dew pointfast (OC):"); + //serial.println (Dewpointfast (temperatyre,humidity)); ADelay +); the } + - DoubleFahrenheit (byteCelsius) $ { $ return 1.8*celsius+ +; - } - the DoubleKelvin (byteCelsius) - {Wuyi returncelsius+273.15; the } - Wu DoubleDewpoint (byteCelsiusbytehumidity) - { About DoubleA0 =373.15/(273.15+Celsius); $ DoubleSUM =-7.90298* (a0-1); -sum+=5.02808*log10 (A0); -sum+=-1.3816e-78* (POW (Ten,(11.344*(1-1/A0))-1); -sum+=8.1328e-3* (POW (Ten,(-3.49149* (a0-1)))-1); ASUM+=LOG10 (1013.246); + DoubleVp=pow (Ten, sum-3)*humidity; the DoubleT =log (vp/0.61078); - return(241.88*T)/(17.558-T); $ } the the DoubleDewpointfast (byteCelsiusbytehumidity) the { the DoubleA=17.271; - Doubleb=273.7; in Doubletemp= (A*celsius)/(B+celsius) +log (humidity/ -); the DoubleTd= (b*temp)/(A-temp); the returnTd; About}
If the collected data does not have floating point data, so the floating-point character data is all 0, this is the problem of the sensor, can not be performed when the code is the question.
/////////////////////////
Reference page: http://www.cnblogs.com/jikexianfeng/p/6290203.html
Reference page: Http://wenku.baidu.com/view/dcdc9efa700abb68a982fbe0.html?re=view
Temperature and humidity sensor DHT11