commit 54f758109465dfafac3480dd69da18693a6f2b3e Author: Denis Denisov Date: Thu Apr 1 23:32:55 2021 +0300 Reading temperature and humidity from DHT22 diff --git a/thermo_sensor/thermo_sensor.ino b/thermo_sensor/thermo_sensor.ino new file mode 100644 index 0000000..14df049 --- /dev/null +++ b/thermo_sensor/thermo_sensor.ino @@ -0,0 +1,36 @@ +#include "DHT.h" + +#define DHTPIN 5 +#define DHTTYPE DHT22 + +DHT dht(DHTPIN, DHTTYPE); + +void setup() { + Serial.begin(115200); + Serial.println("Initialised..."); + + dht.begin(); +} + +void loop() +{ + delay(1500); + + float h = dht.readHumidity(); + float t = dht.readTemperature(); + + if (isnan(h) || isnan(t)) { + Serial.println("Error. Can't get humidity/temperature."); + return; + } + + Serial.print("Temperature: "); + Serial.print(t); + + Serial.print(" "); + + Serial.print("Humidity: "); + Serial.print(h); + + Serial.println(); +}