#define BOARDTYPE_CONSTANT "ESP8266-MP3-OTA-PushS"
// MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START *
// a detailed explanation how these macros work is given in this tutorial
// https://forum.arduino.cc/t/comfortable-serial-debug-output-short-to-write-fixed-text-name-and-content-of-any-variable-code-example/888298
#define dbg(myFixedText, variableName) \
Serial.print( F(#myFixedText " " #variableName"=") ); \
Serial.println(variableName);
#define dbgi(myFixedText, variableName,timeInterval) \
{ \
static unsigned long intervalStartTime; \
if ( millis() - intervalStartTime >= timeInterval ){ \
intervalStartTime = millis(); \
Serial.print( F(#myFixedText " " #variableName"=") ); \
Serial.println(variableName); \
} \
}
#define dbgc(myFixedText, variableName) \
{ \
static long lastState; \
if ( lastState != variableName ){ \
Serial.print( F(#myFixedText " " #variableName" changed from ") ); \
Serial.print(lastState); \
Serial.print( F(" to ") ); \
Serial.println(variableName); \
lastState = variableName; \
} \
}
#define dbgcf(myFixedText, variableName) \
{ \
static float lastState; \
if ( lastState != variableName ){ \
Serial.print( F(#myFixedText " " #variableName" changed from ") ); \
Serial.print(lastState); \
Serial.print( F(" to ") ); \
Serial.println(variableName); \
lastState = variableName; \
} \
}
// MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END *
/*NOTES:
Sketch to supply treated water to a hydroponics system.
A 12V DC water level board controls 9V power to an Arduino Uno R3 through a step down converter.
When the water is low the water level board switches power on to a water supply solenoid which is connected to the Arduino Uno R3 via a Normally Closed solenoid relay.
When the treated water tank begins to fill, a float level switch (2) in the bottom of the treated water tank closes and powers up the Uno.
The Uno then switches on a solution stirrer motor and a peristaltic pump feeding solution into the treated water tank for fixed time periods.
When the peristaltic pump stops the solution stirrer then stops.
When the water tank is full (float level switch 1 in the top of the treated water tank opens) the Uno turns off the water supply solenoid via the Normally Closed solenoid relay.
It then turns on the water transfer pump to feed hydroponic trays.
When the water tank drains, causing the water level switch 2 to open. The open circuit switches off the Uno.
*/
const byte relayDoingWhatPin = 2;
const byte stirrerMotorPin = 3;
const byte periPumpPin = 4;
const byte waterPumpPin = 5;
const byte floatSwitchPin = 6;
const byte ON = HIGH;
const byte OFF = LOW;
const byte relayOff = HIGH;
const byte relayOn = LOW;
void setup() {
Serial.begin(115200);
Serial.println("Setup-Start");
pinMode(relayDoingWhatPin, OUTPUT);
pinMode(stirrerMotorPin, OUTPUT);
pinMode(periPumpPin, OUTPUT);
pinMode(waterPumpPin, OUTPUT);
pinMode(floatSwitchPin, INPUT_PULLUP);
}
void loop() {
Serial.println("top of loop");
digitalWrite(stirrerMotorPin, ON);
dbg("01",digitalRead(stirrerMotorPin) );
delay(10000); // wait 20 seconds to get solution moving
digitalWrite(periPumpPin, ON);
dbg("02",digitalRead(periPumpPin) );
delay(1000); // delay time 20 sec to measure fertilizer
digitalWrite(periPumpPin, OFF);
dbg("03",digitalRead(periPumpPin) );
digitalWrite(stirrerMotorPin, OFF);
dbg("04",digitalRead(stirrerMotorPin) );
Serial.println("entering while-loop...");
while (digitalRead(floatSwitchPin) == LOW) { // wait until float switch 1 shows treated water tank is full
digitalWrite(relayDoingWhatPin, relayOff);
digitalWrite(waterPumpPin, ON);
}
Serial.println("exiting while while-loop...");
}