Help needed water tank indicator and counting numbers of full tank

Hi ,

I want to count number of reservoir and see this value , maybe if is possible to use tree leds to show me how many is was

please find bellow the full code

// definim pinii pentru electrozi

int Plin = 2;
int Mijloc = 3;
int Gol = 4;
int Releu = 13;
int LedRosu = 10;
int LedGalben = 11;
int LedVerde = 12;

// definim variabile de numarare

int Count = 0;


// Asta teoretic ruleaza o data pana se apasa reset:

void setup() {
  // initializam comunicatia seriala
  Serial.begin(9600);
  // pana la realizare voi folosi push butoane pentru test:

  pinMode(Plin, INPUT);
  pinMode(Mijloc, INPUT);
  pinMode(Gol, INPUT);
  pinMode(Releu, OUTPUT);
  pinMode(LedVerde, OUTPUT);
  pinMode(LedGalben, OUTPUT);
  pinMode(LedRosu, OUTPUT);
  digitalWrite(Plin, HIGH);
  digitalWrite(Mijloc, HIGH);
  digitalWrite(Gol, HIGH);
  digitalWrite(Releu, HIGH);   //RELEU APRINS
  digitalWrite(Releu, LOW);    //RELEU stins
  digitalWrite(LedVerde, LOW);   // led verde stins
  digitalWrite(LedGalben, LOW);  // led galben stins
  digitalWrite(LedRosu, LOW);    // led rosu stins
}

// Asta teoretic ruleaza mereu


void loop()

{

  if (digitalRead(Plin) == LOW)
  // rezervor plin
  {
    Serial.println("Apa la maxim -- Cantitate = 1000 Litri ");
    digitalWrite(Releu, HIGH);  // pompa se opreste
    Serial.println("Pompa umplere rezervor se opreste");
    if (Releu == HIGH) { // contor rezervor plin
      Count++; // Increase count by one
      Serial.print("Count: ");
      Serial.print("Time:  ");
      Serial.println(Count);
      delay(1000);
    }
    digitalWrite(LedVerde, HIGH);  // led verde aprins
    digitalWrite(LedGalben, HIGH);  // led galben aprins
    digitalWrite(LedRosu, HIGH);    // led rosu aprins
  }

  else
    // daca rezervorul nu e plin
    {
    if (digitalRead(Plin) == HIGH)
    {
      digitalWrite(LedVerde, HIGH); // led verde aprins
      delay(750);                  // timp aprins
      digitalWrite(LedVerde, LOW); // led verde stins
      delay(750);                  // timp stins
      digitalWrite(LedGalben, HIGH);  // led galben aprins
      digitalWrite(LedRosu, HIGH);    // led rosu aprins
    
    }

    else // daca  scazut nivelul sub jumatate
{
      if (digitalRead(Mijloc) == HIGH)
      {
        Serial.println("Apa sub jumatate= 500 Litri ");
        digitalWrite(LedVerde, LOW);  // led verde stins
        digitalWrite(LedGalben, HIGH); // led galben aprins
        delay(450);                  // timp aprins
        digitalWrite(LedGalben, LOW); // led galben stins
        delay(450);                  // timp stins
        digitalWrite(LedRosu, HIGH);    // led rosu aprins
      
      }

      else  // daca nivelul e sub minim
{
        if (digitalRead(Gol) == HIGH)
        {
          Serial.println("Rezervor la nivel minim");
          digitalWrite(Releu, LOW);  // pompa porneste
          Serial.println("Porneste pompa umplere rezervor");
          digitalWrite(LedVerde, LOW);  // led verde stins
          digitalWrite(LedGalben, LOW);  // led galben stinss
          digitalWrite(LedRosu, HIGH);    // led rosu aprins
          delay(250);                  // timp aprins
          digitalWrite(LedRosu, LOW);    // led rosu Stins
          delay(250);                  // timp stins
        }
       }
       }
       }
}
// sfarsit program principal

Yes.
If You have any question about the code then post it the proper way. You posted text, not code.
Read the first topic telling how to get the best from this forum.

