Please Help me in decreasing the dynamic memory space of the Arduino Nano for (WATER TANK MONITOR AND PUMP CONTROLLER)

#include <NewPing.h>
#include <IRremote.h>

... removed code that was not in code tags and unusable.

** MAX = eeprom_read_word(OFF_PUMP);**
** MIN = eeprom_read_word(ON_PUMP);**
}

all the stars and bold font in your source code takes up lots of SRAM... get rid of it

:innocent: :grimacing:

PS: do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).

1 Like

These stars are not appear in my the program, but they appeared when I copied and pasted the code here

too bad code tags did not appear !

1 Like

no cigar!

:grimacing:

Hello majidye
Post your sketch well formatted, with comments and in so called code tags grafik.
Have a nice day and enjoy coding in C++.
Дайте миру шанс!

I'm not an Arduino programming expert, I'm just a hobbyist. I wrote this code by searching and browsing the internet.

Just add the code tags.
No Arduino programming experience required

Try the "copy for forum" method
https://forum.arduino.cc/t/understanding-code-tags/956396/15

1 Like

Use the Autoformat tool in the IDE.

Use the Copy for Forum tool in the IDE.

Then you can just paste your code here, it should look like

void setup() {

/// code code code

}

void loop() {

/// code code code oh so much code OMG 

}

code.

HTH

a7

#include <NewPing.h>
#include <IRremote.h>
#include <NewTone.h>
const int RECV_PIN = 12; 
IRrecv irrecv(RECV_PIN);
decode_results results;
#include<avr/eeprom.h>
#include <LcdBarGraph.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd (7, 6, 5, 4, 3, 2);

byte lcdNumCols = 20; 
LcdBarGraph lbg0(&lcd, lcdNumCols, 0, 1);  
LcdBarGraph lbg1(&lcd, lcdNumCols, 0, 3);

int pumpcont[] = {4, 0, 2, 1};
int alarm_disable[] = {4, 0, 2, 1};
int lcdcont[] = {4, 0, 2, 1};
int roww[] = {4, 0, 2, 1};
int info_page1[] = {4, 0, 2, 1};
int info_page2[] = {4, 0, 2, 1};

#define SONAR_NUM 2     


NewPing sonar[SONAR_NUM] = {   

  NewPing(11, 10),
  
  NewPing(8, 9)   
};

float pum1 = 0.8;  


float pum2 = 0.75; 
float pum3 = 0.25;  
int relay = 13; 

int buzz = A2;   
int led_alarm = A3; 
int stop_button = A4; 
const int restart_pin = A5; 


#define up 0xFF906F 
#define down 0xFFE01F
#define ir_info 0xFFA25D 
#define ir_stop 0xFFE21D
#define ir_move_up 0xFF02FD 
#define ir_move_down 0xFF9867
#define ir_setting 0xFFA857               
#define ir_reset 0xFF18E7   
#define save 0xFFB04F  
#define ir_pump 0xFF7A85 
#define ir_exit 0xFF6897
#define ir_restart 0xFF30CF

#define ir_no 0xFF22DD 

#define ir_yes 0xFFC23D 



#define delay_change_value 50
#define delay_select 500
#define delay_text_view 100
#define delay_text_info_view 7000
#define delay_save 100
#define delay_setting_view 4000
#define delay_error_text 2000
#define delay_press_tone1 100
#define delay_press_tone2 200
#define delay_press_tone3 300
#define delay_press_tone4 500
#define delay_press_tone5 20  
#define delay_press_tone6 800
#define delay_warning_tone 1000
#define frq_press_tone1 150    
#define frq_press_tone3 1500   



unsigned long lastTime = 0;
unsigned long timerDelay = 1000;
unsigned long lastTime1 = 0;
unsigned long timerDelay1 = 4000;


int high_tank1 = 1;    
int tank1 = 0 ;      
int distance_sen_wat1 = 5;  
int sensor1 = 0;               
int high_tank2 = 3;  
int tank2 = 0 ;    
int distance_sen_wat2 = 7;  
int sensor2 = 0;                

int ON_PUMP = 9;   
int MIN = 0 ;
int OFF_PUMP = 11;  
int MAX = 0;


int distance1 = 1;
int distance2 = 2;
int precent1, precent2;
int heigh1, heigh2;
float heightofwater11,  heightofwater12;
int heightofwater1, heightofwater2;
char tank1string_arr [10];
char tank2string_arr [10];
char sendstring [10];

int pump_save;
int val ;
int VAL1;
int VAL2;
int VAL3;
int VAL4;
int VAL5;
int VAL6;
int VAL7;
int row;
int exit_sure;
int L1 = 0;
int L2 = 0;
int L3 = 0;
int avrg = 0;
int larm;
unsigned int sec = 0;
unsigned int mint = 0;
bool pump = false;
bool pump1 = true;
bool IR = false;
bool NUM = false;
bool lcd1 = false;
bool RESTART = false;
int reset ;
int sett ;
bool IR_SAVE = false;
bool ON_OK = true;
bool OFF_OK = true;
bool UP_ULTRA = true;
bool DOWN_ULTRA = true;
bool DOWN_PAGE = false;
bool UP_PAGE = false;

