how to saving flow water meter reading into EEPROM

please i need help to solve my problem with saving value of flow water sensor to eeprom which is back to 0 after powered off ,

Which board are you using?

arduino mega 2560

Please post your full sketch. If possible you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help. If the sketch is longer than the forum will allow then it’s ok to add it as an attachment. Don’t put your code in some external file service like dropbox, etc. We shouldn’t need to go to an external website just to help you. I do feel it’s reasonable to post a link to code hosted on GitHub or similar code hosting sites since that’s an platform specifically designed for this sort of thing

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you’re using the Arduino Web Editor then you will not have access to this useful tool. I recommend using the standard Arduino IDE instead.

When your code requires a library that’s not included with the Arduino IDE please post a link (using the chain links icon on the toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

this my code

My Code.txt (2.58 KB)

That code won't even compile. The reason why would be more obvious if you had done an Auto Format as I requested.

I don't know how you know it's back to 0, since you never output the value read from the EEPROM in the code.

I suspect this code doesn't do what you think it does:

void water_daily(){
 if (totalMilliLitres > 0)
  eeprom_daily = totalMilliLitres /1000;
 eeprom_daily != totalMilliLitres /1000;
 Serial.println ("water_daily");


Again, Auto Format makes things more clear:

void water_daily() {
  if (totalMilliLitres > 0)
    eeprom_daily = totalMilliLitres / 1000;
    eeprom_daily != totalMilliLitres / 1000;
  Serial.println ("water_daily");
  EEPROM.put(13, eeprom_daily);


This line:

   eeprom_daily != totalMilliLitres / 1000;

does nothing.

i change the code to void water_daily(){ if (totalMilliLitres > 0) { eeprom_daily = totalMilliLitres /1000;

Serial.println ("water_daily"); EEPROM.put(13,eeprom_daily);


but same issue

How do you know? Where is the code that tells you what value is saved in the EEPROM?

this code

void init_eeprom() { Serial.print("Reset Setting ..."); EEPROM.write(0,0xFF); //check EEPROM.put(1,0); Serial.println(" Done"); } void read_init_eeprom() { Serial.print("Read Setting ...");

//eeprom_daily =(int) EEPROM.get(13); EEPROM.get(1, eeprom_daily);

Serial.println(" Done"); }

Where is the code that tells you what value is saved in the EEPROM?
(for if you still don’t get it: eeprom_daily doesn’t get printed).

Remember: EEPROM has limited write cycles - it’s rated at 100,000 write cycles only, so don’t write your new values too often or you will break it and it doesn’t store anything any more. Or at least, the cell(s) of EEPROM used.

i am not got your point which code should be add

This line

EEPROM.get(1, eeprom_daily);

sets the variable eeprom_daily to the value saved at EEPROM address 1.

If you want to know what the value of eeprom_daily is you need to ouput that to the Serial Monitor:


the value printed on Serial.println(eeprom_daily); based on eeprom_daily != totalMilliLitres / 1000;

for example if totalMilliLitres 3000 Serial.println(eeprom_daily); will be 3 liters

You’re going to need to make a better effort at communicating. I guess English is not your first language but that just means you need to be very thorough in explaining what you mean. If you use lots of words then even if a lot of it isn’t clear to us, enough will be that we will get the meaning. If you use very few words then chances are we will have no clue what you’re trying to say and the whole conversation will just be a waste of time for everyone.

What behavior are you expecting?

What behavior are you seeing that doesn’t match what you expected?

thanks for your time I think in briefly my problem in save last value counter that passed from water flow sensor