setup basic temperature sample
This commit is contained in:
parent
73e0739815
commit
ec56181c08
@ -15,4 +15,6 @@ framework = arduino
|
|||||||
|
|
||||||
lib_deps =
|
lib_deps =
|
||||||
# ID of Lightsensor library BH1750
|
# ID of Lightsensor library BH1750
|
||||||
439
|
439
|
||||||
|
DHT sensor library
|
||||||
|
Adafruit Unified Sensor
|
||||||
@ -7,6 +7,10 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <BH1750.h>
|
#include <BH1750.h>
|
||||||
|
#include <Adafruit_Sensor.h>
|
||||||
|
#include <DHT.h>
|
||||||
|
#include <DHT_U.h>
|
||||||
|
|
||||||
|
|
||||||
extern int meineVariable;
|
extern int meineVariable;
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@ void setup() {
|
|||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
setupCapacitiveSoilMoistureSensor();
|
setupCapacitiveSoilMoistureSensor();
|
||||||
setupLightSensor();
|
setupLightSensor();
|
||||||
|
setupTemperatureSensor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|||||||
67
src/temperatureSensor.cpp
Normal file
67
src/temperatureSensor.cpp
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#include <header.h>
|
||||||
|
|
||||||
|
#define DHTPIN 4
|
||||||
|
|
||||||
|
#define DHTTYPE DHT11 // DHT 11
|
||||||
|
|
||||||
|
|
||||||
|
DHT_Unified dht(DHTPIN, DHTTYPE);
|
||||||
|
|
||||||
|
uint32_t delayMS;
|
||||||
|
|
||||||
|
void setupTemperatureSensor() {
|
||||||
|
Serial.begin(9600);
|
||||||
|
// Initialize device.
|
||||||
|
dht.begin();
|
||||||
|
Serial.println(F("DHT11 Unified Sensor Example"));
|
||||||
|
// Print temperature sensor details.
|
||||||
|
sensor_t sensor;
|
||||||
|
dht.temperature().getSensor(&sensor);
|
||||||
|
Serial.println(F("------------------------------------"));
|
||||||
|
Serial.println(F("Temperature Sensor"));
|
||||||
|
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
|
||||||
|
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
|
||||||
|
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
|
||||||
|
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("°C"));
|
||||||
|
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("°C"));
|
||||||
|
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("°C"));
|
||||||
|
Serial.println(F("------------------------------------"));
|
||||||
|
// Print humidity sensor details.
|
||||||
|
dht.humidity().getSensor(&sensor);
|
||||||
|
Serial.println(F("Humidity Sensor"));
|
||||||
|
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
|
||||||
|
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
|
||||||
|
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
|
||||||
|
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("%"));
|
||||||
|
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("%"));
|
||||||
|
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("%"));
|
||||||
|
Serial.println(F("------------------------------------"));
|
||||||
|
// Set delay between sensor readings based on sensor details.
|
||||||
|
delayMS = sensor.min_delay / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
void loopTemperatureSensor() {
|
||||||
|
// Delay between measurements.
|
||||||
|
delay(delayMS);
|
||||||
|
// Get temperature event and print its value.
|
||||||
|
sensors_event_t event;
|
||||||
|
dht.temperature().getEvent(&event);
|
||||||
|
if (isnan(event.temperature)) {
|
||||||
|
Serial.println(F("Error reading temperature!"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Serial.print(F("Temperature: "));
|
||||||
|
Serial.print(event.temperature);
|
||||||
|
Serial.println(F("°C"));
|
||||||
|
}
|
||||||
|
// Get humidity event and print its value.
|
||||||
|
dht.humidity().getEvent(&event);
|
||||||
|
if (isnan(event.relative_humidity)) {
|
||||||
|
Serial.println(F("Error reading humidity!"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Serial.print(F("Humidity: "));
|
||||||
|
Serial.print(event.relative_humidity);
|
||||||
|
Serial.println(F("%"));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user