Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <dht11.h>
- void setup()
- {
- Serial.begin(115200);
- }
- String top;
- String bottom;
- void loop()
- {
- top = readDht(4);
- bottom = readDht(2);
- Serial.println(top+"::"+bottom);
- Serial.flush();
- delay(10000);
- }
- String readDht(int pin)
- {
- dht11 sensor;
- int chk = sensor.read(pin);
- switch (chk)
- {
- case DHTLIB_OK:
- //Serial.println("OK");
- break;
- case DHTLIB_ERROR_CHECKSUM:
- //Serial.println("Checksum error");
- return "checksum";
- break;
- case DHTLIB_ERROR_TIMEOUT:
- //Serial.println("Time out error");
- return "timeout";
- break;
- default:
- //Serial.println("Unknown error");
- break;
- }
- float humidity = (float) sensor.humidity;
- float temperature = (float) sensor.temperature;
- int h = (int) humidity;
- int t = (int) temperature;
- return String(h)+"-"+String(t);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement