EEPROM not working probably on codes.

I tried to follow other information regarding to these matter but I think i’m doing it wrong.
I tried to make the WATER, FREQUENCY AND TOTAL LITERS to save its data from the arduino mega 2560 rev3,and arduino uno r3 using an EEPROM write and read.

when I click the serial monitor and type any number on it.
the result was this

TOTAL :
352.22
L

VOL.:
350.2
L/M

TOTAL LITERS:
64.3
L

after I exit serial monitor, it didn’t save the numbers. maybe the code for the eeprom is wrong, but I don’t know how to reconfigure, 'cause i’m confused.

#include <EEPROM.h>
#define SERIAL_TX_BUFFER_SIZE 256
#define SERIAL_RX_BUFFER_SIZE 256
#define trigger 16
#define echo 19
#define Relay 6

float time = 0, distance = 0;
unsigned char flowsensor = 0; // Sensor Input
int val;
int val2;
int addr = 0;
int green = 32; //green yellow y red 
int yellow = 40;
int red =  48;
int button = 5;

byte value;
int counter;
int X;
int Y;
float TIME = 0;
float FREQUENCY = 0;
float WATER = 0;
float TOTAL = 0;
float LS = 0;
//int setLED;

void setup()
{
  Serial.begin(9600);
  pinMode(green, OUTPUT);
  pinMode(yellow, OUTPUT); //dagdag
  pinMode(red, OUTPUT);
  delay(200);
  Serial.println(EEPROM.read(addr));
  val2 = EEPROM.read(addr);
  switch (val2) 
  {
    case 1:
      digitalWrite(green, LOW);
      digitalWrite(yellow, LOW);
      digitalWrite(red, HIGH);
      Serial.println("RED ");
      break;
    case 2:
      digitalWrite(green, LOW);
      digitalWrite(yellow, HIGH);
      digitalWrite(red, LOW);
          Serial.println("yellow ");
      break;
    case 3:
      digitalWrite(green, HIGH);
      digitalWrite(yellow, LOW);
      digitalWrite(red, LOW);
         Serial.println("green ");
      break;
  }
  pinMode(flowsensor, INPUT);//ernal
  digitalWrite(flowsensor, HIGH); 
  EEPROM.write(0, flowsensor);// Optional IntPull-Up
  pinMode(trigger, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(Relay, OUTPUT);
  delay(500);
 if (Serial.available() > 0)
    {
      setLed();
    }
 
  //counter = EEPROM.read(0);
 // EEPROM.write(0, 0);

 
}
void loop()
{
    X = pulseIn(flowsensor, HIGH);
    Y = pulseIn(flowsensor, LOW);
    TIME = X + Y;
    EEPROM.write(0, FREQUENCY);
     EEPROM.read(FREQUENCY); 
    FREQUENCY = 1000000 / TIME;
    EEPROM.write(0, WATER);
    EEPROM.read(WATER);
    WATER = FREQUENCY / 7.5;
    LS = WATER / 60;
    measure_distance();
    if (distance < 10)
    {
      digitalWrite(Relay, LOW);

    }
    else
    {
      digitalWrite(Relay, HIGH);
    }
    
    delay(500);

    if (FREQUENCY >= 0)
    {
      if (isinf(FREQUENCY))
      {
       // Serial.println(0, 1);
        Serial.println("VOL.:0.00");
        Serial.println(0, 1);
        Serial.println("TOTAL: ");
        Serial.println(TOTAL);
        Serial.println("  L ");
      }
      else
      {

        TOTAL = TOTAL + LS; // to get the total liters
       EEPROM.write(0, TOTAL);
       EEPROM.read(TOTAL);
     //   Serial.println(0, 0);
      
        Serial.println(FREQUENCY);
        Serial.println("VOL.: ");
       
        Serial.println(WATER);
        Serial.println(" L/M"); 
        Serial.println(0, 1);
        Serial.println("TOTAL LITERS: ");
        Serial.println(TOTAL);
      }

      delay(500);
    }
   
  }
  void setLed()

  {
   TOTAL =  Serial.read();
    if (TOTAL >= 5)
    {
      digitalWrite(green, LOW);
      digitalWrite(yellow, LOW);
      digitalWrite(red, HIGH);
      EEPROM.write(addr, 1);
      Serial.println(EEPROM.read(addr));
           Serial.println("RED ");
    }
    if (TOTAL >= 1 && TOTAL < 5)
    {
      digitalWrite(green, LOW);
      digitalWrite(yellow, HIGH);
      digitalWrite(red, LOW);
      EEPROM.write(addr, 2);
      Serial.println(EEPROM.read(addr));
             Serial.println("yellow ");
    }
    if (TOTAL >= 0)
    {
         EEPROM.read(0);
      digitalWrite(green, HIGH);
      digitalWrite(yellow, LOW);
      digitalWrite(red, LOW);
      EEPROM.write(addr, 3);
      Serial.println(EEPROM.read(addr));
           Serial.println("green ");
    }
  }
  void measure_distance()
  {
    digitalWrite(trigger, LOW);
    delayMicroseconds(2);
    digitalWrite(trigger, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigger, LOW);
    delayMicroseconds(2);
    time = pulseIn(echo, HIGH);

    distance = time * 348 / 20000;
  }

Your code is such a mess that it's impossible to even understand what you were attempting to accomplish. All I can do is recommend that you spend some time studying the documentation of the EEPROM library: https://www.arduino.cc/en/Reference/EEPROM

Write some very simple sketches that only write data to the EEPROM, read the data from the EEPROM, and print the read value to Serial Monitor. Run those programs to make sure they work as you intend them to.

Make sure you fully understand what every single line of your sketches do.

Once you are certain you understand how to use the EEPROM library, you can return to your project and rewrite the code based on that understanding.

If you end up with specific questions along the way, feel free to come back here, write a detailed description, and we'll help you out with them.