From 54f758109465dfafac3480dd69da18693a6f2b3e Mon Sep 17 00:00:00 2001 From: Denis Denisov Date: Thu, 1 Apr 2021 23:32:55 +0300 Subject: [PATCH] Reading temperature and humidity from DHT22 --- thermo_sensor/thermo_sensor.ino | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 thermo_sensor/thermo_sensor.ino 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(); +}