You gave Releu the value 13.
HIGH has the value 1, so that's never going to happen.

Did you forget a digitalRead?

Please remember to use code tags when posting code

Please read the introductory posts for this forum.
pay attention on how to post code.


// definim pinii pentru electrozi

int Plin = 2;
int Mijloc = 3;
int Gol = 4;
int Releu = 13;
int LedRosu = 10;
int LedGalben = 11;
int LedVerde = 12;

// definim variabile de numarare

int Count = 0;


// Asta teoretic ruleaza o data pana se apasa reset:

void setup() {
  // initializam comunicatia seriala
  Serial.begin(9600);
  // pana la realizare voi folosi push butoane pentru test:

  pinMode(Plin, INPUT);
  pinMode(Mijloc, INPUT);
  pinMode(Gol, INPUT);
  pinMode(Releu, OUTPUT);
  pinMode(LedVerde, OUTPUT);
  pinMode(LedGalben, OUTPUT);
  pinMode(LedRosu, OUTPUT);
  digitalWrite(Plin, HIGH);
  digitalWrite(Mijloc, HIGH);
  digitalWrite(Gol, HIGH);
  digitalWrite(Releu, HIGH);   //RELEU APRINS
  digitalWrite(Releu, LOW);    //RELEU stins
  digitalWrite(LedVerde, LOW);   // led verde stins
  digitalWrite(LedGalben, LOW);  // led galben stins
  digitalWrite(LedRosu, LOW);    // led rosu stins
}

// Asta teoretic ruleaza mereu


void loop()

{

  if (digitalRead(Plin) == LOW)
  // rezervor plin
  {
    Serial.println("Apa la maxim -- Cantitate = 1000 Litri ");
    digitalWrite(Releu, HIGH);  // pompa se opreste
    Serial.println("Pompa umplere rezervor se opreste");
    digitalWrite(LedVerde, HIGH);  // led verde aprins
    digitalWrite(LedGalben, HIGH);  // led galben aprins
    digitalWrite(LedRosu, HIGH);    // led rosu aprins
  }

  else
    // daca rezervorul nu e plin itre 500 si 1000 litri
    {
    if (digitalRead(Plin) == HIGH)
    {
      digitalWrite(LedVerde, HIGH); // led verde aprins
      delay(850);                  // timp aprins
      digitalWrite(LedVerde, LOW); // led verde stins
      delay(850);                  // timp stins
      digitalWrite(LedGalben, HIGH);  // led galben aprins
      digitalWrite(LedRosu, HIGH);    // led rosu aprins
    
    }

    else // daca  scazut nivelul sub jumatate
{
      if (digitalRead(Mijloc) == HIGH)
      {
        Serial.println("Apa sub jumatate= 500 Litri ");
        digitalWrite(LedVerde, LOW);  // led verde stins
        digitalWrite(LedGalben, HIGH); // led galben aprins
        delay(450);                  // timp aprins
        digitalWrite(LedGalben, LOW); // led galben stins
        delay(450);                  // timp stins
        digitalWrite(LedRosu, HIGH);    // led rosu aprins
      
      }

      else  // daca nivelul e sub minim
{
        if (digitalRead(Gol) == HIGH)
        {
          Serial.println("Rezervor la nivel minim");
          digitalWrite(Releu, LOW);  // pompa porneste 
        Count++; // Increase count by one
      Serial.print("Count: ");
      Serial.print("Time:  ");
      Serial.println(Count);
      delay(1000);
          Serial.println("Porneste pompa umplere rezervor");
          digitalWrite(LedVerde, LOW);  // led verde stins
          digitalWrite(LedGalben, LOW);  // led galben stinss
          digitalWrite(LedRosu, HIGH);    // led rosu aprins
          delay(250);                  // timp aprins
          digitalWrite(LedRosu, LOW);    // led rosu Stins
          delay(250);                  // timp stins
        }
       }
       }
       }
}
// sfarsit program principal

Preformatted text

That's better, now you can go back and edit your first post so the code is properly formatted and readable.

Don't change the code itself, just mark it up as code. :grinning:

Hi again,

