Arduino Uno project: millis() not incrementing properly in my saved data

Hello everyone, I’m working on a project where two sensors (a radar-based level sensor and a laser distance sensor) are read via serial communication, and the measurements are logged to a micro SD card. The original sketch works fine: both sensors provide values, the data is logged correctly to the card, and the Serial Monitor shows the expected output. The issue is with the millis() values in my log. They don’t increment the way I need them to. They often appear almost constant, so I cannot use them reliably for time-based logging intervals (e.g. one entry every 3 seconds). I tried to fix this by modifying the code (with the help of AI), but after those changes the program stopped working properly: • sometimes the Serial Monitor output freezes, • sometimes the SD logging stops completely, • and overall the behavior became unstable. Note: The manufacturer’s LiquidLevelDetection library had to be modified so that two serial devices could work in the same sketch (don’t know if that could be related ). The original code still compiles and runs, but I don’t know how to correctly integrate millis()-based timing without breaking it. Could someone please review this and suggest how to structure the code so that millis() increments properly and logging happens at regular intervals, without blocking other parts of the loop? Thanks in advance!
3 Replies
Dgr897er
Dgr897erOP2w ago
You can check out the millis in the data for a better understanding of the problem.
pseud0
pseud02w ago
I don't see an obvious error in the code. When you do just
void setup() {
Serial.begin(9600);
}

void loop() {
Serial.println(millis());
delay(500);
}
void setup() {
Serial.begin(9600);
}

void loop() {
Serial.println(millis());
delay(500);
}
It prints the values normally?
Dgr897er
Dgr897erOP2w ago
Yes it does..

Did you find this page helpful?