question about 2 different water tank code!

Hi!
i make a code for 2 water tank, both of them 1M what if i want setup my device on difrent water tank
first one 1M the other one 2M ?
my problem is the code give the size for both tanks, so i must have the same size for both tanks

this is my code

#include <LiquidCrystal.h>

#define ECHOPIN 3                            // Pin to receive echo pulse
#define TRIGPIN 4                            // Pin to send trigger pulse
#define ECHO_PIN2 6                            // Pin to receive echo pulse2
#define TRIG_PIN2 5                            // Pin to send trigger pulse2

#define STATUSPIN 13                        // Use for troubleshooting

int highWater = 30;        // These values allow to calculate % of full
int lowWater = 100 ;        // SRF04 hangs above water (lower distance = more water)

byte symbol[8] = {         // Custom character for LCD display
  B00000, 
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B00000,
};

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);    // Assign pins

// Utility function for flashing STATUSPIN
void flashLed(int pin, int times, int wait) {

  for (int i = 0; i < times; i++) {
    digitalWrite(pin, HIGH);
    delay(wait);
    digitalWrite(pin, LOW);

    if (i + 1 < times) {
      delay(wait);
    }
  }
}


void setup() {
  
  lcd.begin(16,2);
  lcd.print("   AQUA LEVEL ");
  lcd.createChar(0, symbol);
  pinMode(ECHOPIN, INPUT);
  pinMode(TRIGPIN, OUTPUT);
  pinMode(ECHO_PIN2, INPUT);
  pinMode(TRIG_PIN2, OUTPUT);

 delay(3000);       // Show application name for 3 seconds.

}

void loop() {
 // Measure distance
  digitalWrite(TRIGPIN, LOW);                   // Set the trigger pin to low for 2uS
  delayMicroseconds(2);
  digitalWrite(TRIGPIN, HIGH);                  // Send a 10uS high to trigger ranging
  delayMicroseconds(10);
  digitalWrite(TRIGPIN, LOW);                   // Send pin low again
  int distance = pulseIn(ECHOPIN, HIGH);        // Read in times pulse
  distance= distance/58;                        // divide by 58 gives cm.

// Measure distance 2
  digitalWrite(TRIG_PIN2, LOW);                   // Set the trigger pin to low for 2uS
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN2, HIGH);                  // Send a 10uS high to trigger ranging
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN2, LOW);                   // Send pin low again
  int distance2 = pulseIn(ECHO_PIN2, HIGH);        // Read in times pulse
  distance2= distance2/58;                        // divide by 58 gives cm.
  
 // Convert measured value1 to value between 0-11, to display on LCD
  // Use Arduino built-in map and constrain functions
  int scaledValue = map(constrain(distance, highWater, lowWater), lowWater, highWater, 0, 15);
  lcd.clear();
  lcd.print("E      |      F1");
  lcd.setCursor(0,1);
  while (scaledValue > 0) {
     lcd.print((char)0);
     scaledValue--;
  }
      
   delay(3000);  // Wait 2 seconds before printing the 2nd value.

  // Convert measured value2 to value between 0-11, to display on LCD
  // Use Arduino built-in map and constrain functions
  int scaledValue2 = map(constrain(distance2, highWater, lowWater), lowWater, highWater, 0, 15); 
  lcd.clear();
  lcd.print("E      |      F2");
  lcd.setCursor(0,1);
  while (scaledValue2 > 0) {
     lcd.print((char)0);
     scaledValue2--;
  }
      
   delay(3000);  // Wait 2 seconds before measuring again. We're in no hurry!
}

If you cannot change the code for each tank, then maybe you could add a 'calibrate' button to switch between 100 and 200 cm distances, an LED can be used as an indicator. Or even simpler, just a set of exposed pins you can bridge with a shunt/jumper for what ever mode you need. ( I gather that 1M is 1 meter high, not 1 Mega liter in capacity ).

Your answer is dependent on the geometry of the two tanks which determines the level of equal amount of water.
A simple ratio can be used for comparing the water levels..
OR if one tank can be above the other, the total level level or volume is related to the pressure at the final tank outlet..
Or here is a simple Google search that will return the volume in gallons, Took me 5 seconds, I guess you don't have google?

Hi Dean,

I'll do cylinder A and that should show you how to do the calculations for B. I am going to assume that you mean American gallons. One American gallon is 231 cubic inches.

The volume of a cylinder is given by

volume = radius2 height

Your cylinder A has a radius of 4' = 48" so, since is approximately 3.1416, one foot (12 inches) height of this cylinder has a volume of

radius^2 height = 3.1416 482 12 = 86859 cubic inches. // use your tank numbers here and do it for both tanks
A simple set of calculations with a slight re arrangement of the formula above will give you an answer that can easily scaled to any measurement type that you desire

Since 231 cubic inches is one gallon this is

86859/231 = 376 gallons.

Since your cylinder is 12 feet high its volume is

12 multiply 376 = 4512 gallons.

Penny

Stolen from Gallons in a cylinder...

Doc

pYro_65 i like your idea , and yes 1M is the high, but i am searching on other solution, i think i can solve this problem with only small code.

Docedison you idea is far away from my needs, the 2 tanks not connected to each others, i google it!!

if i can add other code for the other tank like this

int highWater = 30;        // These values allow to calculate % of full
int lowWater = 100 ;        // SRF04 hangs above water (lower distance = more water)

it will be great !

I didn't consider anything but a means of measuring both tank volumes, Obviously connecting both was a simple answer to an unstated condition..
However with a little imagination and some very little (simple) mathematical knowledge it could be written as a simple function that can be called with each data set.. The rest is up to your skills at C/C++ and your ability to use google and a simple calculator to prove your math.
Particularly since one variable per tank can change...

...

if i can add other code for the other tank like this

You can! However you still need to work out how to let the Arduino know which set of values to use. It needs some way of knowing if its looking at a half full 2 meter tank or an empty tank that is only 1 meter high.

...Or just modify and upload the program for whatever tank size you need.

If the tank is empty when you setup the device, you can have it calibrate to the distance of the first reading(s) then it can simply scale the values between empty and full to obtain percentages or volume.

pYro_65 oh you miss understand me, i mean i want show the level of 2 tank in the same time, first one 1M and the second 2M
i have arduino ano R3 and 2 ultrasonic sensor

You are most of the way there - you already have ECHO_PIN2 and TRIG_PIN2. Now you just need highWater2 and lowWater2 and use them in the code that calculates the reading for tank two.

willbill ya thats what i want to do but this code for the both
how i can make 2 codes and where i will add it really i dont know

int highWater1 = 30; // These values allow to calculate % of full
int lowWater1 = 100 ; // SRF04 hangs above water (lower distance = more water)

int highWater2 = 30; // These values allow to calculate % of full
int lowWater2 = 200 ; // SRF04 hangs above water (lower distance = more water)

i think that's will not work how the arduino will know wich one for the first one and the second one!!

  int scaledValue2 = map(constrain(distance2, highWater2, lowWater2), lowWater2, highWater2, 0, 15);

ops it seems there is genus here :astonished:
so for my case will be like this
int scaledValue1 = map(constrain(distance1, highWater1, lowWater1), lowWater1, highWater1, 30, 100);
int scaledValue2 = map(constrain(distance2, highWater2, lowWater2), lowWater2, highWater2, 30, 200);

thanks aloooot wildbill =( finally
i will try it now :roll_eyes: