Automatic Water change

Hi Blynkers,

I came up with an idea for my aquarium. Every week I have to do a 25% water change over and over again. So I tougth of programming a Wemos board to do all the draining and filling by it self. The system will consist of 4 float sensors. Two in the aquarium where the water needs to stop draning and another one at the top to prevent over flowing. One other sensor at the top of the drain bucket and the other one at the bottom of the bucket to prevent me from burning the pump due to low water. I will have a relay to control the pump to fill the aquarium and a solenoid valve to drain pipe coming from the aquarium to the drain bucket. I think I wont need another pump to drain the aquarium I will be using the power of gravity the drain the water. As a sefety procedure I will have a soil water sensor of of ebay the stop the pump and alert me if there is water on the floor near the aquarium. I will think that will come in handy someday :wink: . In the Blynk app I will have 4 buttons. One to start filling the aquarium, one to turn the water valve on and off to drain the aquarium just till the stop sensor. Another one the start the whole process on and the forth button the stop everything.

This is the code so far but I got stuck due to my lack of skills :sweat: Withe this code the Board is resetting and giving a lot of garbage when you toggle the button. I also attached a copy of my dashboard. Can some one help me with this code I an completely lost?

This is the garbage I was talking about in the serial monitor. After the arduino resets.

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#define drain_bucket_full 16 //D0
#define fill_bucket_empty 14 //D5
#define aquarium_empty 12 //D6
# define aquarium_full 5 //D1

#define Fill_Pump 15 //D8 Relay
#define drain 13 //D7 Solenoid

#define watersensor A0

char auth[] = "501xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx71a2";
char ssid[] = "ClxxxxxxxxxxxxxxxxxxxxxxxxxxWi-Fi";
char pass[] = "clxxxxxxxxxxxxxxx3";

BLYNK_WRITE(V0) // At global scope (not inside of the function)
{
  if ( param.asInt() == 1 ) {



    while (digitalRead(fill_bucket_empty) == HIGH && digitalRead(aquarium_empty) == LOW) {
      digitalWrite(Fill_Pump, HIGH);
    }



  }

}
void setup() {

  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  while (Blynk.connect() == false) {}



  pinMode(drain_bucket_full, INPUT);
  pinMode(fill_bucket_empty, INPUT);
  pinMode(aquarium_empty, INPUT);
  pinMode(watersensor, INPUT);

  pinMode(Fill_Pump, OUTPUT);
  pinMode(drain, OUTPUT);
}

void loop() {
  Blynk.run();


}

Hi. How are you powering your board? You need something around 300 to 500 mA to power it.
Also, you could consider using a ultrasound sensor to get the level of your tank. check this project: https://lowpowerlab.com/forum/projects/heater-control-system-intefacing-with-a-ds18b20-and-a-parallax-ping-(photos)/

1 Like

I am using the Wemos D1 Mini Pro board which has everything intergraded and till now I only have 1 led instead of the relay just for testing purposes. I dont think its a power problem.

Try Googling the soft WDT reset error… I see various references to issues and solutions, but not sure which would be applicable in your case.

The soft WDT reset is only happening when I use the while loop.

@claytoncamilleri100 while and ESP’s don’t go well together. You tend to get in a continuous loop that will crash the ESP. Consider better coding.

Oh thats why then. But is there a way to get around this and make the code work?

Has man walked on the moon?

What precisely is the while statement trying to do?

In place of while statement you normally use a timer check at intervals i.e. is something still on / off etc.

Yes… I have noticed how errors only happen when doing something wrong :wink:

Anyhow… If you are using a Wemos, why does your Serial Monitor show Arduino? I don’t know if it will affect your issue, but perhaps make sure you are using the correct settings in the IDE (and might as well check the app also) for your actual board type.