problem with my code :/

#include <LiquidCrystal.h>

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

#define STATUSPIN 13                        // Use for troubleshooting

int highWater = 20;        // 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);

  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, 11);
  lcd.clear();
  lcd.print("E    SENSOR 1    F");
  lcd.setCursor(0,1);
  while (scaledValue > 0) {
     lcd.print((char)0);
     scaledValue--;
  }
      
   delay(2000);  // 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 scaledValue = map(constrain(distance2, highWater, lowWater), lowWater, highWater, 0, 11);//<<<<<<<<note distance2
  lcd.clear();
  lcd.print("E   SENSOR 2   F ");
  lcd.setCursor(0,1);
  while (scaledValue > 0) {
     lcd.print((char)0);
     scaledValue--;
  }
      
   delay(2000);  // Wait 2 seconds before measuring again. We're in no hurry!

i use this code and i have this error any one can help !!

sketch_aug27a.ino: In function 'void loop()':
sketch_aug27a:86: error: redeclaration of 'int scaledValue'
sketch_aug27a:73: error: 'int scaledValue' previously declared here
sketch_aug27a:95: error: expected `}' at end of input

the program highlight this line
int scaledValue = map(constrain(distance2, highWater, lowWater), lowWater, highWater, 0, 11);

In loop():

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, 11);  // =======  Pick this one or... ====
  lcd.clear();
  lcd.print("E    SENSOR 1    F");
  lcd.setCursor(0,1);
  while (scaledValue > 0) {
     lcd.print((char)0);
     scaledValue--;
  }
      
   delay(2000);  // 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 scaledValue = map(constrain(distance2, highWater, lowWater), lowWater, highWater, 0, 11);  // ======= ...this one, not both ===
;//<<<<<<<<note distance2
  lcd.clear();
  lcd.print("E   SENSOR 2   F ");
  lcd.setCursor(0,1);
  while (scaledValue > 0) {
     lcd.print((char)0);
     scaledValue--;
  }
      
      delay(2000);  // Wait 2 seconds before measuring again. We're in no hurry!
}

You have define scaledValue twice. You can’t use the same variable name twice at the same scope level.

i read that code twice :astonished: i really not see the problem !! heeeeeelp my head want explode =(

// 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, 11);
  lcd.clear();
  lcd.print("E    SENSOR 1    F");
  lcd.setCursor(0,1);
  while (scaledValue > 0) {
     lcd.print((char)0);
     scaledValue--;
  }
      
   delay(2000);  // 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 scaledValue = map(constrain(distance2, highWater, lowWater), lowWater, highWater, 0, 11);//<<<<<<<<note distance2
  lcd.clear();
  lcd.print("E   SENSOR 2   F ");
  lcd.setCursor(0,1);
  while (scaledValue > 0) {
     lcd.print((char)0);

See the lines I marked *****************************… you declare scaledValue both times. Once it’s declared the first time, the second time, lose the “int”

i change the second one to "int scaledValue2" now i have other error the program highlight this line

delay(2000); // Wait 2 seconds before measuring again. We're in no hurry!

the error is

sketch_aug27a.ino: In function 'void loop()': sketch_aug27a:95: error: expected `}' at end of input

That delay() is below the closing } of loop()

edit... in fact your loop() doesn't have a closing }, you are one short

hmm and what that's mean :/ ! how i can fix it

oh ok thanks alot :)

Tip… place your cursor just after any bracket and the IDE will highlight the matching one with a little box. See attached, red line is cursor, matching brackets in yellow.

brackets.PNG

You could test that with an LED in place of the relay. I don't know what your hardware is: you would not want to drive the relay coil from an Arduino i/o pin.

Relay tutorial