millis or micros has a time delay phenomenon?

There is nothing in the loop except only time function.
At first, it can be seen to work constantly on time.
But, it gets more and more time to work.
Why is this happening?

You can refer to the pictures I attached.
(figure 1. code, figure 2. The excel picture shows how long the interval has occurred.)

What do you expect? You are outputting 960 characters per second. If you output two characters before the decimal point, the decimal point, two characters after the decimal point, the carriage return and the line feed then you are outputting 7 characters per line. This takes over 7 milliseconds once the internal buffer is filled.

Why are you measuring in microseconds when your program is taking nearly 10 milliseconds?

In the future, please be aware that most people in this forum hate pictures of code. The code should be posted inline using code tags.

To post code and/or error messages:

  1. Use CTRL-T in the Arduino IDE to autoformat your complete code.
  2. Paste the complete autoformatted code between code tags (the </> button)
    so that we can easily see and deal with your code.
  3. Paste the complete error message between code tags (the </> button)
    so that we can easily see and deal with your messages.
  4. If you already posted without code tags, you may add the code tags by
    ~~ editing your post.~~ Do not change your existing posts in any other way.
    You may make additional posts as needed.
  5. Please provide links to any libraries that are used
    (look for statements in your code that look like #include ). Many libraries
    are named the same but have different contents.

Before posting again, you should read the three locked topics at the top of the Programming Questions forum, and any links to which these posts point.

If your project involves wiring, please provide a schematic and/or a wiring diagram and/or a clear photograph of the wiring.

Good Luck!

You are stuffing characters into the serial buffer faster than they can be sent. Once the buffer is full, each character being put into the buffer will have to wait for a character to be sent.

It takes about a millisecond to send one character at 9600 baud (10 bits: 1 start, 8 data, 1 stop). When you are sending about six characters per line the delay is 6.24 milliseconds. When you are sending about seven characters each time through loop() it makes sense that your timer will have intervals of 7.28 milliseconds. It looks like it takes 1.04 milliseconds per character.

Adding to the helpful comments above- careful use of micros() should be studied; see Nick's reply.

I have no intention of trying to read code that is posted as a picture. Post your .ino file.


I save a variable to an array and when the array is full, stop the test and print the results.
reset and repeat.

unsigned long loopTime [50];  // An Array To hold the loop test times
byte loopNum;  // Index for the Array
unsigned long oldLoopTime; 
int delayTime = 5;

void setup() {
  Serial.begin (9600);

void loop()
  loopTime [loopNum] = micros();  // Record the time
  loopNum++;  // Increment the Index
  if (loopNum >= 49)  // when the array is full
    loopNum = 0;  // reset the Index
    testResults();  // call a function to print the results
  delay (delayTime);  // slow things down a little. We will subract this from the result

void testResults()  // do the math and print the results
  for (byte i = 0; i <= 49; i++)
    unsigned long result = (loopTime[i]- oldLoopTime)-(delayTime*1000);
    oldLoopTime = loopTime [i];

Also, 9600 baud is kind of slow. You might want to try changing your program (and setting your Serial monitor) to use a higher baud rate.