Water Level Controller

Hi,

I am using the following code to make a water level controller & know very little programming. I have been successful doing so, but like to add -

  1. Dry Run Feature. While m=1 (motor ON) & if there is a absence in water flow (add time delay)the motor should switch OFF displaying "Dry Run" with buzzer ON, attempting to switch ON about 3 times (add delay between each attempt) provide reset button (this is to prime the motor and to press reset button).

Here is the code -

#include <LiquidCrystal.h>
int sump = A0;
int qut = A1;
int hlf = A2;
int thf = A3;
int ful = A4;
int motor = 8;
int buz = 7;
int s;
int q;
int h;
int t;
int f;
int i;     //motor status flag
int v = 100; //comparison variable(needs some adjustment)
int b = 0; //buzzer flag
int m = 0; //motor flag
int c = 0; //sump flag

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{

  pinMode(qut, INPUT);
  pinMode(hlf, INPUT);
  pinMode(qut, INPUT);
  pinMode(ful, INPUT);
  pinMode(sump, INPUT);
  pinMode(motor, OUTPUT);
  pinMode(buz, OUTPUT);
  lcd.begin(16, 2);
  digitalWrite(buz, LOW);
}

void loop()
{

  i = digitalRead(motor);
  s = analogRead(sump);
  q = analogRead(qut);
  h = analogRead(hlf);
  t = analogRead(thf);
  f = analogRead(ful);
  lcd.clear();

  if (f > v && t > v && h > v && q > v )
  {
    lcd.setCursor(0, 0);
    lcd.print(char(219));
    lcd.print(char(219));
    lcd.print(char(219));
    lcd.print(char(219));
    lcd.setCursor(5, 0);
    lcd.print("FULL");
    m = 0;
    b = 0;



  }
  else
  {
    if (f < v && t > v && h > v && q > v)
    {
      lcd.setCursor(0, 0);
      lcd.print(char(219));
      lcd.print(char(219));
      lcd.print(char(219));
      lcd.print("_");
      lcd.setCursor(5, 0);
      lcd.print("3/4th");
      b = 0;
    }
    else
    {
      if (f < v && t < v && h > v && q > v)
      {
        lcd.setCursor(0, 0);
        lcd.print(char(219));
        lcd.print(char(219));
        lcd.print("_");
        lcd.print("_");
        lcd.setCursor(5, 0);
        lcd.print("HALF");
        m = 1;
        b = 0;
      }
      else if (f < v && t < v && h < v && q > v)
      {
        lcd.setCursor(0, 0);
        lcd.print(char(219));
        lcd.print("_");
        lcd.print("_");
        lcd.print("_");
        lcd.setCursor(5, 0);
        lcd.print("1/4th");
        b = 0;
      }
      else
      {
        if (f < v && t < v && h < v && q < v)
        {
          lcd.setCursor(0, 0);
          lcd.print("_");
          lcd.print("_");
          lcd.print("_");
          lcd.print("_");
          lcd.setCursor(5, 0);
          lcd.print("LOW");
          b = 0;
        }
        else

        {
          digitalWrite(motor, LOW);
          lcd.setCursor(0, 0);
          lcd.print("ERROR!");
          b = 1;
        }
      }
    }
  }
  if (i == HIGH)
  {
    lcd.setCursor(0, 1);
    lcd.print("Motor ON");
  }
  else
  {
    lcd.setCursor(0, 1);
    lcd.print("Motor OFF");
  }



  if (s > v && m == 1)
  {
    digitalWrite(motor, HIGH);
  }
  if (s < v)
  {
    digitalWrite(motor, LOW);
    lcd.setCursor(11, 0);
    lcd.print("Low");
    lcd.setCursor(11, 1);
    lcd.print("Sump");
    c = 1;
  }
  if (s > v)
  {
    c = 0;
  }

  if (m == 0)
  {
    digitalWrite(motor, LOW);
  }

  if (b == 1 || c == 1)
  {
    digitalWrite(buz, HIGH);
    delay(500);
    digitalWrite(buz, LOW);
  }
  else
  {
    digitalWrite(buz, LOW);
  }
  delay(100);
  lcd.clear();
}