byte p20[8] = {
  B10000,
  B10000,
  B10000,
  B10000,
  B10000,
  B10000,
  B10000,
  B10000,
};
byte p40[8] = {
  B11000,
  B11000,
  B11000,
  B11000,
  B11000,
  B11000,
  B11000,
  B11000,
};
byte p60[8] = {
  B11100,
  B11100,
  B11100,
  B11100,
  B11100,
  B11100,
  B11100,
  B11100,
};
byte p80[8] = {
  B11110,
  B11110,
  B11110,
  B11110,
  B11110,
  B11110,
  B11110,
  B11110,
};
byte p100[8] = {
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
};
byte ROW[] = {
  B00000,
  B00100,
  B00010,
  B11111,
  B00010,
  B00100,
  B00000,
  B00000
};
byte RIGHT[10] = {
  0b00000,
  0b00001,
  0b00011,
  0b10110,
  0b11100,
  0b01000,
  0b00000,
  0b00000
};

byte customChar[] = {
  0b00001,
  0b00011,
  0b01111,
  0b01111,
  0b01111,
  0b00011,
  0b00001,
  0b00000
};
byte customChar1[] = {
  B00000,
  B10001,
  B11011,
  B01110,
  B01110,
  B11011,
  B10001,
  B00000
};

void setup()
{ irrecv.enableIRIn();
  Serial.begin (9600);
  pinMode(stop_button, INPUT_PULLUP);
  pinMode(relay, OUTPUT);
  pinMode(led_alarm, OUTPUT);
  pinMode(buzz, OUTPUT);
  VAL1 = 1;
  VAL2 = 1;
  VAL3 = 1;
  VAL4 = 1;
  VAL5 = 1;
  VAL6 = 1;
  VAL7 = 1;
  pump_save = 0;
  row = 0;
  larm = 1;
  reset = 0;
  sett = 0;
  val = 0;
  exit_sure = 0;
 lcd.begin(20, 4);
  tank1 = eeprom_read_word(high_tank1);
  tank2 = eeprom_read_word(high_tank2);
  sensor1 = eeprom_read_word(distance_sen_wat1);
  sensor2 = eeprom_read_word(distance_sen_wat2);
  MIN = eeprom_read_word(ON_PUMP);
  MAX = eeprom_read_word(OFF_PUMP);
  lcd.createChar(0, p20);
  lcd.createChar(1, p40);
  lcd.createChar(2, p60);
  lcd.createChar(3, p80);
  lcd.createChar(4, p100);
  lcd.createChar(5, customChar);
  lcd.createChar(6, customChar1);
  lcd.createChar(7, ROW);
  lcd.createChar(8, RIGHT);
  lcd.setCursor(1, 0);
  lcd.print("WATER TANK MONITOR");
  lcd.setCursor(0, 1);
  lcd.print("AND PUMP CONTROLLER");
  lcd.setCursor(0, 2);
  lcd.print("DESIGNE BY:");
  lcd.setCursor(1, 3);
  lcd.print("(MAJID ABDULKAREEM)");
  delay(delay_text_info_view);
  lcd.clear();
  digitalWrite(restart_pin, HIGH);
  pinMode(restart_pin, OUTPUT);
}
void loop()
{
  if (irrecv.decode(&results)) {
  
    switch (results.value) {
      case ir_restart:
        if (RESTART == false) {
          delay(delay_save);
          exit1();
        }
    }

    
    switch (results.value) {
      case  ir_stop:

        VAL1 = 2;
        VAL2 = 2;
        VAL3 = 2;
        if (larm == 0) {
          larm = 2;
        }
        if ( VAL6 == 0 ) {
          VAL5 = 2;
          VAL6 = 2;
        }
    }

  
    switch (results.value) {
      case  ir_info:
        if (lcd1 == false) {
          if (lcdcont[1] == 0) {
            lcdcont[1] = 1;
            delay(300);
            lcd.clear();
            val = 1;
            IR = true ;
            VAL7 = 0;
            NUM = true ;
            RESTART = true ;
            DOWN_PAGE = true;
            UP_PAGE = true;
            pumpcont[1] = 3;
            reset = 5;
            eprom_val();
            info1();
            select_tone();
          }

          else if (lcdcont[1] == 1) {
            select_tone();
            lcd.clear();
            val = 0;
            reset = 0;
            IR = false ;
            NUM = false ;
            VAL7 = 1;
            RESTART = false ;
            DOWN_PAGE = false;
            UP_PAGE = false;
            pumpcont[1] = 0;
            lcdcont[1] = 0;

            delay(300);
          }
        }
    }

    switch (results.value) {
      case ir_move_down:
        if (DOWN_PAGE == true ) {
          if (info_page1[1] == 0) {
            delay(delay_select);
            info_page1[1] = 1;
            info2();
            select_tone();
          }

          else if (info_page1[1] == 1) {
            delay(delay_select);
            info_page1[1] = 2;
            info3();
            select_tone();
          }
        }
    }


    switch (results.value) {
      case ir_move_up:
        if (UP_PAGE == true ) {
          if (info_page1[1] == 2) {
            delay(delay_select);
            info_page1[1] = 1;
            info2();
            select_tone();
          }

          else if (info_page1[1] == 1) {
            delay(delay_select);
            info_page1[1] = 0;
            info1();
            select_tone();
          }
        }
    }


    switch (results.value) {
      case  ir_pump:
        if (pumpcont[1] == 0) {
          pump = true;
          pumpcont[1] = 1;
          select_tone();
          delay(300);
        }
        else if (pumpcont[1] == 1) {
          pump = false;
          pumpcont[1] = 0;
          select_tone();
          delay(300);
        }
    }

    switch (results.value) {
      case  ir_exit:

        if (alarm_disable[1] == 0 && lcdcont[1] == 0 && reset == 0 && IR == false) {

          alarm_disable[1] = 1;

          VAL4 = 2;
          select_tone();
          delay(300);
        }

        else if (alarm_disable[1] == 1 && lcdcont[1] == 0 && reset == 0 && IR == false) {
          alarm_disable[1] = 0;

          VAL4 = 1;
          select_tone();
          delay(300);
        }
    }

    switch (results.value) {
      case  ir_reset:
        if (reset == 0) {

          delay(delay_select);
          reset = 2;
          sett = 1;
          val = 1;
          VAL7 = 0;
          RESTART = true;
          lcd1 = true;
          IR = true ;
          NUM = true ;
          pump1 = false;
          pumpcont[1] = 3;
          lcd.clear();
          lcd.setCursor(2, 0);
          lcd.print("DO YOU WANT RESET");
          lcd.setCursor(5, 1);
          lcd.print ("ALL VALUES?");
          lcd.setCursor(7, 3);
          lcd.print ("NO  YES");


          eprom_val();
          warning_tone();

        }
    }

    switch (results.value) {
      case  ir_no:

        if (reset == 2) {
          delay(delay_select);
          pumpcont[1] = 0;
          sett = 0;
          lcd.clear();
          lcd.setCursor(1, 1);
          lcd.print("RESET IS CANCELED");
          exit_tone();
          delay(delay_text_view);
          exit1();
        }

    }

    switch (results.value) {
      case  ir_yes:
        if (reset == 2) {
          delay(delay_select);
           eeprom_update_word(high_tank1, 100);
            eeprom_update_word(high_tank2, 400);
            eeprom_update_word(distance_sen_wat1, 10);
           eeprom_update_word(distance_sen_wat2, 20);
           eeprom_update_word(OFF_PUMP, 95);
           eeprom_update_word(ON_PUMP, 50);
          lcd.clear();
          lcd.setCursor(0, 1);
          lcd.print("RESET IN PROGRESSING");
          reset_tone();
          for (int i = 0; i < 20; i++)
          {
            for (int j = 0; j < 5; j++)
            {
              lcd.setCursor(i, 2);
              lcd.write(j);
              delay(delay_save);
            }
          }
          lcd.clear();
          reset = 0;
          sett = 0;
          val = 0;
          VAL4 = 1;

          lcd1 = false;
          IR = false ;
          NUM = false ;
          exit1();
        }
    }


    switch (results.value) {
      case  ir_setting:
        if (IR == false && sett == 0) {
          delay(delay_select);

          eprom_val();
          IR = true;
          lcd1 = true;
          pump1 = false;

          val = 1;
          VAL7 = 0;
          RESTART = true;
          reset = 1;
          sett = 2;
          pumpcont[1] = 3;

          select_tone();
          lcd.clear();
          roww[1] = 1;
          row = 1;
   

          lcd.setCursor(0, 0);
          lcd.write(byte(7)); 
         

          lcd_display();
        }
    }
 
    switch (results.value) {
      case  ir_exit:
        if (IR == true && exit_sure == 0 && sett == 2) {


          exit_tone();
          pumpcont[1] = 0;
          exit1();
        }
        else if ( IR == true && exit_sure == 1 && sett == 2) {
          lcd.clear();
          lcd_sure();
          exit_sure = 2;
          NUM = true ;
          warning_tone();
        }
    }
    switch (results.value) {
      case  ir_yes:
        if (IR == true && exit_sure == 2 && sett == 2) {

          exit_sure = 0;
          exit_tone();
          pumpcont[1] = 0;
          exit1();
        }
    }


    switch (results.value) {
      case  ir_no:
        if (IR == true && exit_sure == 2 && sett == 2) {
          exit_sure = 1;
          NUM = false ;
          lcd.clear();
          lcd_display();
          roww[1] = 1;
          row = 1;
          lcd.setCursor(0, 0);
          lcd.write(7);
          select_tone();

        }
    }
    switch (results.value) {
      case ir_move_up:
        if (IR == true && NUM == false && UP_PAGE == false) {
          delay(delay_select);
         
          if (roww[1] == 2) {
            roww[1] = 1;
            row = 1;

            lcd.setCursor(0, 0);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd.setCursor(0, 0);
            lcd.write(7);
          }
          else if (roww[1] == 3) {
            roww[1] = 2;
            row = 2;
            lcd.clear();
            lcd_display();
            lcd.setCursor(0, 1);
            lcd.write(7);
          }

          else if (roww[1] == 4) {
            roww[1] = 3;
            row = 3;
            lcd.setCursor(0, 0);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd_display2();
            lcd.setCursor(0, 0);
            lcd.write(7);
          }
          else if (roww[1] == 5) {
            roww[1] = 4;
            row = 4;
            lcd.clear();
            lcd.setCursor(0, 1);
            lcd.write(7);
            lcd_display2();
          }
          else if (roww[1] == 6) {
            roww[1] = 5;
            row = 5;
            lcd.setCursor(0, 0);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd.setCursor(0, 0);
            lcd.write(byte(7));
            lcd_display3();
          }
          select_tone();
        }
    }

 
    switch (results.value) {
      case ir_move_down:
        if (IR == true && NUM == false && DOWN_PAGE == false) {
          delay(delay_select);
         
          if (roww[1] == 1) {
            roww[1] = 2;
            row = 2;
            lcd.setCursor(0, 0);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.write(7);




          }

          else if (roww[1] == 2) {
            roww[1] = 3;
            row = 3;
            lcd.clear();
            lcd_display2();
            lcd.setCursor(0, 0);
            lcd.write(byte(7));

          }
          else if (roww[1] == 3) {
            roww[1] = 4;
            row = 4;
            lcd.setCursor(0, 0);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.write(byte(7));
          }
       
          else if (roww[1] == 4) {
            roww[1] = 5;
            row = 5;
            lcd.clear();
            lcd_display3();
            lcd.setCursor(0, 0);
            lcd.write(byte(7));

            if ((MIN > pum2 * tank1) || (MIN < pum3 * tank1) || MIN == 0) {
              lcd.setCursor(19, 0);
              lcd.print(" ");
              lcd.setCursor(19, 0);
              lcd.write(byte(6));
            }
            else {
              lcd.setCursor(19, 0);
              lcd.print(" ");
              lcd.setCursor(19, 0);
              lcd.write(byte(8));
            }

            if ((MAX > tank1) || (MAX < pum1 * tank1) || MAX == 0) {
              lcd.setCursor(19, 1);
              lcd.print(" ");
              lcd.setCursor(19, 1);
              lcd.write(byte(6));
            }
            else {
              lcd.setCursor(19, 1);
              lcd.print(" ");
              lcd.setCursor(19, 1);
              lcd.write(byte(8));
            }

          }
          else if (roww[1] == 5) {
            roww[1] = 6;
            row = 6;
            lcd_display3();
            lcd.setCursor(0, 0);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.write(byte(7));
          }
          select_tone();
        }
    }
   
    switch (results.value) {
      case up:
        if (IR == true && NUM == false) {
          if (row == 1 ) {
            delay(delay_change_value);
            tank1 = tank1 + 1;
            if (tank1 > 300) tank1 = 300;
          }
          if (row == 2 ) {
            delay(delay_change_value);
            sensor1 = sensor1 + 1;
            if (sensor1 > 50) sensor1 = 50;

          }
          if (row == 3 ) {
            delay(delay_change_value);
            tank2 = tank2 + 1;
            if (tank2 > 450) tank2 = 450;
          }
          if (row == 4 ) {
            delay(delay_change_value);
            sensor2 = sensor2 + 1;
            if (sensor2 > 50) sensor2 = 50;
          }
         
          if (row == 5 ) {
            delay(delay_change_value);
            MIN = MIN + 1;
            if ((MIN > pum2 * tank1) || (MIN < pum3 * tank1) || MIN == 0) {
              lcd.setCursor(19, 0);
              lcd.print(" ");
              lcd.setCursor(19, 0);
              lcd.write(byte(6));
            }
            else {
              lcd.setCursor(19, 0);
              lcd.print(" ");
              lcd.setCursor(19, 0);
              lcd.write(byte(8));
            }
          }
        
          if (row == 6 ) {
            delay(delay_change_value);
            MAX = MAX + 1;
            if ((MAX > tank1) || (MAX < pum1 * tank1) || MAX == 0) {
              lcd.setCursor(19, 1);
              lcd.print(" ");
              lcd.setCursor(19, 1);
              lcd.write(byte(6));
            }
            else {
              lcd.setCursor(19, 1);
              lcd.print(" ");
              lcd.setCursor(19, 1);
              lcd.write(byte(8));
            }
          }
         

          if (row == 3 ) {
            lcd.setCursor(16, 0);
            lcd.print("   ");
            lcd.setCursor(0, 0);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd.setCursor(0, 0);
            lcd.write(byte(7));
            lcd_display2();
          }
          else if ( row == 4) {
            lcd.setCursor(16, 1);
            lcd.print("   ");
            lcd.setCursor(0, 0);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.write(byte(7));
            lcd_display2();
          }

          else if ( row == 5) {
            lcd.setCursor(16, 0);
            lcd.print("   ");
            lcd.setCursor(0, 0);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd.setCursor(0, 0);
            lcd.write(byte(7));
            lcd_display3();
          }
          else if ( row == 6) {
            lcd.setCursor(16, 1);
            lcd.print("   ");
            lcd.setCursor(0, 0);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.write(byte(7));
            lcd_display3();
          }
          else {
            lcd.clear();
            if (row == 1) {
              lcd.setCursor(0, 0);
              lcd.write(7);
            }
            if (row == 2) {
              lcd.setCursor(0, 1);
              lcd.write(7);
            }
            if (row == 3) {
              lcd.setCursor(0, 2);
              lcd.write(7);
            }
            if (row == 4) {
              lcd.setCursor(0, 3);
              lcd.write(7);
            }

            lcd_display();
          }
          change_tone();
          exit_sure = 1;
          IR_SAVE = true;
        }
    }


    switch (results.value) {
      case down:
        if (IR == true && NUM == false) {
          if (row == 1 ) {
            delay(delay_change_value);
            tank1 = tank1 - 1;
            if (tank1 < 0) tank1 = 0;
          }
          if (row == 2 ) {
            delay(delay_change_value);
            sensor1 = sensor1 - 1;
            if (sensor1 < 10) sensor1 = 10;
          }
          if (row == 3 ) {

            delay(delay_change_value);
            tank2 = tank2 - 1;
            if (tank2 < 0) tank2 = 0;
          }
          if (row == 4 ) {
            delay(delay_change_value);
            sensor2 = sensor2 - 1;

            if (sensor2 < 10) sensor2 = 10;
          }
          
          if (row == 5 ) {
            delay(delay_change_value);
            MIN = MIN - 1;
            if ((MIN > pum2 * tank1) || (MIN < pum3 * tank1)) {
              lcd.setCursor(19, 0);
              lcd.print(" ");
              lcd.setCursor(19, 0);
              lcd.write(byte(6));
            }
            else {
              lcd.setCursor(19, 0);
              lcd.print(" ");
              lcd.setCursor(19, 0);
              lcd.write(byte(8));
            }
          }

     
          if (row == 6 ) {
            delay(delay_change_value);
            MAX = MAX - 1;
            if ((MAX > tank1) || (MAX < pum1 * tank1)) {
              lcd.setCursor(19, 1);
              lcd.print(" ");
              lcd.setCursor(19, 1);
              lcd.write(byte(6));
            }
            else {
              lcd.setCursor(19, 1);
              lcd.print(" ");
              lcd.setCursor(19, 1);
              lcd.write(byte(8));
            }
          }


          if (row == 3 ) {
            lcd.setCursor(16, 0);
            lcd.print("   ");
            lcd.setCursor(0, 0);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd.setCursor(0, 0);
            lcd.write(byte(7));
            lcd_display2();
          }
          else if ( row == 4) {
            lcd.setCursor(16, 1);
            lcd.print("   ");
            lcd.setCursor(0, 0);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.write(byte(7));
            lcd_display2();
          }
          else if ( row == 5) {
            lcd.setCursor(16, 0);
            lcd.print("   ");
            lcd.setCursor(0, 0);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd.setCursor(0, 0);
            lcd.write(byte(7));
            lcd_display3();
          }
          else if ( row == 6) {
            lcd.setCursor(16, 1);
            lcd.print("   ");
            lcd.setCursor(0, 0);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.write(byte(7));
            lcd_display3();
          }
        
          else {
            lcd.clear();
            if (row == 1) {
              lcd.setCursor(0, 0);
              lcd.write(7);
            }
            if (row == 2) {
              lcd.setCursor(0, 1);
              lcd.write(7);
            }
            if (row == 3) {
              lcd.setCursor(0, 0);
              lcd.write(7);
            }
            if (row == 4) {
              lcd.setCursor(0, 1);
              lcd.write(7);
            }

            if (row == 5) {
              lcd.setCursor(0, 0);
              lcd.write(7);
            }
            if (row == 6) {
              lcd.setCursor(0, 1);
              lcd.write(7);
            }
            lcd_display();
          }
          change_tone();
          exit_sure = 1;
          IR_SAVE = true;
        }
    }
   
    
    switch (results.value) {
      case save:
        if (IR_SAVE == false && IR == true && sett == 2) {

          lcd_display4();
        }
    }
    switch (results.value) {
      case save:
        if (IR_SAVE == true && sett == 2) {
          if ((MAX > tank1 || MAX < pum1 * tank1) && (MIN <= pum2 * tank1 && MIN >= pum3 * tank1))   {
            OFF_OK = false;
            ON_OK = true;
          }
          if ( ( MIN > pum2 * tank1 || MIN < pum3 * tank1) && (MAX <= tank1 && MAX >= pum1 * tank1)) {
            ON_OK = false;
            OFF_OK = true;
          }

          if ((MAX > tank1 || MAX < pum1 * tank1 ) && ( MIN > pum2 * tank1 || MIN < pum3 * tank1)) {
            ON_OK = false;
            OFF_OK = false;
          }
          if (MAX <= tank1 && MAX >= pum1 * tank1 && MIN <= pum2 * tank1 && MIN >= pum3 * tank1) {
            ON_OK = true;
            OFF_OK = true;
          }
          if (ON_OK == true && OFF_OK == false) {
            lcd.clear();
            ERROR_SAVE();
            ERROR_SAVE_1();
            warning_tone();
            delay(delay_error_text);
            roww[1] = 6;
            row = 6;
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.write(byte(7));
            lcd.setCursor(19, 0);
            lcd.print(" ");
            lcd.setCursor(19, 0);
            lcd.write(byte(8));
            lcd.setCursor(19, 1);
            lcd.print(" ");
            lcd.setCursor(19, 1);
            lcd.write(byte(6));
            lcd_display3();
          }
          if (ON_OK == false && OFF_OK == true) {
            lcd.clear();
            ERROR_SAVE();
            ERROR_SAVE_2();
            warning_tone();
            delay(delay_error_text);
            roww[1] = 5;
            row = 5;
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd.setCursor(0, 0);
            lcd.write(byte(7));
            lcd.setCursor(19, 1);
            lcd.print(" ");
            lcd.setCursor(19, 1);
            lcd.write(byte(8));
            lcd.setCursor(19, 0);
            lcd.print(" ");
            lcd.setCursor(19, 0);
            lcd.write(byte(6));
            lcd_display3();
          }
          if (ON_OK == false && OFF_OK == false) {
            lcd.clear();
            ERROR_SAVE();
            ERROR_SAVE_3();
            warning_tone();
            delay(delay_error_text);
            roww[1] = 5;
            row = 5;
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print(" ");
            lcd.setCursor(0, 1);
            lcd.print(" ");
            lcd.setCursor(0, 0);
            lcd.write(byte(7));
            lcd.setCursor(19, 0);
            lcd.print(" ");
            lcd.setCursor(19, 1);
            lcd.print(" ");
            lcd.setCursor(19, 0);
            lcd.write(byte(6));
            lcd.setCursor(19, 1);
            lcd.write(byte(6));
            lcd_display3();
          }
          if (ON_OK == true && OFF_OK == true) {
            delay(delay_save);
              eeprom_update_word(high_tank1, tank1);
              eeprom_update_word(distance_sen_wat1, sensor1);
              eeprom_update_word(high_tank2, tank2);
               eeprom_update_word(distance_sen_wat2, sensor2);
               eeprom_update_word(OFF_PUMP, MAX);
             eeprom_update_word(ON_PUMP, MIN);
            exit_sure = 0;
            lcd.clear();
            save1();
          }
        }
    }

    irrecv.resume();
  }

  if (val == 0) {
    if ((millis() - lastTime) > timerDelay) {
      heightofwater1 = eeprom_read_word(high_tank1) - (sonar[0].ping_cm() - eeprom_read_word(distance_sen_wat1));
      dtostrf (heightofwater1, 0, 2, tank1string_arr);      
    
      heightofwater2 = eeprom_read_word(high_tank2) - (sonar[1].ping_cm() - eeprom_read_word(distance_sen_wat2));
      dtostrf(heightofwater2, 0, 2, tank2string_arr);    

    strcat (sendstring, tank1string_arr);
      strcat (sendstring, tank2string_arr);

      Serial.print(sendstring);
      delay (200);
      memset(sendstring, '\0', 10);

      heigh1 = 0;
      heigh2 = 0;
      heightofwater11 = heightofwater1;
      heightofwater12 = heightofwater2;
      if (heightofwater1 >= 0) {
        precent1 = (heightofwater11 / eeprom_read_word(high_tank1)) * 100;
      }
      else {
        precent1 = (heigh1 / eeprom_read_word(high_tank1)) * 100;
      }

  
      if (heightofwater2 >= 0) {
        precent2 = (heightofwater12 / eeprom_read_word(high_tank2)) * 100;
      }
      else {
        precent2 = (heigh2 / eeprom_read_word(high_tank2)) * 100;
      }




      if (heightofwater1 >= 0 && heightofwater1 <= eeprom_read_word(high_tank1) ) {
        lbg0.drawValue( (heightofwater1), ( tank1));
      }

      if (heightofwater1 > eeprom_read_word(high_tank1) ) {
        lbg0.drawValue( (tank1), ( tank1));
      }
      if (heightofwater1 < 0) {
        lbg0.drawValue( (0), ( tank1));
      }

      if (heightofwater2 >= 0  && heightofwater2 <= eeprom_read_word(high_tank2) ) {
        lbg1.drawValue( (heightofwater2), ( tank2));
      }

      if (heightofwater2 > eeprom_read_word(high_tank2) ) {
        lbg1.drawValue( (tank2), ( tank2));
      }
      if (heightofwater2 < 0) {
        lbg1.drawValue( (0), ( tank2));
      }
 
      if (VAL4 == 2) {
        lcd.setCursor (0, 0);
        lcd.print("        ");
        lcd.setCursor(3, 0);
        lcd.write(byte(5));
        lcd.setCursor(4, 0);
        lcd.write(byte(6));
      }
      else {
        lcd.setCursor (0, 0);
        lcd.print("        ");
        lcd.setCursor (0, 0);
        lcd.print("UP.TANK:");
      }

      lcd.setCursor(9, 0);
      lcd.print("           ");
      if (heightofwater1 >= 0) {
        lcd.setCursor (9, 0);
        lcd.print(heightofwater1);
        lcd.print(" CM");
      }
      else {
        lcd.setCursor(9, 0);
        lcd.print(heigh1);
        lcd.print(" CM");
      }

      lcd.setCursor(16, 0);
      lcd.print( precent1  );
      lcd.print("% ");
      lcd.setCursor (0, 2);
      lcd.print("GR.TANK:");
      lcd.setCursor(9, 2);
      lcd.print("           ");
      if (heightofwater2 >= 0) {
        lcd.setCursor (9, 2);
        lcd.print(heightofwater2);
        lcd.print(" CM");
      }
      else {
        lcd.setCursor (9, 2);
        lcd.print(heigh2);
        lcd.print(" CM");
      }

      lcd.setCursor(16, 2);
      lcd.print( precent2  );
      lcd.print("% ");
      sec++;
      lastTime = millis();
    }
  }

 

  if (digitalRead(stop_button) == LOW && VAL6 == 0   ) {

    VAL5 = 2;
    VAL6 = 2;
  }
  if (digitalRead(stop_button) == LOW  ) {
    VAL1 = 2;
    VAL2 = 2;
    VAL3 = 2;
    if (larm == 0) {
      larm = 2;
    }
  }



  if (sec > 44) {
    sec = 0;
    mint = mint + 1;
  }
  if (mint > 5) {
    mint = 0;
    L1 = 0;
    L3 = 0;
  }
  if (sec == 1 && mint == 0 ) {
    L1 = heightofwater1;
  }

  if (sec == 1 && mint == 4) {
    L2 = heightofwater1;
  }

  if (sec == 1 && mint == 5) {
    L3 = heightofwater1;
  }
  avrg = (L1 - L3);

  if ((avrg > 3) && larm == 1 && L3 > 0 && heightofwater1 > 75) {
    larm = 0;

  }
  if ((avrg >= 1) && larm == 1 && L3 > 0 && heightofwater1 <= 75) {
    larm = 0;
  }
  if ((L1 == L2) || ((L3 - L1) > 2)) {
    larm = 1;
  }
  if (larm == 0) {
    digitalWrite(led_alarm, HIGH);

  }
  else {
    digitalWrite(led_alarm, LOW);
  }

  if (VAL7 == 1) {
    if (VAL4 == 1) {

      if  (heightofwater1 >= tank1 && VAL1 == 1 )    {
        VAL1 = 0;
      }
      if (VAL1 == 0) {
       
           alarm1();
      }
      if (heightofwater1 < tank1 - 5) {
        VAL1 = 1;

      }
      if (heightofwater1 < 0.45 * tank1 && VAL3 == 1 )    {
        VAL3 = 0;
      }
      if (VAL3 == 0) {
         alarm2();
      }
      if ( heightofwater1 >= (0.45 * tank1) + 5 )    {
        VAL3 = 1;
      }

      if (heightofwater2 >= tank2  && heightofwater2 < tank2 + 5 && VAL2 == 1 )    {
        VAL2 = 0;
      }
      if (VAL2 == 0) {
          alarm2();
        
      }
      if (heightofwater2 < tank2 - 5)    {
        VAL2 = 1;
        VAL5 = 1;
        VAL6 = 1;

      }

    

      if (heightofwater2 >= tank2 + 5 && VAL5 == 1 )    {
        VAL5 = 0;
        VAL6 = 0;
        VAL2 = 2;
      }
      if (VAL5 == 0) {
        
         alarm4();
      }
      if (heightofwater2 < tank2)    {
        VAL5 = 1;

      }

    }
  }



  if (MAX > tank1 || MAX < pum1 * tank1 || MIN > pum2 * tank1 || MIN < pum3 * tank1  ) {
    pump_save = 1;

  }
  if (MAX <= tank1 && MAX >=  pum1 * tank1 && MIN <= pum2 * tank1 && MIN >= pum3 * tank1  ) {
    pump_save = 0;

  }
  if (pump_save == 0) {
    if (heightofwater1 <= MIN && (heightofwater2 > 0.3 * (tank2)  ) )  {
      pump = true;
    }

    if ((heightofwater1 >= MAX || (heightofwater2 <= 0.3 * (tank2)  )) )   {
      pump = false;
    }

    if (pump == true && pump1 == true) {  

      digitalWrite(relay, HIGH);
    }


    if (pump == false || pump1 == false ) {
      digitalWrite(relay, LOW);
    }
  }

}




