Automatic Water pump Controller (Help me with my Project to complete)

Hi everyone, I am new to Arduino and I am trying to build an Automatic Water Pump Controller. Can anyone help me to complete my project?
https://www.tinkercad.com/things/6i1RQUcbeF5-automatic-water-pump-controller
I have made it with Tinkercad.
Here is my Code.

#include <LiquidCrystal.h>
int ledPin = 6; // LED is connected to digital pin 6
int flow=A0;  // Water flow sensor is connected to A0 Analog Pin
int qut=A1;
int hlf=A2;
int thf=A3;
int ful=A4;
int motor=8;
int buz=7;
int s;		//Flow status flag
int q;		// quater
int h;		// half
int t;		//75 %
int f;		//full
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;   //flow flag
int sumValue; // a variable to keep track of when sum tank is empty or not.
int counter = 0;

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

byte Level0[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b11111,
  0b11111
};
byte Level1[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b11111,
  0b11111,
  0b11111,
  0b11111
};
byte Level2[8] = {
  0b00000,
  0b00000,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111
};
byte Level3[8] = {
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111
};
byte NoLevel[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b11111
};
byte tank[8] = {
  0b10001,
  0b10001,
  0b10001,
  0b10001,
  0b10001,
  0b11111,
  0b11111,
  0b11111
};
byte arrow[8] = {
  0b00000,
  0b00100,
  0b00110,
  0b11111,
  0b11111,
  0b00110,
  0b00100,
  0b00000
};

void setup()
{
Serial.begin(9600);
lcd.createChar(0, Level0);
lcd.createChar(1, Level1);
lcd.createChar(2, Level2);
lcd.createChar(3, Level3);
lcd.createChar(4, NoLevel);
lcd.createChar(5, tank);
pinMode(ledPin, OUTPUT); // sets the ledPin to be an output
pinMode(qut,INPUT);
pinMode(hlf,INPUT);
pinMode(qut,INPUT);
pinMode(ful,INPUT);
pinMode(flow,INPUT);
pinMode(motor,OUTPUT);
pinMode(buz,OUTPUT);
lcd.begin(16, 2);
digitalWrite(ledPin, HIGH); // turn the LED on
digitalWrite(buz, HIGH);
delay(250);
digitalWrite(buz,LOW);
digitalWrite(ledPin, LOW); // turn the LED OFF
lcd.print("AUTOMATIC WATER");
lcd.setCursor(0,1);
lcd.print("PUMP COMTROLLER");
delay(5000);
lcd.clear();
lcd.setCursor(7,0);
lcd.print("BY");
lcd.setCursor(2,1);
lcd.print("BIMAN MANDAL");
delay(5000);
}
void loop()
{
i=digitalRead(motor);
s=analogRead(flow);
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.write(byte(4));
lcd.write(byte(0));
lcd.write(byte(1));
lcd.write(byte(2));
lcd.write(byte(3));
lcd.setCursor(6,0);
lcd.print("TANK FULL");
m=0;
b=0;
}
  else
{
if(f<v && t>v && h>v && q>v)
{
lcd.setCursor(0,0);
lcd.write(byte(4));
lcd.write(byte(0));
lcd.write(byte(1));
lcd.write(byte(2));
lcd.setCursor(5,0);
lcd.print("75%");
b=0;
}
else
{
if(f<v && t<v && h>v && q>v)
{
lcd.setCursor(0,0);
lcd.write(byte(4));
lcd.write(byte(0));
lcd.write(byte(1));
lcd.setCursor(5,0);
lcd.print("HALF");
b=0;
}
else
if(f<v && t<v && h<v && q>v)
{
lcd.setCursor(0,0);
lcd.write(byte(4));
lcd.write(byte(0));
lcd.setCursor(5,0);
lcd.print("25%");
b=0;
}
else
{
if(f<v && t<v && h<v && q<v)
{
lcd.setCursor(0,0);
lcd.write(byte(5));
lcd.print("TANK EMPTY");
m=1;
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");
digitalWrite(ledPin, HIGH); // turn the LED on
}
else
{
lcd.setCursor(0,1);
lcd.print("MOTOR OFF");
digitalWrite(ledPin, LOW); // turn the LED OFF
}

if(s>v && m==1)
{
digitalWrite(motor,HIGH);
digitalWrite(ledPin, HIGH); // turn the LED on
}
if(s<v && m==1)
{
delay(1000);
lcd.setCursor(13,0);
lcd.print("NO");
lcd.setCursor(12,1);
lcd.print("FLOW");
delay(500);
digitalWrite(motor,LOW);
digitalWrite(ledPin, LOW); // turn the LED OFF
c=1;
}
if (sumValue == HIGH)
{
counter = 0;
  c=0;
}
if(s>v)
{
c=0;
}

if(m==0)
{
digitalWrite(motor,LOW);
digitalWrite(ledPin, LOW); // turn the LED OFF
}

if(b==1 || c==1)
{
digitalWrite(buz,HIGH);
digitalWrite(ledPin, HIGH); // turn the LED on
delay(500);
digitalWrite(buz,LOW);
digitalWrite(ledPin, LOW); // turn the LED OFF
delay(500);
}
else
{
digitalWrite(buz,LOW);
digitalWrite(ledPin, LOW); // turn the LED OFF
  delay(2000);
}
}

it is working fine. But now I want to add some extra features to it.

  1. Emergency on and off with a Button or two different buttons.
  2. If there is no water flowing in the tank, the Motor will on and off 3 times with a 30-second gap and then finally stop. A reset button will be there to start over.
  3. Overvoltage and undervoltage protection with ZMPT101B.
    If anyone has any ideas please help me. I will be very grateful.
    Thanks in advance.

I will be surprised if you can fill the tank with the 9V battery? I know they show them being used with the Arduino but there life is very short. The upside is iot helps the battery manufacturers sell batteries. Post your code showing where you are at with it?

Hello biman0007

Welcome to the world's best Arduino forum ever.

You might change the variable names first.
Use the text given by the comments for a better code documentation.

In the following link you will find a Project on "Two Water Pump System" from post#48 onwards:

It is for demonstration purposes. There will be a relay instead of a DC 9V Motor.

There are two Pump, but I want to build a Project with only one Pump.

Hi paulpaulson
Thank you very much for your willingness to help me.
My code is working fine, you can check in Tinkercad.
https://www.tinkercad.com/things/6i1RQUcbeF5-automatic-water-pump-controller

I want to add some extra features to it.

  1. Emergency on and off with a Button or two different buttons.
  2. If there is no water flowing in the tank, the Motor will on and off 3 times with a 30-second gap and then finally stop. A reset button will be there to start over.
  3. Overvoltage and undervoltage protection with ZMPT101B.

Please someone help me.

Show what you have done to accomplish this.

Have you tried to modify the sketch for one pump operation?

Please, write the sequence of operations of your pump system.

1 Like

We are trying to help you but you must also help yourself. We are not a free design service, there is a for hire section if you want to use that. It is best to post an annotated schematic of what you propose, I do not do well with picture layouts as I normally do not have the parts pictured and word problems are hard to follow. I ignore links to other projects as generally they are not relevant or the same as except. Your four wire motor and buzzer are confusing. Take a close look at your picture and explain where the second pump is connected in your posted picture. Take a few moments and put together what you have and what you want with updated schematics.

Please see my schematic diagram,
The sequence of operations:

  1. If there is no water or Water below 25% Sensor, the Motor Will Start (Relay energized).
  2. Reaching water to 100% sensor, Motor Stop. (Relay de-energized).
  3. If the Motor Starts (Relay energized) but no water is flowing to the overhead tank through the Inlet pipe, the Motor will Stop and wait for 30 Sec and then Start again to check if water is flowing or not. if not Motor will stop and this process will continue 3 times, if water is still not coming the Motor will STOP permanently. After reset it will continue the same process.
  4. There will be two switches for Manually ON and OFF the Motor.
  5. Also Over-Voltage and under-voltage protection is to be made through ZMPT101B.

Your schematic capture looks ok except that 12V can be directly connected with VIN-pin of NANO as there is a (7V - 12V)/5V regulator on NANO Board. The LCD display's operating voltage is 5V (and NOT 12V) which you can get from NANO.

The description that you have presented as to the sequence of operation of the Punmp/Motor is rated execellent.

Now, you need to follow SSS (Small Start Strategy) Methodology to develop your project. According to SSS Methodoloy, you test basic (simple and elementary) hardware and associated software. Once it is working, add the next piece of hardware and associated software and test it. You continue this incremental step until the project comes to its end.

For example:
A: Testing 1. and 2. of post #12.
1. Connect NANO wth PC.
2. Place an push-type Switches (S5 and S2) on Breadboard and connect it with NANO using DPin-A4 and DPin-A1 respectively and external pull-down resistors. Connect other sides of S5 and S2 with 5V of NANO and NOT VIN-pin.

I assume that S5 will open when water level is below 25% and S2 will also open when water level is below 100%. Use on-board LED (L) to indicate the Motor/Pump status (L is ON means Pump is running).

Test Codes:
1. As Flow Chart (Fig-1 for your easy understanding)


Figure-1:

2. Convert the Flow Chart of Fig-1 into Programming codes. (I am giving below a sketch using goto statements for your easy understanding of the Flow Chart. Once you have understood the Flow Chart, replace the goto statements by consulting the relevant skectch of the link of post #4).

#define S2 A4
#define S5 A1
#define L 13
bool flag = false;

void setup()
{
  Serial.begin(9600);
  pinMode(S2, INPUT);  //100% level switch S2
  pinMode(S5, INPUT); //25% level switch S5
  pinMode(L, OUTPUT);  //onboard LED (L)
  pinMode(5, OUTPUT);
  digitalWrite(L, LOW);  //Pump is Off
}

void loop()
{
L1: if (digitalRead(S2) == LOW) //water level below 100%
  {
    if (digitalRead(S5) == LOW)//water level is below 25%
    {
      digitalWrite(L, HIGH);  //Pump is On
      digitalWrite(5, HIGH);  //status  debugg
      delay(5000); //Pump be running for 5 sec for level >= 25%
      digitalWrite(5, LOW); //debug
      delay(2000);  //debug
    }
    else
    {
      goto L1;
    }
  }
  else
  {
    digitalWrite(L, LOW);  //Pump is Off
    goto L1;
  }
}

3. Procedures to opeate the sketch of Step-2.
(1) Connect a LED1 with a series resistor at DPin-5 to monitor the timing status.
(2) Uplaod the sketch of Step-2.
(3) Press down bothe S2 and S5 and then press the RESET button of NANO. Check that L is Off (Pump is Off).

(4) Release/open S2 (WL < 100%)
(5) Release/open S5 (WL < 25%). Check that L in On (Pump is On). Let the Pump be running for sometime so that WL >= 25%). Check that LED1 is On.

(6) When LED1 goes Off after 5-sec, press down S5. Wait for about 2-sec. press and hold S2 (to simulate WL = 100%). Check that L is Off.

(7) Release S2 (to simulate WL < 100%). Release S5 (to simulate WL < 25%). Check that L is on (Pump On).

(8) Repeat the process for few times to understand the the On/Off mechanism of Pump.

(9) Consult post #81 @J-M-L of the link of post #4 to develop a FSM (Finite State Machine) Diagram similar to Fig-2 (example of two Pump System taken from the referred post #81) for your one Pump System. If you find difficulties to FSM diagram, add you functions incrementally with Fig-1.

Also, if you have difficulties to replace goto statement, keep using it and finally replace the goto statement as use of goto statement in programming is highly discouraged.


Figure-2:

1 Like

Thanks GolamMostafa for your valuable time.
I will make changes in my schematic as per your suggestion, and I will test the code on my NANO board.
in the meantime can you please check my code?

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int ledPin = 6; // LED is connected to digital pin 6
int sump=A0;
int qut=A1;
int hlf=A2;
int thf=A3;
int ful=A4;
int man=A5;
int motor=8;
int buz=7;
int s;		//sump status flag
int q;		// quater
int h;		// half
int t;		//75 %
int f;		//full
int i;    //motor status flag
int n;		//Manual Mode flag
int v=100; //comparison variable(needs some adjustment)
int b=0;   //buzzer flag
int m=0;   //motor flag
int c=0;   //sump flag
int sumValue; // a variable to keep track of when sum tank is empty or not.
int counter = 0;

byte Level0[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b11111,
  0b11111,
};
byte Level1[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b11111,
  0b11111,
  0b11111,
  0b11111
};
byte Level2[8] = {
  0b00000,
  0b00000,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111
};
byte Level3[8] = {
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111
};
byte NoLevel[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b11111
};
byte tank[8] = {
  0b10001,
  0b10001,
  0b10001,
  0b10001,
  0b10001,
  0b11111,
  0b11111,
  0b11111
};
byte arrow[8] = {
  0b00000,
  0b00100,
  0b00110,
  0b11111,
  0b11111,
  0b00110,
  0b00100,
  0b00000
};

void setup()
{
Serial.begin(9600);
lcd.createChar(0, Level0);
lcd.createChar(1, Level1);
lcd.createChar(2, Level2);
lcd.createChar(3, Level3);
lcd.createChar(4, NoLevel);
lcd.createChar(5, tank);
pinMode(ledPin, OUTPUT); // sets the ledPin to be an output
pinMode(qut,INPUT);
pinMode(hlf,INPUT);
pinMode(qut,INPUT);
pinMode(ful,INPUT);
pinMode(man,INPUT);  
pinMode(sump,INPUT);
pinMode(motor,OUTPUT);
pinMode(buz,OUTPUT);
pinMode(10, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
lcd.begin(16, 2);
digitalWrite(ledPin, HIGH); // turn the LED on
digitalWrite(buz, HIGH);
delay(1000);
digitalWrite(buz,LOW);
digitalWrite(ledPin, LOW); // turn the LED OFF
lcd.setCursor(0,0);
lcd.clear();
lcd.print("AUTOMATIC WATER");
lcd.setCursor(0,1);
lcd.print("PUMP COMTROLLER");
delay(1000);
lcd.clear();
lcd.setCursor(7,0);
lcd.print("BY");
lcd.setCursor(2,1);
lcd.print("BIMAN MANDAL");
delay(1000);
}
void loop()
{
i=digitalRead(motor);
s=analogRead(sump);
q=analogRead(qut);
h=analogRead(hlf);
t=analogRead(thf);
f=analogRead(ful);
n=analogRead(man);
lcd.clear();
if(n>v)
{
  if(f>v && t>v && h>v && q>v)
  {
  lcd.clear();
  lcd.setCursor(2,0);
  lcd.print("MANUAL  MODE");
  lcd.setCursor(4,1);
  lcd.print("MOTOR OFF");
  digitalWrite(motor,LOW);
  digitalWrite(ledPin, LOW);
  delay(1000);
  }
  else{
  lcd.clear();
  lcd.setCursor(2,0);
  lcd.print("MANUAL  MODE");
  lcd.setCursor(4,1);
  lcd.print("MOTOR ON");
  digitalWrite(motor,HIGH);
  digitalWrite(ledPin, HIGH);
  delay(1000);
  }
}
  else
  {
if(f>v && t>v && h>v && q>v )
{
lcd.setCursor(0,0);
lcd.write(byte(4));
lcd.write(byte(0));
lcd.write(byte(1));
lcd.write(byte(2));
lcd.write(byte(3));
lcd.setCursor(0,0);
lcd.write(byte(5));
lcd.setCursor(7,0);
lcd.print("FULL");
m=0;
b=0;
}
else
{
if(f<v && t>v && h>v && q>v)
{
lcd.setCursor(0,0);
lcd.write(byte(4));
lcd.write(byte(0));
lcd.write(byte(1));
lcd.write(byte(2));
lcd.setCursor(0,0);
lcd.write(byte(5));
lcd.setCursor(7,0);
lcd.print(">75%");
b=0;
}
else
{
if(f<v && t<v && h>v && q>v)
{
lcd.setCursor(0,0);
lcd.write(byte(4));
lcd.write(byte(0));
lcd.write(byte(1));
lcd.setCursor(0,0);
lcd.write(byte(5));
lcd.setCursor(7,0);
lcd.print(">50%");
b=0;
}
else
if(f<v && t<v && h<v && q>v)
{
lcd.setCursor(0,0);
lcd.write(byte(4));
lcd.write(byte(0));
lcd.setCursor(0,0);
lcd.write(byte(5));
lcd.setCursor(7,0);
lcd.print(">25%");
b=0;
}
else
{
if(f<v && t<v && h<v && q<v)
{
lcd.setCursor(0,0);
lcd.write(byte(5));
lcd.setCursor(2,0);
lcd.print("TANK EMPTY");
m=1;
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");
digitalWrite(ledPin, HIGH);
}
else
{
lcd.setCursor(0,1);
lcd.print("MOTOR OFF");
digitalWrite(ledPin, LOW);
}

if(s>v && m==1)
{
digitalWrite(motor,HIGH);
digitalWrite(ledPin, HIGH);
}
if(s<v && m==1)
{
lcd.setCursor(13,0);
lcd.print("NO");
lcd.setCursor(12,1);
lcd.print("FLOW");
delay(10000);
digitalWrite(motor,LOW);
digitalWrite(ledPin,LOW);
c=1;
sumValue = digitalRead(sump); // check to see if WATER IS FLOWING
if ((sumValue == LOW) && (counter <= 3)) { // if WATER IS NOT FLOWING,
digitalWrite(motor, HIGH); // turn the motor on
digitalWrite(ledPin, HIGH);
delay(5000); // wait for 10 second
digitalWrite(motor, LOW); // turn the motor off
digitalWrite(ledPin, LOW);
delay(5000); // wait for 10 second
counter++;
}
if (sumValue == HIGH)
{
counter = 0;
c=0;
}
}
if(s>v)
{
c=0;
}
if(m==0)
{
digitalWrite(motor,LOW);
digitalWrite(ledPin, LOW);
}
if(b==1 || c==1)
{
lcd.clear();
 lcd.setCursor(0,0);
 lcd.print("Pump Fault Press");
 lcd.setCursor(0,1);
 lcd.print("Reset Button!");  
digitalWrite(buz,HIGH);
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(buz,LOW);
digitalWrite(ledPin, LOW);
delay(1000);
}
else
{
digitalWrite(buz,LOW);
delay(1000);
}
} 
}

I am very weak in Arduino programming.

I have given you guide lines in post #4, and #13 which you may consult to tailor your sketch.

I think it's referred to as strategy of small steps

I was introduced to "SSS Methodology" in 1982 when I joined with Schlumberger Wire Line Ltd. as an Instrument Engineer to trouble shoot and repair the Well Logging Tools and Equipment. There was a full name for "SSS" which (probably) I had forgotten and started to using "Small Start Strategy" after joining with Arduino Forum. I have noted down your proposed full name and am searching for documentations to support you.

Schlumberger was founded in 1926 in Paris and as such I would not be surprised you inherited from French denominations in your processes. In French we talk about "la stratégie des petits pas" which translates straight into "the strategy of small steps" SSS

or may be it's a subset of Kaizen's SSSSS (5S or 6S)

1 Like

I spent about 15 years with Schulumberger working around the world and I knew that Schulumberger is originally a French Company founded by two brothers Conrad Schlumberger and Marcel Schlumberger and later on it became an International Company with majority shares belong to American people.

I accept the name "Strategy of Small Steps" for "SSS" without waiting anymore. Thank you so much!

1 Like

I personally wouldn't power a 5v LCD off a Nano long term but maybe it doesn't matter as much as I think... a variable voltage regular that takes 12v is like a dollar, even less if you buy the tiny ones in 24 packs.