OK, your first task:

You need to go and read the forum instructions so that you can go back and modify your original post - the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window. Just highlight each section of code or output from the IDE and click the icon. In fact, the IDE has a "copy for forum" link to put these markings on for you so you then just paste it here in a posting window.

Do not attach it as a ".ino" file. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And that would also assume they are using a PC and have the IDE running on that PC.

But don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read. If you do not post it as "code", it can be quite garbled and is always more difficult to read.

Hi Paul

Thanks for enlightening me & I am a new member.

What is connected to the analog input pins? How do you detect the absence of water flow?

hi Outsider

Each Analog pin is closed via a magnetic float switch to positive, when the water level rises it lifts the switch making contact therefore detecting the given level.

Hi everyone

I am unable to do the coding since my programming skill is "beginner". Is there anyone who can do it for me.

Thanks in advance

hi Shekhar

I am working on a similar project:- "Water Level Controller" The function goes like this:-

  1. Two tank system a)Over Head Tank. b)Lower Sump

The overhead tank has 4 float switches detecting 1/4, 1/2, 3/4 & Full, The Lower sump has 1 float switch to detect low level.

When water level falls to 1/2 level in the OHT, the motor switches ON, rises to 3/4 and switches OFF at the Full level. In any given time if the Lower Sump water level reduces below the set level, ie above the suction pipe the motor if ON switches OFF & if OFF will switch ON only when the sump water level rises.

I am not an expert in Arduino programming so I have copied the code, made very minor changes & it works, but I needed to add Dry Run protection and posted the code in the Programming section. Still haven't got resolved. (Using the Arduino UNO). After completion I would be using the NANO.

If you want the code & are willing to change the same according to your need, let me know.

sydhalls:
Each Analog pin is closed via a magnetic float switch to positive, when the water level rises it lifts the switch making contact therefore detecting the given level.

Particularly if you are dealing with water, the "universal solvent", you should not have sensor switches connected to the positive supply.

They should be connected between an Arduino input and ground. This avoids possible faults where the supply voltage itself might accidentally become shorted to ground. You can use the "INPUT_PULLUP" option in pinMode() to enable a built-in pull-up in the Arduino, this is an effective resistance in the order of 45k, or you may need to provide a "stiffer" pull-up such as 4k7 to the Vcc. Your code logic simply needs to look for a LOW instead of a HIGH to sense switch closure.


Can't help with the code. While I often do provide code, particularly when it is already in my library (at least, before the recent disk crash :astonished: ), things are hectic nowadays and you probably would not want to pay my fees! :astonished:

I'm wondering why you are analog reading a signal that's either full ON (Vcc volts) or full OFF (0 volts), nothing in between, we usually do that with a digital input, anyway what is the time period between "qut" switching OFF and dry sump? Bad idea to run a submersible pump without being submerged in cooling water, it may overheat and fail.

I didn't get the overview in the sequence of events in your program, sections like the following

lcd.setCursor(0, 0);
    lcd.print(char(219));
    lcd.print(char(219));
    lcd.print(char(219));
    lcd.print(char(219));
    lcd.setCursor(5, 0);
    lcd.print("FULL");

are better of within a function, preferably a standarized one, but even a function called printFull() would help already.

Thank all of you for taking time to reply.

Since I am new to programming, the code was copy pasted, All your suggestions are good and may be the best. I have taken note and will be making changes.

I wouldn't mind paying a reasonable fee for the complete functional code.

I wouldn't mind paying a reasonable fee for the complete functional code.

Post in the Gigs and Collaborations forum section. You can ask a moderator to move your post (link below).

Thread moved.

@sydhalls, do not hijack. Thread split.

@sydhalls, do not cross-post. Threads merged.

Hi sydhalls,

See PM for details.