diff --git a/platformio.ini b/platformio.ini index 16bf944..7d75caf 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,5 +14,6 @@ board = az-delivery-devkit-v4 framework = arduino lib_deps = - # ID of Lightsensor library BH1750 - 439 \ No newline at end of file + 439 #ID of Lightsensor library BH1750 + 19 #DHT sensor library + 31 #Adafruit Unified Sensor \ No newline at end of file diff --git a/src/capacitiveSoilMoistureSensor.cpp b/src/capacitiveSoilMoistureSensor.cpp index 116061f..4f69fb6 100644 --- a/src/capacitiveSoilMoistureSensor.cpp +++ b/src/capacitiveSoilMoistureSensor.cpp @@ -19,7 +19,7 @@ void setupCapacitiveSoilMoistureSensor() { } } -void loopCapacitiveSoilMoistureSensor() { +int loopCapacitiveSoilMoistureSensor() { // subtract the last reading: total = total - readings[readIndex]; // read from the sensor: @@ -37,5 +37,6 @@ void loopCapacitiveSoilMoistureSensor() { // calculate the average: average = total / numReadings; - Serial.println(average); + + return average; } \ No newline at end of file diff --git a/src/header.h b/src/header.h index ee66b47..2d52083 100644 --- a/src/header.h +++ b/src/header.h @@ -6,14 +6,24 @@ #include #include +#include #include +#include +#include +#include + extern int meineVariable; // moisture extern void setupCapacitiveSoilMoistureSensor(); -extern void loopCapacitiveSoilMoistureSensor(); +extern int loopCapacitiveSoilMoistureSensor(); // light extern void setupLightSensor(); -extern int readLightSensorValue(); \ No newline at end of file +extern int readLightSensorValue(); + +// temperature & humidity +extern void setupTemperatureSensor(); +extern int readHumidity(); +extern int readTemperature(); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 44e2c7c..faf23ca 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ void setup() { Serial.begin(9600); setupCapacitiveSoilMoistureSensor(); setupLightSensor(); + setupTemperatureSensor(); } void loop() { @@ -16,6 +17,18 @@ void loop() { Serial.print(lxValue); Serial.println(" lx"); - loopCapacitiveSoilMoistureSensor(); - delay(200); // delay in between reads for stability + uint16_t mstValue = loopCapacitiveSoilMoistureSensor(); + Serial.print("Soil moisture: "); + Serial.println(mstValue); + + uint16_t humidityValue = readHumidity(); + Serial.print("Humidity: "); + Serial.println(humidityValue); + + uint16_t temperatureValue = readTemperature(); + Serial.print("Temperature: "); + Serial.println(temperatureValue); + Serial.print("\n"); + + delay(2000); // delay in between reads for stability } \ No newline at end of file diff --git a/src/temperatureSensor.cpp b/src/temperatureSensor.cpp new file mode 100644 index 0000000..53789b6 --- /dev/null +++ b/src/temperatureSensor.cpp @@ -0,0 +1,32 @@ +#include + +#define DHTPIN 4 + +#define DHTTYPE DHT11 + + +DHT_Unified dht(DHTPIN, DHTTYPE); + +void setupTemperatureSensor() { + Serial.begin(9600); + dht.begin(); + Serial.println(F("DHT11 Unified Sensor Ready")); + sensor_t sensor; + dht.temperature().getSensor(&sensor); + +} + +// Get humidity event and its value. +int readHumidity(){ + + sensors_event_t event; + dht.humidity().getEvent(&event); + return event.relative_humidity; +} + +// Get temperature event and its value. +int readTemperature(){ + sensors_event_t event; + dht.temperature().getEvent(&event); + return event.temperature; +} \ No newline at end of file