Project showcase
Watersource Controller

Watersource Controller © GPL3+

This Arduino project automatically switches the watersource solenoid depending on the available stored rainwater.

  • 4,485 views
  • 0 comments
  • 11 respects

Components and supplies

Ard nano
Arduino Nano R3
×1
Mfr 25frf52 10k sml
Resistor 10k ohm
×6
Oled lcd 128x64 1
ElectroPeak 0.96" OLED 64x128 Display Module
any oled display will do, just see you make the right connections. A4 -> SDA A5 -> SCL
×1
Relay Module (Generic)
this should be a common ground relay that switches when the pin is pulled low. Otherwise you have to change the code accordingly.
×1
Omron b3f 1000 image 75px
SparkFun Pushbutton switch 12mm
×1
Fairchild semiconductor 1n4004. image
1N4007 – High Voltage, High Current Rated Diode
any diode will do, and they should be put on the solenoid valves. They are important to prevent causing resets of the arduino due to current spikes when the solenoids close again. The diode should be put so that they conduct electricity from GND to VCC. This is called a flyback diode setup.
×1

Necessary tools and machines

09507 01
Soldering iron (generic)

About this project

My project is about saving tap water, because people take water for granted but it really isn't. A lot of people flush the toilet with drinking water. That's just wrong. I'm using a pump to pump up ground water to flush the toilets. But this water can't be used to wash my clothes. That's why I put a 1000 liter storage tank in de backyard to collect rainwater. In this tank are 2 floating sensor. The bottom sensor when not floating will trigger the arduino to switch to tap water. When it's raining and the upper sensor is floating, the arduino will switch back to rainwater. Only when the washine machine is requesting water, the solenoid of the correct watersource will be openend. This is achieved by using a pressure sensor that is connected to the same pipe of where the washine machine is connected. There are two tresholds according to the watersource. This is because at my place the pressure of the waterpump is lower than the tap water pressure. There is also a switch you can connect (the upper connection on the picture). Here you can connect a switch, and when in the "on" possition, the watervalve of the correct source will be openen regardless of the pressure.

One thing that cost me a lot of trouble is the resetting of the arduino when the solenoids closed. It turned out to be the recoil of the solenoids. So it is very important to put fly-back diodes on the solenoids themselves. Therefore it is important to not switch polarity when you are connecting the wires that power the solenoid. Otherwise you will cause a short. So the diode should conduct from GND to VCC on the solenoids.

Code

codeArduino
#include <Wire.h>
#include <ACROBOTIC_SSD1306.h>

int Off = LOW;
int On = HIGH;

//initializing states
int WaterRelayState = On;
int PowerRelayState = On;
int MemoryState = Off;
int ServerState = 0;
int TSSourceCity = 0;
int TSSourceRain = 0;

//setting GPIO pins
const int ManualOverride = 8;
const int WaterSupplySwitch = 7;
const int PowerSupplySwitch = 6;
const int PressureSensor = A0;
const int BottomSensor = 4;
const int TopSensor = 5;

//pressure var
float CurrentPressure = 0;
float WaterPressureToggle = 0;
float WaterPressureToggleHIGH = 0;
float WaterPressureRef = 0;
int LowValue = 0;
int HighValue = 0;

boolean FLOW = false;
boolean RECALIBRATED = true;
boolean ManualFlow = false;

String Source = "";
String val = "";

//variables for delay without using delay
unsigned long CurrentMillis = 0;    // stores the value of millis() in each iteration of loop()
unsigned long PreviousMillis = 0;


//variable to protect against disconnected hose
unsigned long RunningWater = 0;

//constants
const long Interval = 1000;
//const long Interval_Wifi = 15000;
const int MaxWaterDuration = 300;
 
const int led = 13;



void calibrate(){
  CurrentPressure = analogRead(PressureSensor);
  WaterPressureRef = CurrentPressure;
  }

void setup(void) {
  Serial.begin(115200);
  pinMode(ManualOverride, INPUT);
  pinMode(WaterSupplySwitch, OUTPUT);
  pinMode(PowerSupplySwitch, OUTPUT);
  pinMode(BottomSensor, INPUT);
  pinMode(TopSensor, INPUT);
  pinMode(PressureSensor, INPUT);

  digitalWrite(PowerSupplySwitch, PowerRelayState);
  digitalWrite(WaterSupplySwitch, WaterRelayState);
  FLOW = true;
  //checkwaterlevel(1);
  delay(5000);
  FLOW = false;
  
  calibrate();
  
  Wire.begin();  
  oled.init();                      // Initialze SSD1306 OLED display
  oled.clearDisplay();              // clear screen
}

void loop(void) {

  CurrentMillis = millis();

  if(digitalRead(ManualOverride) == LOW){
    ManualFlow = true;}
    else{
    ManualFlow = false;
  }
  
  if(CurrentMillis - PreviousMillis >= Interval) {
      PreviousMillis = CurrentMillis; 
    CurrentPressure = analogRead(PressureSensor);
    Serial.print("CurrentPressure");
    Serial.println(CurrentPressure);
    checkwaterlevel(0);
    }
}

