Merge branch 'develop' into sherzog_dev

This commit is contained in:
Sebastian 2020-06-28 11:40:38 +02:00
commit 09c045fd2e
5 changed files with 65 additions and 8 deletions

View File

@ -14,5 +14,6 @@ board = az-delivery-devkit-v4
framework = arduino framework = arduino
lib_deps = lib_deps =
# ID of Lightsensor library BH1750 439 #ID of Lightsensor library BH1750
439 19 #DHT sensor library
31 #Adafruit Unified Sensor

View File

@ -19,7 +19,7 @@ void setupCapacitiveSoilMoistureSensor() {
} }
} }
void loopCapacitiveSoilMoistureSensor() { int loopCapacitiveSoilMoistureSensor() {
// subtract the last reading: // subtract the last reading:
total = total - readings[readIndex]; total = total - readings[readIndex];
// read from the sensor: // read from the sensor:
@ -37,5 +37,6 @@ void loopCapacitiveSoilMoistureSensor() {
// calculate the average: // calculate the average:
average = total / numReadings; average = total / numReadings;
Serial.println(average);
return average;
} }

View File

@ -6,14 +6,24 @@
#include <Arduino.h> #include <Arduino.h>
#include <Wire.h> #include <Wire.h>
#include <SPI.h>
#include <BH1750.h> #include <BH1750.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
extern int meineVariable; extern int meineVariable;
// moisture // moisture
extern void setupCapacitiveSoilMoistureSensor(); extern void setupCapacitiveSoilMoistureSensor();
extern void loopCapacitiveSoilMoistureSensor(); extern int loopCapacitiveSoilMoistureSensor();
// light // light
extern void setupLightSensor(); extern void setupLightSensor();
extern int readLightSensorValue(); extern int readLightSensorValue();
// temperature & humidity
extern void setupTemperatureSensor();
extern int readHumidity();
extern int readTemperature();

View File

@ -8,6 +8,7 @@ void setup() {
Serial.begin(9600); Serial.begin(9600);
setupCapacitiveSoilMoistureSensor(); setupCapacitiveSoilMoistureSensor();
setupLightSensor(); setupLightSensor();
setupTemperatureSensor();
} }
void loop() { void loop() {
@ -16,6 +17,18 @@ void loop() {
Serial.print(lxValue); Serial.print(lxValue);
Serial.println(" lx"); Serial.println(" lx");
loopCapacitiveSoilMoistureSensor(); uint16_t mstValue = loopCapacitiveSoilMoistureSensor();
delay(200); // delay in between reads for stability 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
} }

32
src/temperatureSensor.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <header.h>
#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;
}