程式碼:

        #include <dht11.h>
        dht11 DHT11;
        #define DHT11PIN 4
        
        void setup()
        {
          Serial.begin(9600);
        }
        
        void loop()
        {
          int chk = DHT11.read(DHT11PIN);
          Serial.print("Read sensor: ");
          switch (chk)  //檢驗是否正常運行
          {
            case 0: Serial.println("OK"); break;
            case -1: Serial.println("Checksum error"); break;
            case -2: Serial.println("Time out error"); break;
            default: Serial.println("Unknown error"); break;
          }
          Serial.print("Humidity (%): ");  //濕度
          Serial.println((float)DHT11.humidity, 2);
          Serial.print("Temperature (oC): ");   //溫度
          Serial.println((float)DHT11.temperature, 2);
          delay(2000);
        } 


程式碼:

    Void loop(){
        Serial.print("Temperature (oF): ");
        Serial.println(Fahrenheit(DHT11.temperature), 2);	//呼叫副程式
      }
      
      double Fahrenheit(double celsius)	//副程式
      {
          return 1.8 * celsius + 32;// 華氏溫度為9/5攝氏溫度+32
      }