Browse Source

Add DHT11 sensor and test

master
Tom Nordal 2 years ago
parent
commit
bf5805a129
  1. 4
      Sensors/platformio.ini
  2. 37
      Sensors/src/main.cpp

4
Sensors/platformio.ini

@ -12,3 +12,7 @@
platform = atmelavr platform = atmelavr
board = uno board = uno
framework = arduino framework = arduino
lib_deps =
# RECOMMENDED
# Accept new functionality in a backwards compatible manner and patches
adafruit/DHT sensor library @ ^1.4.6

37
Sensors/src/main.cpp

@ -2,10 +2,47 @@
#include <Arduino.h> #include <Arduino.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
// #include <DHT_U.h>
#define DHTTYPE DHT11
#define DHTPIN 2
DHT dht(DHTPIN, DHTTYPE);
float humidity;
float tempC;
float tempF;
int setTime = 500;
void setup() { void setup() {
// put your setup code here, to run once: // put your setup code here, to run once:
Serial.begin(9600);
Serial.println("DHT11 test!");
dht.begin();
delay(setTime);
} }
void loop() { void loop() {
// put your main code here, to run repeatedly: // 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);
} }

Loading…
Cancel
Save