Menu
CoddyTech

The millis() Clock

Part of the Timing Without Delay section of Coddy's Arduino journey. Lesson 1 of 18.

The board has a clock inside it. millis() returns how many milliseconds have passed since the board started: 0 at power-on, 1000 after one second, 60000 after a minute.

You never start or reset this clock. It counts on its own, even while your sketch is inside delay(), and you can read it at any moment:

Serial.println(millis());   // prints the time, in ms

Until now, delay() was the only way to time something, and it stops the whole sketch while it waits. Reading the clock stops nothing: the sketch keeps running and checks how much time has passed.

challenge icon

Challenge

Easy

Print the board's clock once a second:

  • in loop(), print millis() with Serial.println()
  • keep the delay(1000) after it

Press Run and watch the numbers in the Serial monitor, then Check.

Try it yourself

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

void loop() {
  // print the time since the board started here

  delay(1000);
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Timing Without Delay

Practice on your own: Arduino playground