#define VERSION "2023-01-03-03"
/*
*********** INFO ***********
Geschrieben für Arduino Nano
CODE SCHÖNER SCHREIBEN!!!!
**** SIMULATOR: https://wokwi.com/projects/352293125068070913 ****
ERROR Codes:
2x -> Water Pump runs to long! (to less water?)
*********** Wassersensor ***********
https://www.bastelgarage.ch/xkc-y25-v-non-contact-digital-wasser-liquid-level-sensor
Anschluss Belegung XKC-Y25-V:
VCC Braun
Out Gelb
GND Blau
Mode Schwarz
*********** Todo ***********
- Sicherhietsfunktionen
+ Fehlercode durch schnelleres Blinken und dann Pause anzeigen 2 -> 2mal blinken 3 -> 3mal ...
+ im Fehlerfall alle Relais immer aus!
- Fehlerzustände
+ zu langes Pumpen -> Fehler 2
+ Notfallschalter springt an -> Fehler 3
- clear part of display using: display.fillRect( x, y, width, height, BLACK);
+ Char Size width=5, height=7 , char + 1 space -> 6 pixel Width
+ Display Simulator: https://wokwi.com/projects/352283290710105089
- Display 0x3C (SSD1306)
- ds18b20 temperatursensor
https://diyusthad.com/image2cpp
*********** WÜNSCHE ***********
- Auffüllautomatik
- Wasserwechselautomatik
*********** Vorbild ***********
Vorbild: Tunze Osmolator Universal Wasser Nachfüllanlage
Funktion:
Im TUNZE Osmolator sind immer zwei
Sensoren eingesetzt, d.h. ein Arbeitssensor (5)
zur Überwachung des Wasserniveaus und
ein Sicherheitssensor (6) gegen Überfüllung
des Aquariums. Der Arbeitssensor tastet die
Wasseroberfläche ab und initiiert bei Unterschreitung
des eingestellten Wasserniveaus den Controller (7).
Dieser schaltet die Dosierpumpe (2) ein, die soviel
Wasser aus dem Vorratsbehälter ins Aquarium
fördert, bis die verdunstete Wassermenge ersetzt
ist. Danach schaltet der Controller mit elektronischer
Zeitüberwachung die Dosierpumpe automatisch ab.
Sollte aus technischen Gründen der Arbeitssensor
versagen, verhindert der Sicherheitssensor das
Überfüllen des Aquariums und es ertönt ein
Signalton. Läuft die Dosierpumpe länger als 10 Min.
wird sie zur Sicherheit abgeschaltet.
*********** Watchdog ***********
15mS WDTO_15MS
30mS WDTO_30MS
60mS WDTO_60MS
120mS WDTO_120MS
250mS WDTO_250MS
500mS WDTO_500MS
1S WDTO_1S
2S WDTO_2S
4S WDTO_4S
8S WDTO_8S
D2 & D3 -> Interrupt Pins!
*********** Simulator ***********
Display:
https://wokwi.com/projects/327308213042020946
*/
// SSD1306 display
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define DEGREE_SIGN char(248) // https://learn.adafruit.com/adafruit-gfx-graphics-library/graphics-primitives
// DS18B20 Temperatursensor
#include <OneWire.h>
#include <DallasTemperature.h>
// Enable Watchdog
#include <avr/wdt.h>
#define DEBUG 1
#define LED LED_BUILTIN // LED on PIN 13
#define WATER_SENSOR_HIGH 2 // D2
#define WATER_SENSOR_LOW 3 // D3
#define ONE_WIRE_BUS 4 // D4 Datapin for ds18b20
#define RELAY1 7 // D7
#define RELAY2 8 // D8
#define RELAY3 10 // D10
#define RELAY4 11 // D11
#define LED_ON 1
#define LED_OFF 0
#define RELAY_ON 0
#define RELAY_OFF 1
#define WATER_SENSOR_NO_WATER 0
#define WATER_SENSOR_WATER 1
#define TIME_REFILL 120
#define TIME_REFILL_INIT 600
#if DEBUG == 1
#define debug(x) Serial.print(x)
#define debugln(x) Serial.println(x)
#else
#define debug(x)
#define debugln(x)
#endif
// 'Aquarium-Final-Small', 72x64px
const unsigned char Aquarium[] PROGMEM = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0x00, 0x1c, 0x38, 0x00, 0x00, 0x00,
0x00, 0x03, 0xf0, 0x00, 0x1c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x03, 0x38, 0x00, 0x1c, 0x38, 0x00,
0x00, 0x00, 0x07, 0x03, 0x38, 0x00, 0x1c, 0x38, 0x00, 0x00, 0x00, 0x0f, 0x83, 0xf8, 0x00, 0x1c,
0x38, 0x00, 0x30, 0x00, 0x1f, 0xc1, 0xf0, 0x00, 0x1c, 0x38, 0x00, 0x7c, 0x78, 0x18, 0xc0, 0xc0,
0x00, 0x1c, 0x38, 0x00, 0xff, 0xfc, 0x1d, 0xc0, 0x00, 0x00, 0x1c, 0x38, 0x01, 0xcf, 0xcc, 0x1f,
0xc0, 0x00, 0x00, 0x1c, 0x38, 0x03, 0xc7, 0x8e, 0x0f, 0x80, 0x70, 0x00, 0x1c, 0x38, 0x03, 0x83,
0x87, 0x00, 0x03, 0xfc, 0x00, 0x1c, 0x38, 0x07, 0x01, 0xc7, 0x00, 0x1f, 0xfe, 0x00, 0x1c, 0x38,
0x0e, 0x00, 0xe3, 0x81, 0xff, 0x8e, 0x00, 0x1c, 0x38, 0x0c, 0x00, 0xe1, 0x83, 0xff, 0xe6, 0x0f,
0xdc, 0x38, 0x0c, 0x38, 0x61, 0x87, 0x9c, 0xfe, 0x1f, 0xdc, 0x38, 0x0e, 0x38, 0xe1, 0x8e, 0x0c,
0x3e, 0x7f, 0xdc, 0x38, 0x0e, 0x38, 0xc3, 0x8c, 0x0e, 0x0f, 0x73, 0x9c, 0x38, 0x07, 0x39, 0xc7,
0x9c, 0x0e, 0x07, 0xe3, 0x1c, 0x38, 0x03, 0x39, 0x87, 0x1c, 0x4e, 0x03, 0xc7, 0x1c, 0x38, 0x03,
0x3b, 0x8e, 0x18, 0x46, 0x01, 0xce, 0x1c, 0x38, 0x03, 0x3b, 0x8c, 0x18, 0x06, 0x01, 0xc6, 0x1c,
0x38, 0x07, 0x39, 0x8c, 0x1c, 0x0e, 0x03, 0xc7, 0x1c, 0x38, 0x07, 0x39, 0xce, 0x1c, 0xce, 0x07,
0xe3, 0x9c, 0x38, 0x0e, 0x38, 0xe6, 0x0f, 0x8c, 0x1e, 0x73, 0x9c, 0x38, 0x0c, 0x38, 0xe6, 0x0f,
0x1c, 0x7e, 0x3f, 0xdc, 0x38, 0x0c, 0x38, 0x67, 0x07, 0xdf, 0xfe, 0x1f, 0xdc, 0x3c, 0x0c, 0x38,
0x67, 0x03, 0xff, 0xe6, 0x07, 0xdc, 0x3f, 0x0e, 0x38, 0xe7, 0x00, 0xff, 0x8e, 0x00, 0x1c, 0x3f,
0xee, 0x38, 0xce, 0x00, 0x0f, 0xfc, 0x00, 0x1c, 0x39, 0xff, 0x39, 0xdc, 0x00, 0x01, 0xf8, 0x00,
0x1c, 0x38, 0x7f, 0x3b, 0xbc, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x38, 0x0f, 0xbb, 0xb8, 0x00, 0x00,
0x00, 0x00, 0x1c, 0x38, 0x01, 0xff, 0x70, 0x00, 0x00, 0x01, 0xff, 0xfc, 0x38, 0x01, 0xfe, 0xe0,
0x00, 0x00, 0x07, 0xff, 0xfc, 0x38, 0x00, 0xff, 0xff, 0x00, 0x00, 0x1f, 0x00, 0x1c, 0x38, 0xc0,
0x7f, 0xff, 0x80, 0x1f, 0xfc, 0x00, 0x1c, 0x38, 0xc0, 0x3f, 0xff, 0xc0, 0x7f, 0xf0, 0x00, 0x1c,
0x38, 0x00, 0x00, 0x00, 0xe0, 0x7f, 0xc0, 0x00, 0x1c, 0x38, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00,
0x00, 0x1c, 0x38, 0x00, 0x00, 0x70, 0x3e, 0x00, 0x00, 0x0c, 0x1c, 0x38, 0x0e, 0x00, 0x70, 0x1f,
0xc0, 0x00, 0x0c, 0x1c, 0x38, 0x0e, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x1c, 0x38, 0x00, 0x00,
0x00, 0x00, 0x7f, 0xc0, 0x00, 0x1c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xfc, 0x00, 0x1c, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
/*
Setup
*/
// DS18B20 Temperatur Sensor
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
#define MAX_TXT_CHAR_LENGHT 150
const char ERR_1[] PROGMEM = "\
1234567890-1234567890\n\
2234567890-1234567890\n\
3234567890-1234567890\n\
4234567890-1234567890\n\
5234567890-1234567890\n\
6234567890-1234567890";
const char ERR_2[] PROGMEM = "Water refill Timeout!";
const char ERR_3[] PROGMEM = "Water Sensor logic problem!";
const char *const ERR_table[] PROGMEM = { ERR_1, ERR_2, ERR_3 };
#define STATE_normal 0
#define STATE_init 1
#define STATE_full 2
#define STATE_delay 3
#define STATE_refill 4
#define STATE_booting 5
const char STAT_0[] PROGMEM = "normal";
const char STAT_1[] PROGMEM = "init";
const char STAT_2[] PROGMEM = "full";
const char STAT_3[] PROGMEM = "delay";
const char STAT_4[] PROGMEM = "refill";
const char STAT_5[] PROGMEM = "booting";
const char *const STAT_table[] PROGMEM = { STAT_0, STAT_1, STAT_2, STAT_3, STAT_4, STAT_5 };
volatile uint8_t PINCHANGE = 0;
bool WATER_SENSOR_HIGH_value = 0;
bool WATER_SENSOR_LOW_value = 0;
void IRQ_PINCHANGE() {
PINCHANGE++;
}
void setup() {
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(RELAY4, OUTPUT);
digitalWrite(RELAY1, RELAY_OFF);
digitalWrite(RELAY2, RELAY_OFF);
digitalWrite(RELAY3, RELAY_OFF);
digitalWrite(RELAY4, RELAY_OFF);
Serial.begin(115200);
Serial.print(F("Aquarium Nachfüllautomat\nVersion: "));
Serial.println(F(VERSION));
pinMode(LED, OUTPUT);
pinMode(WATER_SENSOR_HIGH, INPUT_PULLUP);
pinMode(WATER_SENSOR_LOW, INPUT_PULLUP);
WATER_SENSOR_HIGH_value = digitalRead(WATER_SENSOR_HIGH);
WATER_SENSOR_LOW_value = digitalRead(WATER_SENSOR_LOW);
sensors.begin(); // DS18b20
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
}
display.cp437(true);
// Draw nice image
display.clearDisplay();
display.drawBitmap(30, 0, Aquarium, 72, 64, WHITE);
display.display();
display.setTextSize(1);
display.setTextColor(WHITE);
#if DEBUG == 1
digitalWrite(RELAY1, RELAY_ON);
digitalWrite(RELAY2, RELAY_OFF);
delay(100);
digitalWrite(RELAY2, RELAY_ON);
digitalWrite(RELAY1, RELAY_OFF);
delay(100);
digitalWrite(RELAY3, RELAY_ON);
digitalWrite(RELAY2, RELAY_OFF);
delay(100);
digitalWrite(RELAY4, RELAY_ON);
digitalWrite(RELAY3, RELAY_OFF);
delay(100);
digitalWrite(RELAY4, RELAY_OFF);
#endif
pinMode(RELAY4, INPUT);
Serial.println(F("Booting Done"));
// Enable Watchdog 1s
wdt_enable(WDTO_1S);
// Enable IRQ for Watersensors
attachInterrupt(digitalPinToInterrupt(WATER_SENSOR_HIGH), IRQ_PINCHANGE, CHANGE);
attachInterrupt(digitalPinToInterrupt(WATER_SENSOR_LOW), IRQ_PINCHANGE, CHANGE);
sei();
// Clear Display after Boot
display.clearDisplay();
display.display();
// Read the Temperatur Sensor
readDS18B20TemperaturSensor();
// if Waterlevelsensor 1 & 2 are low, set inital long waterfilling
if (WATER_SENSOR_HIGH_value == WATER_SENSOR_NO_WATER && WATER_SENSOR_LOW_value == WATER_SENSOR_NO_WATER) { fillWater(TIME_REFILL_INIT, STATE_init); }
if (WATER_SENSOR_HIGH_value == WATER_SENSOR_WATER && WATER_SENSOR_LOW_value == WATER_SENSOR_NO_WATER) { fillWater(TIME_REFILL, STATE_refill); }
if (WATER_SENSOR_HIGH_value == WATER_SENSOR_WATER && WATER_SENSOR_LOW_value == WATER_SENSOR_WATER) { displayHighAndLow(STATE_full); }
PINCHANGE++;
}
// Time Loop Mills
unsigned long currentMillis = 0;
unsigned long previousMillis_10ms = 0;
unsigned long previousMillis_100ms = 0;
unsigned long previousMillis_1000ms = 0;
uint16_t REFILL_COUNTER = 0;
float temperatursensor = 0;
/*
Main Loop
*/
void loop() {
//for security, if WATER_SENSOR_HIGH detects water, shutdown Waterpump
if (digitalRead(WATER_SENSOR_HIGH) == WATER_SENSOR_WATER){digitalWrite(RELAY1, RELAY_OFF);digitalWrite(RELAY2, RELAY_OFF);}
currentMillis = millis();
// Loop every 10ms
if (currentMillis - previousMillis_10ms >= 10) {
loopEvery10ms();
previousMillis_10ms = currentMillis;
}
// Loop every 100ms
if (currentMillis - previousMillis_100ms >= 100) {
loopEvery100ms();
previousMillis_100ms = currentMillis;
}
// Loop every 1s
if (currentMillis - previousMillis_1000ms >= 1000) {
loopEvery1000ms();
previousMillis_1000ms = currentMillis;
}
}
// Time Loops
void loopEvery10ms() {
if (pinStatus()) {
if (WATER_SENSOR_HIGH_value == WATER_SENSOR_WATER && WATER_SENSOR_LOW_value == WATER_SENSOR_NO_WATER) { displayHighAndLow(STATE_normal); }
if (WATER_SENSOR_HIGH_value == WATER_SENSOR_WATER && WATER_SENSOR_LOW_value == WATER_SENSOR_WATER) { displayHighAndLow(STATE_full); }
if (WATER_SENSOR_HIGH_value == WATER_SENSOR_NO_WATER && WATER_SENSOR_LOW_value == WATER_SENSOR_NO_WATER) {
fillWater(TIME_REFILL, STATE_refill);
REFILL_COUNTER++;
}
}
wdt_reset();
}
void loopEvery100ms() {
}
void loopEvery1000ms() {
setLED();
updateDisplay();
if ((currentMillis / 1000) % 5 == 0) { readDS18B20TemperaturSensor(); } // alle 5 sekunden Temperatur auslesen
}
// normal functions
void updateDisplay() {
//display.clearDisplay();
//display.fillRect(0, 0,128, 21, BLACK);
display.fillRect(0, 0, 128, 38, BLACK);
display.setTextSize(3);
display.setCursor(0, 2);
// Display static text
display.print(temperatursensor);
display.print(DEGREE_SIGN);
display.println(F("C"));
display.setTextSize(1);
display.setCursor(0, 30);
display.print(F("C: "));
display.print(REFILL_COUNTER);
display.print(F(" T: "));
display.print((unsigned long)currentMillis / 3600000);
display.print(F("h"));
display.display();
}
bool pinStatus() {
if (PINCHANGE) {
PINCHANGE = 0;
WATER_SENSOR_HIGH_value = digitalRead(WATER_SENSOR_HIGH);
WATER_SENSOR_LOW_value = digitalRead(WATER_SENSOR_LOW);
// The following combinations are not possible -> error
if (WATER_SENSOR_HIGH_value == WATER_SENSOR_NO_WATER && WATER_SENSOR_LOW_value == WATER_SENSOR_WATER) { error(3); }
displayHighAndLow();
return true;
}
return false;
}
#define H_y 50
#define C_SIZE 6
void displayHighAndLow(uint8_t state) {
displayHighAndLow();
char buffer[20];
strcpy_P(buffer, (char *)pgm_read_word(&(STAT_table[state])));
display.setCursor(50, H_y);
display.print(F("State: "));
display.fillRect(85, H_y, 128, 21, BLACK);
//display.print(state);
display.print(buffer);
display.display();
}
void displayHighAndLow() {
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, H_y);
display.print(F("H"));
display.setCursor(25, H_y);
display.print(F("L"));
if (WATER_SENSOR_HIGH_value == WATER_SENSOR_WATER) {
display.fillCircle(14, H_y + (C_SIZE / 2), C_SIZE, WHITE);
} else {
display.fillCircle(14, H_y + (C_SIZE / 2), C_SIZE, BLACK);
display.drawCircle(14, H_y + (C_SIZE / 2), C_SIZE, WHITE);
}
if (WATER_SENSOR_LOW_value == WATER_SENSOR_WATER) {
display.fillCircle(39, H_y + (C_SIZE / 2), C_SIZE, WHITE);
} else {
display.fillCircle(39, H_y + (C_SIZE / 2), C_SIZE, BLACK);
display.drawCircle(39, H_y + (C_SIZE / 2), C_SIZE, WHITE);
}
display.display();
}
#define Faktor1 (0.8)
#define Faktor2 (1 - Faktor1)
void readAnalogSensor(unsigned int *value, int number) {
unsigned int new_value = analogRead(number);
float t = *value;
t = Faktor1 * t + Faktor2 * new_value;
*value = (int)(t + 0.5); // Kaufmännisch gerundet
}
void readDS18B20TemperaturSensor() {
sensors.requestTemperatures(); // Send the command to get temperatures
temperatursensor = sensors.getTempCByIndex(0);
if (temperatursensor == DEVICE_DISCONNECTED_C) {
Serial.println("Error: Could not read temperature data");
}
}
void fillWater(uint16_t timeout, uint8_t state) {
currentMillis = millis();
unsigned long previousMillis = currentMillis;
display.clearDisplay();
display.setTextSize(3);
display.setCursor(0, 0);
display.print(timeout);
displayHighAndLow(state);
digitalWrite(RELAY1, RELAY_ON);
digitalWrite(RELAY2, RELAY_ON);
while (timeout > 0) {
wdt_reset();
pinStatus();
currentMillis = millis();
if ((currentMillis - previousMillis) >= 1000) {
previousMillis = currentMillis;
timeout--;
display.fillRect(0, 0, 128, 21, BLACK);
display.setTextSize(3);
display.setCursor(0, 0);
display.print(timeout);
display.display();
}
if (state == STATE_init && (WATER_SENSOR_HIGH_value == WATER_SENSOR_WATER || WATER_SENSOR_LOW_value == WATER_SENSOR_WATER)) {
break;
}
if (state == STATE_refill && (WATER_SENSOR_HIGH_value == WATER_SENSOR_WATER && WATER_SENSOR_LOW_value == WATER_SENSOR_WATER)) {
displayHighAndLow(STATE_full);
break;
}
} // END WHILE loop
digitalWrite(RELAY1, RELAY_OFF);
digitalWrite(RELAY2, RELAY_OFF);
if (timeout == 0) { error(2); }
}
/*
ERROR -> Never leave error Function until Reset the Nano!
Noch nicht schön, eine Funktion ohne Delay wäre schöner
*/
void error(unsigned int error_code) {
char buffer[MAX_TXT_CHAR_LENGHT];
strcpy_P(buffer, (char *)pgm_read_word(&(ERR_table[error_code - 1]))); // https://www.arduino.cc/reference/en/language/variables/utilities/progmem/
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.print(F("ERROR: "));
display.print(error_code);
display.setCursor(0, 17);
display.setTextSize(1);
display.print(buffer);
display.display();
while (1) {
allRelaysOff();
Serial.print(F("**** ERROR CODE: "));
Serial.print(error_code);
Serial.println(F(" ****"));
Serial.println(buffer);
// Show the Error Number on the internal led as blink code
for (unsigned int i = 0; i < error_code; i++) {
digitalWrite(LED, LED_ON);
delay(500);
wdt_reset();
digitalWrite(LED, LED_OFF);
delay(500);
wdt_reset();
}
// LED OFF for 3sec
for (unsigned int i = 0; i < 30; i++) {
delay(100);
wdt_reset();
}
}
}
void allRelaysOff() {
digitalWrite(RELAY1, RELAY_OFF);
digitalWrite(RELAY2, RELAY_OFF);
digitalWrite(RELAY3, RELAY_OFF);
}
void setLED() {
digitalWrite(LED, !digitalRead(LED));
}
// ************ OLD PROGRAMM PART ************
/*
void readWaterSensor(unsigned int *value, int number){
bool digitalValue=digitalRead(number);
float FaktorWater1=0.99;
if(digitalValue==1){FaktorWater1=0.9;}
float FaktorWater2=1-FaktorWater1;
unsigned int new_value=digitalValue*1000;
float t=*value;
t=FaktorWater1 * t + FaktorWater2 * new_value;
//t+=0.5; // Kaufmännisch gerundet debug(F("FLOAT :"));
*value=(int)(t);
}
void readSensor(unsigned char number){
readWaterSensor(&WATER1, WATER_SENSOR1);
int sensorVal = digitalRead(number);
debug(F("Water1: "));
debug(WATER1);
debug(F(" Sensor: "));
debugln(sensorVal);
if(WATER1>=990){
digitalWrite(RELAY1,RELAY_OFF);
digitalWrite(RELAY2,RELAY_OFF);
TIME_WATER_ON=0;
} else if (WATER1<=1){
if(digitalRead(RELAY1)==RELAY_OFF){REFILLS++;}
digitalWrite(RELAY1,RELAY_ON);
digitalWrite(RELAY2,RELAY_ON);
}
}
*/
Relais 1
Relais 2
Relais 3
Relais4