void alarm1() {
  for (int hz = 500; hz < 600; hz += 1) {
    NewTone(buzz, hz, 150);
    delay(3);
  }
}

void alarm2() {
  if ((millis() - lastTime1) > timerDelay1) {
    NewTone(buzz, 400, 700);
    lastTime1 = millis();
  }
}



void alarm3() {
  for (int hz = 100; hz < 150; hz += 1) {
    NewTone(buzz, hz, 50);
    delay(45);
  }
}

void alarm4() {
  for (int hz = 150; hz < 350; hz += 4) {
    NewTone(buzz, hz, 7);
    delay(6);
  }
}


void warning_tone() {

  NewTone(buzz, frq_press_tone1);
  delay(delay_warning_tone);
  noNewTone(buzz);

}

void select_tone() {
  NewTone( buzz, frq_press_tone3);
  delay(delay_press_tone1);
  noNewTone(buzz);
}
void save_tone() {
  NewTone( buzz, frq_press_tone3);
  delay(delay_press_tone4);
  noNewTone( buzz);
  delay(delay_press_tone1);
  NewTone( buzz, frq_press_tone3);
  delay(delay_press_tone4);
  noNewTone( buzz);
  delay(delay_press_tone1);
  NewTone( buzz, frq_press_tone3);
  delay(delay_press_tone6);
  noNewTone(buzz);
}
void change_tone() {
  NewTone( buzz, frq_press_tone3);
  delay(delay_press_tone5);
  noNewTone(buzz);
}
void exit_tone() {
  NewTone( buzz, frq_press_tone3);
  delay(delay_press_tone4);
  noNewTone(buzz);
}
void reset_tone() {
  NewTone( buzz, frq_press_tone3);
  delay(delay_press_tone4);
  noNewTone(buzz);
  delay(delay_press_tone1);
  NewTone( buzz, frq_press_tone3);
  delay(delay_press_tone4);
  noNewTone(buzz);
  delay(delay_press_tone1);
  NewTone( buzz, frq_press_tone3);
  delay(delay_press_tone6);
  noNewTone(buzz);
}
void info1() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("UPPER TANK    ");
  lcd.print(tank1);
  lcd.setCursor(18, 0);
  lcd.print("CM");
  lcd.setCursor(0, 1);
  lcd.print("UPPER SENSOR  ");
  lcd.print(sensor1);
  lcd.setCursor(18, 1);
  lcd.print("CM");
  lcd.setCursor(4, 3);
  lcd.print("(DOWN / INFO.)");

}
void info2() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("GROUND TANK   ");
  lcd.print(tank2);
  lcd.setCursor(18, 0);
  lcd.print("CM");
  lcd.setCursor(0, 1);
  lcd.print("GROUND SENSOR ");
  lcd.print(sensor2);
  lcd.setCursor(18, 1);
  lcd.print("CM");

  lcd.setCursor(0, 3);
  lcd.print("(UP / DOWN / INFO.)");

}

