Read Last Value of SD CARD

Hi, I am using a ATMEGA 328p with SD module and RTC DS3231 a waterflow sensor and a water flow generator. The sensor gives me the amount of liters used when its powered by the generator (when water flows). Every 7 sec, the current time and the liters are updated on the sd card. The point is that i need to read the ñast values of it and depending of the time of the last value give, the sd card must be reset. For example:

28/06/2020 17:04 --> 14 Liters

if 3 minutes have not passed:

28/06/2020 17:05 --> 14 Liters

if 3 minutes have passed:

28/06/2020 17:09 --> 0 Liters

How can I do it?

When you say, "the SD card must be reset", do you actually mean, "the cumulative Liter count must be reset to zero"?

In that case, the logic is very simple:

read the last time logged from the SD
read the RTC
if (current time - last time logged > 7 seconds) { literCount = 0 }

And how I can't read the last value that was writen? The device would be powered every (aprox) +- 5 hours. How can I say. Read the last value. If it's posssible how I separate the number to the time and the Liters?:


18:06:33 , 17 Liters

This to:

17 liters

Maybe post your code and we can help?

Maybe post your code and we can help?

void(* resetFunc) (void) = 0;
byte sensorInterrupt = 0;  
byte sensorPin       = 2;
float calibrationFactor = 4;
volatile byte pulseCount; 
float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitres;
unsigned long oldTime;

#include <SD.h>
#include <SPI.h>
#include <DS3231.h>
File myFile;
DS3231  rtc(SDA, SCL);
int pinCS = 53;

void setup() {

  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);
  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;
  attachInterrupt(digitalPinToInterrupt(sensorPin), pulseCounter , FALLING); 

  pinMode(pinCS, OUTPUT);
  if (SD.begin())
    Serial.println("SD card is ready to use.");
  } else
    Serial.println("SD card initialization failed");


void loop() {

  Serial.println(" mL");
  myFile ="test.txt", FILE_WRITE);
  if (myFile) {    
    myFile.close(); // close the file
  // if the file didn't open, print an error:
  else {
    Serial.println("error opening test.txt");

delay (2000);

if((millis() - oldTime) > 300)    { 
    flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
    oldTime = millis();    
    flowMilliLitres = (flowRate / 60)*2000;   
    totalMilliLitres += flowMilliLitres;      
    unsigned int frac;
    attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
    pulseCount = 0;   

void pulseCounter(){

Then read forward to the end of the next-to-last line. Then read the last line.