void sense(){
      WaterPressureToggle = ((100/WaterPressureRef)*CurrentPressure);
      if(Source == "Citywater"){LowValue = 85;HighValue = 90;}
      else{LowValue = 65;HighValue = 80;
      }      
      Serial.print("WaterPressureToggle");
        if(WaterPressureToggle < LowValue or ManualFlow == true){
          FLOW =  true;
        }
        else{
            if(WaterPressureToggle > HighValue){
            FLOW = false;
            WaterPressureToggleHIGH = WaterPressureToggle;
            }
          }
    }

void checkwaterlevel(int x) {
  Serial.print("Flow state = ");
  Serial.println(ManualFlow);
  /*if (RunningWater > MaxWaterDuration) {
    sensorfault();
  }*/

  if (x==0){sense();}

  if (FLOW or ManualFlow) {
    RECALIBRATED = false;
    PowerRelayState = On;
    RunningWater += (Interval / 1000);
    if (digitalRead(BottomSensor) == LOW and digitalRead(TopSensor) == LOW) {//LOW means sensor is floating
      WaterRelayState = On;
      MemoryState = WaterRelayState; 
      Source = "Rainwater";
      Serial.println("Bottomsensor and Topsensor closed, running on rainwater");
    }
    else{
      if(digitalRead(BottomSensor) == LOW){
        WaterRelayState = MemoryState;
        if(WaterRelayState == On){Source = "Rainwater";}
        else{Source = "Citywater";}
        }
      else{
        WaterRelayState = Off;
        MemoryState = WaterRelayState; 
        Source = "Citywater";
        Serial.println("Bottomsensor open, running on Pidpa");}
      }
  }
  else
  {
    if (RECALIBRATED == false) {calibrate();RECALIBRATED == true;}
    PowerRelayState = Off;
    WaterRelayState = Off;
    Source = "No power ";
    RunningWater = 0;
  }
  lcd();
  digitalWrite(PowerSupplySwitch, PowerRelayState);
  digitalWrite(WaterSupplySwitch, WaterRelayState);
  
}

void lcd() {
  oled.setTextXY(0, 0);             // Set cursor position, start of line 0
  oled.putString("Running on ");
  oled.setTextXY(1, 0);             // Set cursor position, start of line 1
  oled.putString(Source);
  oled.setTextXY(2,0);
  oled.putString("Top=");
  oled.setTextXY(2,4);
  if (digitalRead(TopSensor) == LOW){oled.putString("WET");}else{oled.putString("DRY");}
  oled.setTextXY(2,9);
  oled.putString("Bot=");
  oled.setTextXY(2,13);
  if (digitalRead(BottomSensor) == LOW){oled.putString("WET");}else{oled.putString("DRY");}
  
  oled.setTextXY(3, 0);
  oled.putString("LO ");
  oled.setTextXY(3,4);
  oled.putString("     ");
  oled.setTextXY(3,4);
  oled.putNumber(WaterPressureToggle);
  oled.setTextXY(3,9);
  oled.putString("HI ");
  oled.setTextXY(3,13);
  oled.putString("     ");
  oled.setTextXY(3,13);
  oled.putNumber(WaterPressureToggleHIGH);
  oled.setTextXY(4, 0);
  if (PowerRelayState == On)
  {
    oled.putString("valves opened");
  }
  else
  {
    oled.putString("valves closed");
  }
  oled.setTextXY(5, 0);
  val = digitalRead(WaterSupplySwitch);
  oled.putString("          ");
  oled.setTextXY(5, 0);
  oled.putString(val);
  oled.setTextXY(6, 0);
  oled.putString("    ");
  oled.setTextXY(6, 0);
  oled.putNumber(WaterPressureToggle);
}

Schematics

schematics
Arduino watercontroller 2019 (ground to outer side) (3) ixdubifqv3

Comments

Similar projects you might like

Soldering Iron Controller for Hakko 907

Project tutorial by Alexander

  • 31,466 views
  • 22 comments
  • 70 respects

Circuito Arduino Controller Pad

Project tutorial by AhmedAzouz

  • 2,676 views
  • 1 comment
  • 7 respects

Ardunori RC - Arduino based Tenori-On Remote Controller

Video tutorial by artphrases

  • 2,420 views
  • 2 comments
  • 9 respects

Reef Controller

Project showcase by Shawn Leclair

  • 14,369 views
  • 0 comments
  • 23 respects

Arduino Home Controller Activated by Alexa

Project tutorial by Jose Cruz

  • 3,606 views
  • 6 comments
  • 11 respects

Plant Waterer Controller

Project in progress by Paulo Soares

  • 1,235 views
  • 1 comment
  • 5 respects
Add projectSign up / Login