Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does the micros() function in Arduino return?
It returns the number of microseconds since the Arduino board began running the current program.
Click to reveal answer
beginner
What is the data type of the value returned by micros()?
It returns an unsigned long integer representing microseconds.
Click to reveal answer
intermediate
How often does the micros() value overflow (reset to zero) on a 16 MHz Arduino board?
It overflows approximately every 70 minutes because unsigned long maxes out at about 4,294,967,295 microseconds.
Click to reveal answer
beginner
Why is micros() preferred over millis() for measuring very short time intervals?
micros() gives microsecond precision, which is 1000 times more precise than millis() that measures milliseconds.
Click to reveal answer
beginner
Can micros() be used for timing delays shorter than 1 millisecond?
Yes, because it measures time in microseconds, it can measure and help create delays shorter than 1 millisecond.
Click to reveal answer
What unit does micros() use to measure time?
ASeconds
BMilliseconds
CNanoseconds
DMicroseconds
✗ Incorrect
micros() returns time in microseconds since the program started.
What is the return type of micros() in Arduino?
Aunsigned long
Bint
Cfloat
Dlong
✗ Incorrect
micros() returns an unsigned long value.
How long does it take for micros() to overflow on a 16 MHz Arduino?
AAbout 70 minutes
BAbout 24 hours
CAbout 1 hour
DAbout 70 seconds
✗ Incorrect
The unsigned long max value causes overflow roughly every 70 minutes.
Which function is better for measuring very short time intervals?
A<code>millis()</code>
B<code>micros()</code>
C<code>delay()</code>
D<code>Serial.print()</code>
✗ Incorrect
micros() provides microsecond precision, better for short intervals.
If you want to measure 500 microseconds delay, which function helps you do that?
A<code>delay(500)</code>
B<code>delayMicroseconds(500)</code>
C<code>micros()</code>
D<code>millis()</code>
✗ Incorrect
micros() can be used to measure short intervals like 500 microseconds by recording timestamps before and after the event.
Explain how micros() works and why it is useful in Arduino programming.
Think about timing very fast events.
You got /4 concepts.
Describe what happens when the value returned by micros() overflows and how to handle it.
Consider how to measure elapsed time safely.
You got /3 concepts.
Practice
(1/5)
1. What does the Arduino function micros() return?
easy
A. The number of microseconds since the program started
B. The number of milliseconds since the program started
C. The current time in seconds
D. The number of seconds since the last reset
Solution
Step 1: Understand the purpose of micros()
The micros() function returns the time in microseconds since the Arduino program began running.
Step 2: Compare options with the function's behavior
Only The number of microseconds since the program started correctly states it returns microseconds since start. Others mention milliseconds or seconds, which are incorrect.
Final Answer:
The number of microseconds since the program started -> Option A
Quick Check:
micros() = microseconds since start [OK]
Hint: Remember micros() counts microseconds from program start [OK]
Common Mistakes:
Confusing micros() with millis()
Thinking it returns seconds
Assuming it resets every second
2. Which of the following is the correct way to store the current microsecond count in a variable?
easy
A. unsigned long time = micros();
B. int time = micros();
C. float time = micros();
D. long time = micros();
Solution
Step 1: Identify the data type returned by micros()
The micros() function returns an unsigned long integer representing microseconds.
Step 2: Match the correct variable type to store the value
Only unsigned long can hold the large values from micros() without overflow or sign issues.
Final Answer:
unsigned long time = micros(); -> Option A
Quick Check:
Use unsigned long for micros() values [OK]
Hint: Use unsigned long to store micros() values safely [OK]
Common Mistakes:
Using int which is too small
Using float which loses precision
Using signed long which can cause negative values
3. What will be the output of this Arduino code snippet?
unsigned long start = micros();
// some delay here
unsigned long end = micros();
unsigned long diff = end - start;
Serial.println(diff);
Assuming the delay is about 500 microseconds.
medium
A. Always zero
B. A number close to 500000
C. A negative number
D. A number close to 500
Solution
Step 1: Understand the timing measurement
The code measures the time difference in microseconds between two calls to micros().
Step 2: Interpret the delay and difference calculation
If the delay is about 500 microseconds, the difference diff will be close to 500, printed as a positive number.
Final Answer:
A number close to 500 -> Option D
Quick Check:
diff = end - start ≈ 500 [OK]
Hint: Subtract micros() values to get elapsed microseconds [OK]
Common Mistakes:
Expecting milliseconds instead of microseconds
Thinking difference can be negative
Confusing delay units
4. Identify the error in this Arduino code snippet:
unsigned long start = micros();
// some code
unsigned long end = micros();
int elapsed = end - start;
Serial.println(elapsed);
medium
A. micros() cannot be assigned to unsigned long
B. Using int for elapsed can cause overflow
C. Serial.println cannot print integers
D. Subtracting micros() values is invalid
Solution
Step 1: Check variable types for time difference
The difference between two micros() values can be very large, exceeding the range of int.
Step 2: Understand overflow risk
Using int (usually 16-bit) can cause overflow and incorrect negative values. It should be unsigned long.
Final Answer:
Using int for elapsed can cause overflow -> Option B
Quick Check:
Use unsigned long for elapsed time to avoid overflow [OK]
Hint: Use unsigned long, not int, for time differences [OK]
Common Mistakes:
Using int instead of unsigned long
Thinking micros() returns signed values
Assuming Serial.println can't print integers
5. You want to measure how long a button is pressed in microseconds using micros(). Which approach correctly handles the timing even if the program runs longer than 70 minutes (when micros() overflows)?
hard
A. Ignore overflow because it never affects timing
B. Reset the Arduino every 60 minutes to avoid overflow
C. Store start time, then calculate elapsed as micros() - start using unsigned long subtraction
D. Use millis() instead because it never overflows
Solution
Step 1: Understand micros() overflow behavior
micros() overflows roughly every 70 minutes, wrapping back to zero.
Step 2: Use unsigned long subtraction to handle overflow
Unsigned subtraction correctly calculates elapsed time even if overflow happens, so micros() - start works safely.
Final Answer:
Store start time, then calculate elapsed as micros() - start using unsigned long subtraction -> Option C