Consider the following Arduino code running on a board with an LED connected to pin 13. What will be the state of the LED after running this code?
void setup() {
pinMode(13, INPUT);
digitalWrite(13, HIGH);
}
void loop() {}Remember that setting a pin as INPUT disables the output driver, so digitalWrite does not turn the LED on.
When a pin is set as INPUT, calling digitalWrite sets the internal pull-up resistor but does not drive the pin HIGH to power an LED. Therefore, the LED remains OFF.
Given this Arduino code, what will be the voltage level on pin 8?
void setup() {
pinMode(8, OUTPUT);
digitalWrite(8, LOW);
}
void loop() {}Think about what OUTPUT mode and LOW signal mean for voltage.
Setting pinMode to OUTPUT and digitalWrite to LOW sets the pin voltage to 0V, turning it off.
Analyze this Arduino code. What will be the voltage level on pin 7 after setup?
void setup() {
pinMode(7, INPUT_PULLUP);
digitalWrite(7, LOW);
}
void loop() {}INPUT_PULLUP mode enables an internal resistor. What does digitalWrite do in this mode?
pinMode(7, INPUT_PULLUP) enables the internal pull-up resistor, but digitalWrite(7, LOW) disables it, leaving the pin in high-impedance (floating) state with no defined voltage.
What happens when you run this Arduino code?
void setup() {
pinMode(20, OUTPUT);
}
void loop() {}Check the pin numbers available on common Arduino boards like Uno.
Arduino Uno supports digital pins 0-19 (A0-A5 as 14-19). pinMode(20, OUTPUT) compiles and runs without error, but has no effect since pin 20 does not exist.
Which statement best describes the relationship between pinMode() settings and the behavior of digitalWrite() and digitalRead() functions?
Consider what happens when a pin is INPUT vs OUTPUT and how digitalWrite and digitalRead behave.
When pinMode is INPUT, digitalWrite can enable the internal pull-up resistor by writing HIGH, but does not drive the pin. digitalRead reads the voltage level. When OUTPUT, digitalWrite sets voltage, and digitalRead reads the output state.
