Arduino Questions and Answers – Advanced Input Output

This set of Arduino Multiple Choice Questions & Answers (MCQs) focuses on “Advanced Input Output”.

1. What is the maximum number of arguments that the pulseIn() function accepts?
a) 1
b) 2
c) 3
d) 4
View Answer

Answer: c
Explanation: The pulseIn() function is used to determine the length of a pulse supplied to a digital pin. It generally accepts two arguments; the pin number, and the state, i.e. HIGH or LOW. If the state is given as HIGH, then it will wait for the pin to go HIGH and then start counting the time till the pin returns back to LOW. Here the length of the pulse is given by the function in microseconds.

2. What is the purpose of the following code?

  1. int pin1=10;
  2. void setup() {
  3.     pinMode(pin1,OUTPUT);
  4.     Serial.begin(9600);
  5. }
  6. void loop() {
  7.     Serial.println(pulseInLong(pin1,HIGH));
  8. }

a) To count the number of pulses
b) To count the voltage fluctuations in pin1
c) To count the duration of a single pulse
d) To count the total number of pulses supplied
View Answer

Answer: c
Explanation: The pulseInLong() function is similar to the pulseIn() function wherein it is used to count the duration of a pulse. However the only difference is that the pulseIn() function is not very accurate when counting pulses of very large durations, so we used the pulseInLong() function to do the job.
advertisement
advertisement

3. What is the purpose of the tone() function?
a) To generate a sine wave
b) To generate a cosine wave
c) To generate a stable voltage level
d) To generate a square wave
View Answer

Answer: d
Explanation: The tone() function is used to generate a square wave of 50% duty cycle. It accepts a maximum of 3 arguments; the pin number, the frequency, and the duration of the wave. If no duration is specified then the wave is continued to be generated until the noTone() function is invoked within the code.

4. What is the use of the MSBFIRST argument in the shiftIn() function?
a) To denote the least significant bit
b) To denote the maximum number of Bits
c) To denote the most significant bit
d) To denote the minimum number of bits
View Answer

Answer: c
Explanation: The shiftIn() function shifts in one byte of a binary number bit by bit starting from either the most significant bit or the least significant bit. Now after each bit is pulled, the clock pin is turned to HIGH until the next one at which point the clock pin is turned down to LOW again. Now the MSBFIRST argument denotes that the byte of data be read from left to right.

5. What is the output of the code given below?

advertisement
  1. int pin1=10;
  2. void setup() {
  3.     pinMode(pin1,OUTPUT);
  4.     Serial.begin(9600);
  5. }
  6. void loop() {
  7.     tone(pin1,400);
  8. }

a) Finite Square Wave
b) Infinite Sine Wave
c) Infinite Square Wave
d) Infinite Cosine Wave
View Answer

Answer: c
Explanation: The code above sets pin1 as the output pin and generates an infinite square wave of frequency 400Hz at pin1. This is done using the tone() function. Here, since no timeout is mentioned the wave will be generated continuously until the Arduino’s power supply is turned off, or another code is compiled and uploaded to it.
advertisement

6. Can the tone() and noTone() functions be used for digital communications?
a) No, they cannot be used
b) Yes, they can be used but only on certain Arduino Boards
c) Yes, they can be used for all digital pins and Arduino Boards
d) Yes, they can be used but only for certain pins
View Answer

Answer: c
Explanation: The tone() function generates a square wave at a constant 50% duty cycle and a specified frequency. So, if a communication is to be established between two devices on this basis, the receiver only has to record the different frequencies of the square waves and map them to a certain set of finite predefined integers in order to obtain some meaningful data from the transmission.

7. How many tone() functions can be invoked to run simultaneously on an Arduino Board?
a) As many pins are present
b) Infinite number
c) Only one
d) Depending on the number of timers present
View Answer

Answer: c
Explanation: The tone() function uses the Arduino’s built in timer to generate the square wave of the necessary frequency. So the number of tone() invokes a board can handle depends upon the number of timers present on that board.

8. How many arguments does the shiftOut() function require?
a) 1
b) 2
c) 3
d) 4
View Answer

Answer: d
Explanation: The shiftOut() function requires 4 arguments; the pin number to which the bit of data is to be sent, the toggle-pin which is to be turned HIGH or LOW once the data is done transferring, the order in which the bits are to be read (MSBFIRST or LSBFIRST), and the actual data who’s bits are to be shifted out.

9. What is the return type for the shiftOut() function?
a) double
b) null
c) long
d) int
View Answer

Answer: b
Explanation: The shiftOut() function takes a byte of data as input and shifts the data bit by bit out to an output pin by either moving from left to right or vice versa. So, it does provide us an output, however that output is directly updated to the pin, and not sent back as a return value.

10. What is the return type of the pulseIn() function?
a) null
b) signed byte
c) unsigned long
d) unsigned int
View Answer

Answer: c
Explanation: The job of the pulseIn() function is to calculate the time difference (in microseconds) between two digital pulses. It gives the value as output in the form of an unsigned long variable. This is done so as to improve the accuracy of the function when measuring the time gap.

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.