micros()

Description

Returns the number of microseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 70 minutes. On 16 MHz Arduino boards (e.g. Duemilanove and Nano), this function has a resolution of four microseconds (i.e. the value returned is always a multiple of four). On 8 MHz Arduino boards (e.g. the LilyPad), this function has a resolution of eight microseconds.

Syntax

time_us = micros()

Parameter Values

  • None

Return Values

  • Returns the number of microseconds since the Arduino board began running the current program. Data type: unsigned long.

Example Code

The code returns the number of microseconds since the Arduino board began.

unsigned long time_us; void setup() { Serial.begin(9600); } void loop() { Serial.print("Time: "); time_us = micros(); Serial.println(time_us); //prints time since program started delay(1000); // wait a second so as not to send massive amounts of data }

※ NOTES AND WARNINGS:

There are 1,000 microseconds in a millisecond and 1,000,000 microseconds in a second.

See Also

Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.