trying the SimpleDHT
This commit is contained in:
parent
569cd4e795
commit
7d09bff498
15 changed files with 1145 additions and 0 deletions
45
SimpleDHT/examples/DHT11WithRawBits/DHT11WithRawBits.ino
Normal file
45
SimpleDHT/examples/DHT11WithRawBits/DHT11WithRawBits.ino
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include <SimpleDHT.h>
|
||||
|
||||
// for DHT11,
|
||||
// VCC: 5V or 3V
|
||||
// GND: GND
|
||||
// DATA: 2
|
||||
int pinDHT11 = 2;
|
||||
SimpleDHT11 dht11(pinDHT11);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// start working...
|
||||
Serial.println("=================================");
|
||||
Serial.println("Sample DHT11 with RAW bits...");
|
||||
|
||||
// read with raw sample data.
|
||||
byte temperature = 0;
|
||||
byte humidity = 0;
|
||||
byte data[40] = {0};
|
||||
int err = SimpleDHTErrSuccess;
|
||||
if ((err = dht11.read(&temperature, &humidity, data)) != SimpleDHTErrSuccess) {
|
||||
Serial.print("Read DHT11 failed, err="); Serial.print(SimpleDHTErrCode(err));
|
||||
Serial.print(","); Serial.println(SimpleDHTErrDuration(err)); delay(1000);
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.print("Sample RAW Bits: ");
|
||||
for (int i = 0; i < 40; i++) {
|
||||
Serial.print((int)data[i]);
|
||||
if (i > 0 && ((i + 1) % 4) == 0) {
|
||||
Serial.print(' ');
|
||||
}
|
||||
}
|
||||
Serial.println("");
|
||||
|
||||
Serial.print("Sample OK: ");
|
||||
Serial.print((int)temperature); Serial.print(" *C, ");
|
||||
Serial.print((int)humidity); Serial.println(" H");
|
||||
|
||||
// DHT11 sampling rate is 1HZ.
|
||||
delay(1500);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue