Pump automation and flow sensor relay timers

Sorry, i forgot write the ..
RELAY1 : Out pump
RELAY2 : In pump
FLOW1 : In Flow sensor (yf-b5 brass 3/4)
FLOW2 : Out Flow sensor (yf-b5 brass 3/4)
TANK LVL : Ultrasonic JSN-SR04T
all sensor and relay state, show on L2C LCD 2004.
Timing 5 minute if water tank <=10% RELAY2 ON, then OFF 5 minute if no flowrate on FLOW1. loop to read tank level. (to keep In Pump cooling down if no water flow from inlet FLOW1.

I don't understand what you want to say with that.

please fachromiez,

write down with much more details what you meam in your motherlanguage and use google-translate. You will be surprised how many languages google can translate

1 Like

OK, but there's still the language bearer.

See if you can add that detail to your flowchart. In any way mark up the one your drew already to show where and why you need to think about 5 minute periods of elapsing time.

a7

The inlet pump (RELAY2) runs for 5 minutes when the tank content is <=10%, then checks the inlet water flow at (FLOW1).

If there is water flow in (FLOW1) >=1 then (RELAY2) the inlet pump remains on until the tank is >=100%. If there is no water flow in (FLOW1) <=1 then the inlet pump (RELAY2) will shut off for 5 minutes, then return to check the tank contents.

yes.

Relay1 is a very unhelpful name. Why not give it a name that tells you what it is for? Even if that is in Indonesian.

1 Like

i just keep it simple and short. :grinning:

You want help. For other users it will be easier to understand your code if all names are self-explaining

1 Like

Perhaps. But then you have to spend brain power translating it every time you see it, which actually makes your code harder to understand.

Similarly, it's not obvious whether high or low starts the pump.

1 Like
#include "LiquidCrystal.h"
//Tank level;
#define trigPin 8
#define echoPin 9
// Define variables:
long duration;
int TankLevel;
int TankLevelPercentage;
//Tank leve;

//Flo sens out pompa dorong
const int FlowOutPin = 2; //Flo
volatile int  pulse_frequency;
unsigned int  literPerMin;
unsigned long currentTime, loopTime;
byte sensorInterrupt = 0;  // 0 = pin 2; 1 = pin 3
//Flo sens out

//Flo sens in pompa hisap
const int FlowInPin = 3; //Flo
volatile int  pulse_frequencyIn;
unsigned int  literPerMinIn;
unsigned long currentTimeIn, loopTimeIn;
byte sensorInterruptIn = 1;  // 0 = pin 2; 1 = pin 3
//Flo sens in

//Realy 1 check flow
unsigned long prevTimePumpInPin = 0;
unsigned long PumpInPinDelay = 2000 ; //jeda waktu cek air di pompa tarik 1000 = 1 detik
byte PumpInPinState = LOW;

//LCD L2C
#include <LiquidCrystal_I2C.h>
// set the LCD number of columns and rows
int lcdColumns = 20;
int lcdRows = 4;
// set LCD address, number of columns and rows
// if you don't know your display address, run an I2C scanner sketch
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);// SCL to pin A5. SDA ti pin A4)
char line0[21];
char line1[21];
//LCD L2C

//Relay pump
byte PumpOutPin   = 12; //PumpOutPin pompa dorong
byte PumpInPin   = 13; //PumpInPin pompa tarik
#define PumpOutPin 12
#define PumpInPin 13

//Relay pump

void getFlow ()
{
  pulse_frequency++;
  pulse_frequencyIn++;
}


void setup() {
  Serial.begin(9600);// Begin Serial communication at a baudrate of 9600:

  lcd.init();

  pinMode(FlowOutPin, INPUT); //Flo sens out
  pinMode(FlowInPin, INPUT); //Flo sens in
  attachInterrupt(sensorInterrupt, getFlow, FALLING); //Flo sens out 
  attachInterrupt(sensorInterruptIn, getFlow, FALLING); //Flo sens in
  currentTime = millis(); //Flo sens out
  currentTimeIn = millis(); //Flo sens in
  loopTime = currentTime; //Flo sens out
  loopTimeIn = currentTimeIn; //Flo sens in

  // 

  //Tank level;
  // Define inputs and outputs
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  //Tank leve;

  //Relay pump
  pinMode(PumpOutPin, OUTPUT);
  pinMode(PumpInPin, OUTPUT);
  //Relay pump
}

void flowOut() {
  currentTime = millis();
  if (currentTime >= (loopTime + 1000))
  {
    loopTime = currentTime;
    literPerMin = (pulse_frequency / 12);
    pulse_frequency = (float)0;
  }
  else if (literPerMin >= 1) {
    lcd.backlight();
  }
  else
    lcd.noBacklight();
}

void flowIn() {
  currentTimeIn = millis();
  if (currentTimeIn >= (loopTimeIn + 1000))
  {
    loopTimeIn = currentTimeIn;
    literPerMinIn = (pulse_frequencyIn / 12);
    pulse_frequencyIn = (float)0;
  }
  else if (literPerMinIn >= 1) {
    lcd.backlight();
  }
  else
    lcd.noBacklight();
}

/*

void chkflowTarikOff() {
  unsigned long timeNow = millis();

  if (timeNow - prevTimePumpInPin > PumpInPinDelay) {
    prevTimePumpInPin += PumpInPinDelay;
    if (PumpInPinState == HIGH && literPerMinIn <= 1) {
      PumpInPinState = LOW;
    }
    digitalWrite(PumpInPin, PumpInPinState);
  }
}

void chkflowTarikOn() {
  unsigned long timeNow = millis();

  if (timeNow - prevTimePumpInPin > PumpInPinDelay) {
    prevTimePumpInPin += PumpInPinDelay;
    if (PumpInPinState == HIGH && literPerMinIn >= 1) {
      PumpInPinState = HIGH;
    }
    digitalWrite(PumpInPin, PumpInPinState);
  }
}

*/



void Pump() {
  if ( TankLevelPercentage <= 10) {
    digitalWrite(PumpInPin, HIGH); //
    lcd.setCursor(15, 1);
    lcd.print(">");
    digitalWrite(PumpOutPin, LOW);
    lcd.setCursor(14, 1);
    lcd.print(" ");
    lcd.backlight();
  }
  else if (TankLevelPercentage >= 100) {
    digitalWrite(PumpInPin, LOW); // 
    lcd.noBacklight();
    lcd.setCursor(15, 1);
    lcd.print(" ");
  }
  else if (TankLevelPercentage >= 11) {
    digitalWrite(PumpOutPin, HIGH);
    lcd.setCursor(14, 1);
    lcd.print("<");
    //lcd.backlight();
  }


  // else literPerMin = 0;
}

void TanklLvl() {

  // Clear the trigPin by setting it LOW:
  digitalWrite(trigPin, LOW);
  delayMicroseconds(5);
  // Trigger the sensor by setting the trigPin high for 10 microseconds:
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Read the echoPin. pulseIn() returns the duration (length of the pulse) in microseconds:
  duration = pulseIn(echoPin, HIGH);
  // Calculate the TankLevel:
  TankLevel = duration * 0.0343 / 2 - 11;

  TankLevelPercentage = 110 - TankLevel * 100 / 90;
  // TankLevel = TankLevel * 100;
}


void loop() {

  TanklLvl();
  flowOut();
  flowIn();
  Pump();

  lcd.display();
  lcd.setCursor(0, 0);
  lcd.print("Isi Tank: ");
  lcd.setCursor(10, 0);
  lcd.print(TankLevelPercentage);
  lcd.print("   ");

  lcd.setCursor(13, 0);
  lcd.print(" % ");

  lcd.setCursor(0, 1);
  lcd.print("Kran : ");
  lcd.setCursor(7, 1);
  lcd.print(literPerMin);
  lcd.print("  ");
  lcd.setCursor(10, 1);
  lcd.print("L/M");


  Serial.print("Isi Tank : ");
  Serial.print(TankLevelPercentage);
  Serial.print(" % ");
  Serial.print("Liter/M : ");
  Serial.println(literPerMin);
  //lcd.noBacklight();
  delay(100);

}

I have changed it, sorry but still any quote.

I have changed it, sorry but still any quote.
Saya telah mengubahnya, maaf tapi masih ada kutipan.

Maaf, saya tidak mengerti!

Saya tidak mengerti itu.
Gunakan google-translate untuk menerjemahkan teks di bawah ini.
Ini berisi informasi penting tentang cara mendapatkan dukungan yang baik!!

Hei fachromez,

Kirjoitin tämän tekstin saksaksi ja käänsin sen sitten SUOMEN kielelle google-kääntäjällä. Vain osoittaakseni, kuinka hyvin kääntäminen google-kääntäjällä toimii.

Tämän käyttäjäfoorumin ihmiset ovat erittäin ystävällisiä. Ainoa asia, joka tapahtuu, kun et vastaa muiden pyyntöihin ja kysymyksiin, on se, että et saa enää vastauksia.

Tämän suomenkielisen tekstin pitäisi osoittaa sinulle, että tämä toimii erittäin hyvin google-kääntäjän kanssa.

Joten mikä on? Vastaatko meille yksityiskohtaisesti?

best regards Stefan

May be this got better.
olen pahoillani..

#include "LiquidCrystal.h"

#define trigPin 8
#define echoPin 9

long duration;
int TankLevel;
int TankLevelPercentage;

const int FlowOutPin = 2; 
volatile int  pulse_frequency;
unsigned int  literPerMin;
unsigned long currentTime, loopTime;
byte sensorInterrupt = 0; 

const int FlowInPin = 3; 
volatile int  pulse_frequencyIn;
unsigned int  literPerMinIn;
unsigned long currentTimeIn, loopTimeIn;
byte sensorInterruptIn = 1; 

unsigned long prevTimePumpInPin = 0;
unsigned long PumpInPinDelay = 2000 ; 
byte PumpInPinState = LOW;


#include <LiquidCrystal_I2C.h>

int lcdColumns = 20;
int lcdRows = 4;

LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
char line0[21];
char line1[21];

byte PumpOutPin   = 12; 
byte PumpInPin   = 13; 
#define PumpOutPin 12
#define PumpInPin 13



void getFlow ()
{
  pulse_frequency++;
  pulse_frequencyIn++;
}


void setup() {
  Serial.begin(9600);

  lcd.init();

  pinMode(FlowOutPin, INPUT); 
  pinMode(FlowInPin, INPUT); 
  attachInterrupt(sensorInterrupt, getFlow, FALLING); 
  attachInterrupt(sensorInterruptIn, getFlow, FALLING);
  currentTime = millis(); 
  currentTimeIn = millis();
  loopTime = currentTime; 
  loopTimeIn = currentTimeIn;

  

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(PumpOutPin, OUTPUT);
  pinMode(PumpInPin, OUTPUT);
  

void flowOut() {
  currentTime = millis();
  if (currentTime >= (loopTime + 1000))
  {
    loopTime = currentTime;
    literPerMin = (pulse_frequency / 12);
    pulse_frequency = (float)0;
  }
  else if (literPerMin >= 1) {
    lcd.backlight();
  }
  else
    lcd.noBacklight();
}

void flowIn() {
  currentTimeIn = millis();
  if (currentTimeIn >= (loopTimeIn + 1000))
  {
    loopTimeIn = currentTimeIn;
    literPerMinIn = (pulse_frequencyIn / 12);
    pulse_frequencyIn = (float)0;
  }
  else if (literPerMinIn >= 1) {
    lcd.backlight();
  }
  else
    lcd.noBacklight();
}




void Pump() {
  if ( TankLevelPercentage <= 10) {
    digitalWrite(PumpInPin, HIGH); //
    lcd.setCursor(15, 1);
    lcd.print(">");
    digitalWrite(PumpOutPin, LOW);
    lcd.setCursor(14, 1);
    lcd.print(" ");
    lcd.backlight();
  }
  else if (TankLevelPercentage >= 100) {
    digitalWrite(PumpInPin, LOW); // 
    lcd.noBacklight();
    lcd.setCursor(15, 1);
    lcd.print(" ");
  }
  else if (TankLevelPercentage >= 11) {
    digitalWrite(PumpOutPin, HIGH);
    lcd.setCursor(14, 1);
    lcd.print("<");
    //lcd.backlight();
  }


  // else literPerMin = 0;
}

void TanklLvl() {

 
  digitalWrite(trigPin, LOW);
  delayMicroseconds(5);
  
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
 
  duration = pulseIn(echoPin, HIGH);
 
  TankLevel = duration * 0.0343 / 2 - 11;

  TankLevelPercentage = 110 - TankLevel * 100 / 90;
 
}


void loop() {

  TanklLvl();
  flowOut();
  flowIn();
  Pump();

  lcd.display();
  lcd.setCursor(0, 0);
  lcd.print("Tank Lvl: ");
  lcd.setCursor(10, 0);
  lcd.print(TankLevelPercentage);
  lcd.print("   ");

  lcd.setCursor(13, 0);
  lcd.print(" % ");

  lcd.setCursor(0, 1);
  lcd.print("Valv : ");
  lcd.setCursor(7, 1);
  lcd.print(literPerMin);
  lcd.print("  ");
  lcd.setCursor(10, 1);
  lcd.print("L/M");


  Serial.print("Tank Lvl : ");
  Serial.print(TankLevelPercentage);
  Serial.print(" % ");
  Serial.print("Liter/M : ");
  Serial.println(literPerMin);
  
  delay(100);

}




The inlet pump (PumpInPin) runs for 5 minutes when the tank content is <=10%, then checks the inlet water flow at (FlowInPin).

If there is water flow in (FlowInPin) >=1 then (PumpInPin) the inlet pump remains on until the tank is >=100%. If there is no water flow in (FlowInPin) <=1 then the inlet pump (PumpInPin) will shut off for 5 minutes, then return to check the tank contents.


replacing name in flowchart

That flowchart does not seem to match your description.

In particular, nothing keeps the pump running for five minutes after the signal that makes it runs goes away.

The position of the "delay 5 minutes" looks like it runs for five minutes after it starts, but then it will stop if and when the conditions change, no five minute continuation.

a7

It might help if it were clear what this is for.

It appears that you wish to top up a tank if it is low. Once the tank is slightly more full, water will be pumped from the tank and that will continue forever unless the tank becomes low again.

There is a complication in that there may not be water available at the intake.

What is the purpose and where does the outflowing water go?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.