void info3() {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("ON  PUMP VAL. ");
  lcd.print(MIN);
  lcd.setCursor(18, 0);
  lcd.print("CM");
  lcd.setCursor(0, 1);
  lcd.print("OFF PUMP VAL. ");
  lcd.print(MAX);
  lcd.setCursor(18, 1);
  lcd.print("CM");
  lcd.setCursor(4, 3);
  lcd.print("(UP / INFO.)");

}


void save1() {
  lcd.setCursor(4, 0);
  lcd.print("SAVING VALUE");

  for (int i = 0; i < 20; i++)
  {
    for (int j = 0; j < 5; j++)
    {
      lcd.setCursor(i, 2);
      lcd.write(j);
      delay(delay_save);
    }
  }
  lcd.clear();

  lcd.setCursor(3, 0);
  lcd.print("ALL VALUES ARE");
  lcd.setCursor(1, 2);
  lcd.print("SAVED SUCCESSFULLY");
  row = 0;

  save_tone();

  delay(delay_text_view);

  IR_SAVE = false;
  eprom_val();
  lcd.clear();
  roww[1] = 1;
  row = 1;
  lcd.setCursor(0, 0);
  lcd.print(" ");

  lcd.setCursor(0, 0);
  lcd.write(7);
  lcd_display();
}
void exit1() {
  lcd.clear();
  lcd.setCursor(1, 1);
  lcd.print("DEVICE WILL RESTART");
  lcd.setCursor(5, 2);
  lcd.print("IN A MOMENT");
  delay(500);
  digitalWrite(restart_pin, LOW);
  lcd.clear();
  reset = 0;
  val = 0;
  VAL7 = 1;
  IR_SAVE = false;
  lcd1 = false;
  IR = false ;
  sett = 0;
  NUM = false ;
  pump1 = true;
  row = 0;
  RESTART = false;

  eprom_val();
}

