arduinoprojects

git clone https://git.tarina.org/arduinoprojects
Log | Files | Refs

DHT11WithRawBits.ino (1106B)


      1 #include <SimpleDHT.h>
      2 
      3 // for DHT11, 
      4 //      VCC: 5V or 3V
      5 //      GND: GND
      6 //      DATA: 2
      7 int pinDHT11 = 2;
      8 SimpleDHT11 dht11(pinDHT11);
      9 
     10 void setup() {
     11   Serial.begin(115200);
     12 }
     13 
     14 void loop() {
     15   // start working...
     16   Serial.println("=================================");
     17   Serial.println("Sample DHT11 with RAW bits...");
     18   
     19   // read with raw sample data.
     20   byte temperature = 0;
     21   byte humidity = 0;
     22   byte data[5] = {0};
     23   int err = SimpleDHTErrSuccess;
     24   if ((err = dht11.read(&temperature, &humidity, data)) != SimpleDHTErrSuccess) {
     25     Serial.print("Read DHT11 failed, err="); Serial.print(SimpleDHTErrCode(err));
     26     Serial.print(","); Serial.println(SimpleDHTErrDuration(err)); delay(1000);
     27     return;
     28   }
     29   
     30   Serial.print("Sample RAW Bits: ");
     31   for (int i = 0; i < 5; i++) {
     32     for(int n=0;n<8;n++)
     33       Serial.print(bitRead(data[i],n));   
     34     Serial.print(' ');
     35   }
     36   Serial.println("");
     37   
     38   Serial.print("Sample OK: ");
     39   Serial.print((int)temperature); Serial.print(" *C, ");
     40   Serial.print((int)humidity); Serial.println(" H");
     41   
     42   // DHT11 sampling rate is 1HZ.
     43   delay(1500);
     44 }