   
     unsigned long currentMillis = millis();
   
-    if(currentMillis - previousMillis >= logInterval * 1000 && logData) {
+    if (currentMillis - previousMillis >= logInterval * 1000 && logData) {
         previousMillis = currentMillis;
       
         readDHT11();
+    }
+    
+    if (travelTimeSet && currentMillis - previousLogMillis >= logDelay) {
+        setLogInterval();
     }
 }
 


// Variables to use for the interval
unsigned long previousMillis = 0;
unsigned long logDelay;                           // Log delay in milliseconds
long logInterval = 0;                            // Log interval in milliseconds

// Variables
dht11 DHT11;
EDB db(&writer, &reader);
long travelTime; // Total travel time in s
int maxLogs = 252;
String msg;
boolean logData = false;


void clearData() {
    db.clear();
    for ( int i = 0 ; i < EEPROM.length() ; i++ ) EEPROM.write(i, 0);
}

void setTravelTime() {
    Serial.println("set travel time in sec");
    while (Serial.available() == 0) { }
    travelTime = Serial.parseInt();
    
    while (Serial.available() ==0) { }
    logDelay = Serial.parseInt();
    previousLogMillis = millis();
    travelTimeSet = true;
    
    EEPROMWritelong(3, previousLogMillis);
    EEPROM.write(7,travelTimeSet);
    EEPROMWriteInt(8,logDelay);
    EEPROMWritelong(10, travelTime);
}

void setLogInterval() {
    logInterval = travelTime / maxLogs;
    logData = true;
    EEPROMWriteInt(0,logInterval);
    EEPROM.write(2,logData);
}

void readDHT11() {
