From bf5805a12986566ca4a935c3148a74e60fee1f56 Mon Sep 17 00:00:00 2001 From: Tom Nordal Date: Tue, 25 Jun 2024 23:50:23 +0200 Subject: [PATCH] Add DHT11 sensor and test --- Sensors/platformio.ini | 4 ++++ Sensors/src/main.cpp | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/Sensors/platformio.ini b/Sensors/platformio.ini index ea23b77..7d8b21c 100644 --- a/Sensors/platformio.ini +++ b/Sensors/platformio.ini @@ -12,3 +12,7 @@ platform = atmelavr board = uno framework = arduino +lib_deps = + # RECOMMENDED + # Accept new functionality in a backwards compatible manner and patches + adafruit/DHT sensor library @ ^1.4.6 diff --git a/Sensors/src/main.cpp b/Sensors/src/main.cpp index 1c9f9e0..13d3c04 100644 --- a/Sensors/src/main.cpp +++ b/Sensors/src/main.cpp @@ -2,10 +2,47 @@ #include +#include +#include +// #include + +#define DHTTYPE DHT11 +#define DHTPIN 2 + +DHT dht(DHTPIN, DHTTYPE); + +float humidity; +float tempC; +float tempF; + +int setTime = 500; + + void setup() { // put your setup code here, to run once: + Serial.begin(9600); + Serial.println("DHT11 test!"); + + dht.begin(); + delay(setTime); + + } void loop() { // put your main code here, to run repeatedly: + humidity = dht.readHumidity(); + tempC = dht.readTemperature(); + tempF = dht.readTemperature(true); + + Serial.print("Humidity: "); + Serial.print(humidity); + Serial.print(" Temperature: "); + Serial.print(tempC); + Serial.print(" *C "); + Serial.print(tempF); + Serial.println(" *F"); + + delay(setTime * 2); + }