Arduino Questions and Answers – Time Functions

This set of Arduino Multiple Choice Questions & Answers (MCQs) focuses on “Time Functions”.

1. What is the unit of delay in the code given below?

  1. void setup() {
  2.     Serial.begin(9600);
  3. }
  4. void loop() {
  5.     digitalWrite(10,HIGH);
  6.     delay(1000);
  7.     digitalWrite(10,LOW);
  8.     delay(1000);
  9. }

a) Milliseconds
b) Microseconds
c) Seconds
d) Minutes
View Answer

Answer: a
Explanation: The delay() function is used to delay the execution of a command by a certain specified amount of time. This function takes only one argument and that is the time in milliseconds. In the code above we are giving a delay of 1000 ms or 1 s after each digitalWrite() command is executed.
advertisement
advertisement

2. What is the return type of the micros() function?
a) Signed Long
b) Signed Int
c) Unsigned Long
d) Unsigned Int
View Answer

Answer: c
Explanation: The micros() function gives the up-time or the time since the Arduino started to run the program. The return type here is unsigned long, which means basically a number of the long datatype without any plus or minus signs. This number denotes the up-time in microseconds.

3. What is the return type of the millis() function?
a) Signed Long
b) Unsigned Long
c) Signed Float
d) Unsigned Int
View Answer

Answer: b
Explanation: The millis() function gives the up-time or the time since the Arduino started to run the program. The return type here is unsigned long, which means basically a number of the long datatype without any plus or minus signs. This number denotes the up time in milliseconds.
Note: Join free Sanfoundry classes at Telegram or Youtube

4. What is the return type of the delayMicroseconds() function?
a) Unsigned Int
b) Signed Int
c) Unsigned Long
d) Signed Long
View Answer

Answer: a
Explanation: The delayMicroseconds() function delays or pauses program execution for a certain amount of time. The return type here is unsigned int, which means basically a number of the int datatype without any plus or minus signs. This number here is denoted by microseconds.

5. What is the time period of the output signal of the program given below?

advertisement
  1. int pin=10;
  2. void setup() {
  3.     Serial.begin(9600);
  4.     pinMode(pin,OUTPUT);
  5. }
  6. void loop() {
  7.     digitalWrite(pin,HIGH);
  8.     delay(10);
  9.     digitalWrite(pin,LOW);
  10.     delay(10);
  11. }

a) 20 Microseconds
b) 100 Milliseconds
c) 10 Milliseconds
d) 0.02 Seconds
View Answer

Answer: d
Explanation: The program given above uses the delay() function to create a delay of a specified amount of time in milliseconds between each HIGH or LOW signal. Here this delay function is used to create a pulse train with a time period of 20 Milliseconds (10 Milliseconds for the completion of each half of one wave) or 0.02 Seconds.
advertisement

6. What is the purpose of the program given below?

  1. int ledState = LOW;
  2. int ledPin = 13;
  3. unsigned long previousMillis = 0;
  4. const long interval = 1000;           
  5. void setup() {
  6.     pinMode(ledPin, OUTPUT);
  7. }
  8. void loop() {
  9.     unsigned long currentMillis = millis();
  10.     if (currentMillis - previousMillis >= interval) {
  11.         previousMillis = currentMillis;
  12.         if (ledState == LOW) {
  13.             ledState = HIGH;
  14.         } else {
  15.             ledState = LOW;
  16.         }
  17.         digitalWrite(ledPin, ledState);
  18.     }
  19. }

a) To create a delay in blink without using the delay() function
b) To create a delay in blink with the delay() function
c) To find the up-time
d) To find the down-time
View Answer

Answer: a
Explanation: The program above blinks the onboard LED if executed on the Arduino Uno at a delay of 1 Second without using the help of the delay function. It uses the millis() function to calculate the delay to give. The millis() function gives the up-time of the program in milliseconds.

7. What is the resolution of the micros() function on the Arduino Nano?
a) 2 Microseconds
b) 3 Microseconds
c) 4 Microseconds
d) 5 Microseconds
View Answer

Answer: c
Explanation: The micros() function gives the up-time of the Arduino program in microseconds. This function has a resolution, i.e. the intervals in which it gives an output. This resolution depends on the Frequency of the specific Arduino Board that its running on. On the Arduino Duemilanove it’s resolution is 4 Microseconds.

8. What is the overflow point of the millis() function?
a) 10 day
b) 30 days
c) 50 days
d) 70 days
View Answer

Answer: c
Explanation: The millis() function gives the up-time or the time since the Arduino started to run the program. The overflow point of this function is 50 days. This means that the value returned by this function will return to 0 after 50 days.

9. What is the resolution of the micros() function on the Arduino LilyPad?
a) 2 Microseconds
b) 4 Microseconds
c) 6 Microseconds
d) 8 Microseconds
View Answer

Answer: d
Explanation: The micros() function gives the up-time of the Arduino program in microseconds. This function has a resolution, i.e. the intervals in which it gives an output. This resolution depends on the Frequency of the specific Arduino Board that its running on. On the Arduino LilyPad it’s resolution is 8 Microseconds.

10. Can the Arduino read sensor data from a pin while the delay() function is in effect?
a) Yes
b) No
View Answer

Answer: b
Explanation: The delay() function is used to suspend operations for a specified amount of time. This is really handy for certain operations like viewing data on the Serial Monitor. However, this has a very serious drawback; it suspends ALL operations during this time, i.e. no mathematical calculations, no sensor data inputs, etc. for the time it is in effect.

Sanfoundry Global Education & Learning Series – Arduino.

To practice all areas of Arduino, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.