#include <NewPing.h> //fuer Ultraschall-Sensor
#include <Wire.h> //fuer I2C Kommunikation
#include <LiquidCrystal.h> //LCD
#include <DHT.h>
#include <GyverMAX7219.h>
#define LEVELFULL 35 //Hoehe Wassersaeule wenn voll (=100%) in cm
#define LEVELEMPTY 40 //Abstand Boden zu Sensor in cm
#define VOLUME 80 //Volumen des zu messenden Mediums bei 100% in l
#define trigPin 2 // Trigger Pin
#define echoPin 3 // Echo Pin
#define MAX_DISTANCE 320 // Begrenzung fuer Ultraschallsensor
#define DHTPIN 4
#define DHTTYPE DHT22
#define TIMEDHT 1000
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
DHT dht(DHTPIN, DHTTYPE);
float duration;
float humidity, celsius, fahrenheit;
int lefty, distance, levelact, levelpercent, volumeact;
NewPing sonar(trigPin, echoPin, MAX_DISTANCE); // NewPing Setup
void setup() {
Serial.begin(9600); // nur fuer Debugzwecke
lcd.begin(16, 2);
lcd.clear();
lcd.print(" GEAR_SHREDDER");
lcd.setCursor(0, 1);
lcd.print(" CONTROLL PANEL");
}
void loop() {
delay(2000); // Wartezeit zwischen Pings (ca. 20 pings/sec). nicht kleiner als 29ms!
dht.begin();
//Messung mit Mittelung
int iterations = 5;
duration = sonar.ping_median(iterations); //duration = sonar.ping() ohne Mittelung
distance = int((duration / 2) * 0.0343); //Abstand in cm
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
humidity = dht.readHumidity();
// Read temperature as Celsius (the default)
celsius = dht.readTemperature();
//Fuellstand berechnen
levelact = (LEVELEMPTY - distance);
//Fuellstand in Prozent berechnen
levelpercent = (levelact * 100 / LEVELFULL);
//Berechnung Volumen
volumeact = ((VOLUME / 100) * levelpercent);
levelpercent = constrain(levelpercent, 0, 100); //um nur Werte zwischen 0 und 100 zu erhalten
//Display anzeigen#
lcd.clear();
lcd.print(" Wasser: ");
lcd.print(levelpercent);
lcd.print("%");
lcd.setCursor(0, 1);
lcd.print(celsius);
lcd.print("C ");
lcd.print(humidity);
lcd.print("%");
}