Arduino Multiple Choice Questions on “Setting Pin Mode”.
1. What type of signal does the analogWrite() method generate when a pin is set to OUTPUT mode?
a) Digital Signal
b) Pulse Code Modulated Signal
c) Pulse amplitude Modulated Signal
d) Pulse Width Modulated Signal
Answer: d
Calrification: The analogWrite() method in Arduino is used to generate a Pulse Width Modulated Signal since the digital circuitry in the Arduino does not allow for generation of true continuous analog waves. So therefore, the PWM Signal is used.
2. What is the output of “pin1” if “pin2” is sent “1011” where 1 is 5V and 0 is 0V?
-
int pin1 = 12;
-
int pin2 = 11;
-
void setup() { -
pinMode(pin1, OUTPUT);
-
pinMode(pin2, INPUT);
-
Serial.begin(9600);
-
}
-
void loop() { -
if(digitalRead(pin2)==1) { -
digitalWrite(pin1,LOW);
-
}
-
else if(digitalRead(pin2)==0) { -
digitalWrite(pin1,HIGH);
-
}
-
}
a) 0100
b) 1011
c) 1110
d) 1111
Answer: a
Calrification: Here when pin2 receives a digital 1 we set pin1 as “LOW” or a digital 0, and conversely when pin2 receives a digital 0 we set pin1 as “HIGH” or a digital 1. Therefore, effectively generating the inverse of the wave that we received as input.
3. What are the two modes that the pinMode() method sets for a particular pin?
a) DIGITAL and ANALOG
b) INPUT and OUTPUT
c) TX and RX
d) READ and WRITE
Answer: b
Calrification: The pinMode() method determines whether the pin number given in the code is to be used as an input pin wherein it can read voltage from an external circuit or for setting a particular voltage at the pin output to be plugged to an external circuit.
4. What are the voltage levels that can be detected if a pin is set to OUTPUT using the pinMode() method and the analogRead() method is used, in the Arduino Uno?
a) 0 and 5V
b) 0 to 5.1V
c) 0 to 5V
d) 0 to 10V
Answer: c
Calrification: The Arduino UNO has an operating voltage ranging from 0V to 5V. Hence the Serial monitor will record an output ranging from 0 to 1023. This is done by mapping the value of the voltage to an integer set that has a range of 0 to 1023.
5. What will the code given below give as output if a 5V line is connected as input to pin 11?
-
int pin_1=11;
-
void setup() { -
pinMode(pin_1, INPUT);
-
Serial.begin(9600);
-
}
-
void loop() { -
int reading=analogRead(pin_1);
-
Serial.println(reading);
-
}
a) 0
b) 102
c) Null
d) 1023
Answer: d
Calrification: The voltage that is put across the pin 11 goes into the analog to digital convertor onboard the Arduino and then it is converted into an integer value that ranges from 0 to 1023. This is done by “mapping” the voltage value read, to a range of integers from 0 to 1023.
6. What is the output at the serial monitor of the code below if pin 11 is given the following signal?
-
int pin1=11;
-
void setup() { -
pinMode(pin1, INPUT);
-
Serial.begin(9600);
-
}
-
void loop() { -
int ip=analogRead(pin1);
-
if(ip>0) { -
Serial.println(“H”);
-
}
-
else { -
Serial.println(“O”);
-
}
-
}
a) 0H0H0
b) OHHO
c) OHHH
d) HOHOO
Answer: a
Calrification: The input signal given is of the form 01010. Therefore, according to the code, if ip is greater than 0 then ‘H’ is printed and if ip is less than 0 then ‘O’ is printed. So now we get the output as OHOHO. This is printed to the Serial Monitor with a baud rate of 9600.
7. How many errors are present in the code given below?
-
int pin1=12;
-
void setup() { -
pinmode(pin1, IN);
-
Serial.begin(9600);
-
}
-
void loop() { -
int value=analogRead(pin1);
-
Serial.println(value+10);
-
}
a) 1
b) 2
c) 3
d) 4