void lcd_display() {

  lcd.setCursor(1, 0);
  lcd.print("UPPER TANK    ");
  lcd.print(tank1);
  lcd.setCursor(1, 1);
  lcd.print("UPPER SENSOR  ");
  lcd.print(sensor1);
  lcd.setCursor(0, 2);
  lcd.print("(+ / - / UP / DOWN)");
  lcd.setCursor(3, 3);
  lcd.print("(SAVE / Exit)");

}

void lcd_display2() {


  lcd.setCursor(1, 0);
  lcd.print("GROUND TANK   ");
  lcd.print(tank2);
  lcd.setCursor(1, 1);
  lcd.print("GROUND SENSOR ");
  lcd.print(sensor2);
  lcd.setCursor(0, 2);
  lcd.print("(+ / - / UP / DOWN)");
  lcd.setCursor(3, 3);
  lcd.print("(SAVE / Exit)");
}


void lcd_display3() {

  lcd.setCursor(1, 0);
  lcd.print("ON  PUMP LEVEL ");
  lcd.print(MIN);
  lcd.setCursor(1, 1);
  lcd.print("OFF PUMP LEVEL ");
  lcd.print(MAX);


  lcd.setCursor(0, 2);
  lcd.print("(+ / - / UP / DOWN)");
  lcd.setCursor(3, 3);
  lcd.print("(SAVE / Exit)");

}