please help me with a code to read the voltage at pin (Gol) , (Mijloc), (Plin), I measuring the voltage is 2,5 V, only pin (Gol) is 5 V. I need to be High if the voltage between 1,5V and 5 Volts.
Please find bellow a schematic connection for this application.

Hello
I have found a similar sketch in my sketch box. With some done modifications this sketch shall run.

//BLOCK COMMENT
// https://forum.arduino.cc/t/help-needed-water-tank-indicator-and-counting-numbers-of-full-tank/885816
#define ProjectName "Help needed water tank indicator and counting numbers of full tank"
// LIBARIES INCLUSION
// CONSTANT DEFINITION
enum {Empty, Half, Full};
/*
const byte LED[] {2, 3, 4};
const byte Sensor[] {A0, A1, A2};
*/
const byte LED[] {10,11,12};
const byte Sensor[] {2,3,4};
// VARIABLE DECLARATION
void setup() {
  Serial.begin(9600);
  Serial.println(F("."));
  Serial.print(F("File   : ")), Serial.println(__FILE__);
  Serial.print(F("Date   : ")), Serial.println(__DATE__);
  Serial.print(F("Project: ")), Serial.println(ProjectName);
  pinMode (LED_BUILTIN, OUTPUT);
  for (auto pin : LED) pinMode(pin, OUTPUT);
  for (auto pin : Sensor) pinMode(pin, INPUT_PULLUP);
}
void loop () {
  unsigned long currentTime = millis();
  digitalWrite(LED_BUILTIN, (currentTime / 500) % 2);
  static byte sensorStateOld;
  byte sensorState = (!digitalRead(Sensor[Full]) << 2) | (!digitalRead(Sensor[Half]) << 1) | (!digitalRead(Sensor[Empty]));
  if (sensorStateOld != sensorState) {
    sensorStateOld = sensorState;
    for (auto pin : LED) digitalWrite(pin, LOW);
    switch (sensorState) {
      case 0b000 ... 0b001: digitalWrite(LED[Empty], HIGH); break;
      case 0b011:           digitalWrite(LED[Half], HIGH); break;
      case 0b111:           digitalWrite(LED[Full], HIGH); break;
    }
  }
}

assuming that you are using the water as a resistor, the water completing the circuit will result in a change in voltage.

change the sensor pins to analog ones.
add a separate 10k pull-up resistor to each line

you might want to put a ground line near each sensor pin. an inch or two away.

What's wrong with INPUT_PULLUP? :face_with_raised_eyebrow:

Which you can turn off except when you are actually reading the input, to minimise electrolysis. :sunglasses:

1 Like

Whats wrong?

I didn't think of it.

I change to analog A0-A1-A2 and also the code.
The water is changing the Ph so I have some error on reading interface.
Do you recommend to use between Arduino analog reading a resistor of 10k on each pin A0;A1;A2 ?

The pull-up is half of a voltage divider.
The other half is the water between electrode in the tank and ground.

No water and you should see the board voltage.
As soon as the water touches the electrode.
The voltage should drop. Anything less than board voltage means water is touching the sensor.

Can you make a sketch?

each Analog pin would connect to the electrode, separatley and not in series.

5v ----10k---[connect to A0]----electrode1----[water]---ground

5v ----10k---[connect to A1]----electrode2----[water]---ground

5v ----10k---[connect to A2]----electrode3----[water]---ground

each analog pin has connection to 5V

if you have a multi-meter, you can measure the resistance at each sensor.

when I did water test for soil, I got about 8k ohms for an inch of tap water. I did not test for distance.

ok, thank you for support.

can anyone help me with a counter for relay when is changing the state, to count how many times the reservoir is fill with water

You also need to shield the sensor from turbulence/waves on the surface of the water. They will give you rapidly varying results from the sensor that is just now getting wet.
Paul

If you build your sensors as in the initial drawing, it will not be very reliable: a better solution is to hang the sensors from up above in the water so the side of the vessel cannot disturb the measurement.
afbeelding

Anyway: if the impact of a faulty reading is large, use a capacitive or floating device.

1 Like