void lcd_display4() {
  lcd.clear();
  lcd.setCursor(2, 1);
  lcd.print("THERE IS NO DATA");
  lcd.setCursor(1, 2);
  lcd.print("CHANGE TO BE SAVED");
  delay(delay_error_text);
  lcd.clear();
  lcd_display();
  roww[1] = 1;
  row = 1;

  lcd.setCursor(0, 0);
  lcd.write(7);

}
void ERROR_SAVE() {
  lcd.setCursor(7, 0);
  lcd.print("WARNING");
  lcd.setCursor(1, 1);
  lcd.print("CHECK THE VALUE OF");

}

void ERROR_SAVE_1() {

  lcd.setCursor(2, 3);
  lcd.print(" OFF PUMP LEVEL ");
}
void ERROR_SAVE_2() {


  lcd.setCursor(3, 3);
  lcd.print(" ON PUMP LEVEL ");

}

void ERROR_SAVE_3() {

  lcd.setCursor(0, 3);
  lcd.print("ON & OFF PUMP LEVELS");
}
void lcd_sure() {

  lcd.setCursor(0, 0);
  lcd.print("DO YOU WANT TO EXIT");
  lcd.setCursor(3, 1);
  lcd.print("WITHOUT SAVING?");
  lcd.setCursor(6, 3);
  lcd.print ("NO / YES");

}
void eprom_val() {
  tank1 = eeprom_read_word(high_tank1);
  tank2 = eeprom_read_word(high_tank2);
  sensor1 = eeprom_read_word(distance_sen_wat1);
  sensor2 = eeprom_read_word(distance_sen_wat2);
  MAX = eeprom_read_word(OFF_PUMP);
  MIN = eeprom_read_word(ON_PUMP);
}

Thank you very much

find all the lcd.print("xxx"); and change them for lcd.print(F("xxx"));

for example don't use

  lcd.print("CHECK THE VALUE OF");

but prefer

  lcd.print(F("CHECK THE VALUE OF"));

What is the memory usage data for your sketch after you use the F macro on all the lcd prints?

You can get the custom chars (64 bytes) into program memory but using them will be easier with the hd44780.h library.
https://forum.arduino.cc/t/progmem-vs-lcd-custom-characters/479740/12

when I change this code lcd.print ("GR.TANK:"); to this lcd.print(F("GR.TANK:")); and compile the code no problems appear
but , if i change this lcd.print(heightofwater2); to this lcd.print(F(heightofwater2)); and compile the code a problem (Error compiling for board arduino Nano ) is appear
What is the solution to the problem?

Just do it when you have double quotes - not for variables. so keep lcd.print(heightofwater2); as it is because there is no text directly into the print.

I mean fix the problem

which problem ?

this problem
(Error compiling for board arduino Nano )
but Ok you told me now to keep it without change because there is no text directly into the print

yes. only where you see "xxx" then you change into F("xxx") as I wrote in post 15...