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 digitalRead() function do in Arduino?
It reads the value from a specified digital pin, returning HIGH if the voltage is high (usually 5V) or LOW if the voltage is low (0V).
Click to reveal answer
beginner
How do you use digitalRead() to check if a button is pressed?
You connect the button to a digital pin and use digitalRead(pin). If it returns LOW or HIGH depending on your wiring, you know if the button is pressed or not.
Click to reveal answer
beginner
Why should you use pinMode(pin, INPUT) before using digitalRead()?
Setting the pin mode to INPUT tells Arduino to prepare the pin to read signals from sensors or buttons, ensuring digitalRead() works correctly.
Click to reveal answer
beginner
What values can digitalRead() return?
It returns either HIGH or LOW, representing the voltage level on the pin.
Click to reveal answer
beginner
If digitalRead(7) returns LOW, what does it mean?
It means the voltage on digital pin 7 is low (close to 0 volts), which often means a button connected to that pin is pressed or the circuit is connected to ground.
Click to reveal answer
What must you do before using digitalRead() on a pin?
ASet the pin mode to INPUT using <code>pinMode(pin, INPUT)</code>
BSet the pin mode to OUTPUT using <code>pinMode(pin, OUTPUT)</code>
CCall <code>digitalWrite(pin, HIGH)</code>
DNothing, just call <code>digitalRead()</code>
✗ Incorrect
You must set the pin as INPUT to read signals correctly with digitalRead().
What does digitalRead() return when the pin voltage is high?
AHIGH
BLOW
C1
D0
✗ Incorrect
digitalRead() returns HIGH when the voltage is high (usually 5V).
Which of these is a valid use of digitalRead()?
AChanging the baud rate
BSetting a pin to HIGH
CReading a sensor connected to a digital pin
DWriting a value to an LED
✗ Incorrect
digitalRead() reads the state of a digital pin, useful for sensors or buttons.
If a button is connected to pin 2 and digitalRead(2) returns LOW, what might that mean?
AButton is not pressed
BButton is pressed
CPin is set as OUTPUT
DPin is disconnected
✗ Incorrect
Often, buttons connect the pin to ground when pressed, so digitalRead() returns LOW.
What type of signal does digitalRead() read?
ASerial data
BAnalog voltage levels
CPWM signals
DDigital HIGH or LOW signals
✗ Incorrect
digitalRead() reads digital signals that are either HIGH or LOW.
Explain how to use digitalRead() to detect if a button is pressed.
Think about how the button connects the pin to ground or voltage.
You got /4 concepts.
What are the possible return values of digitalRead() and what do they mean?
Consider the two states of a digital signal.
You got /3 concepts.
Practice
(1/5)
1. What does the digitalRead() function do in Arduino?
easy
A. Sets a digital pin to HIGH or LOW
B. Reads the voltage level (HIGH or LOW) from a digital input pin
C. Configures a pin as an output
D. Reads analog voltage from a pin
Solution
Step 1: Understand the purpose of digitalRead()
The function digitalRead() checks the voltage level on a digital pin and returns HIGH or LOW.
Step 2: Differentiate from other functions
Unlike digitalWrite() which sets pin output, digitalRead() only reads input state.
Final Answer:
Reads the voltage level (HIGH or LOW) from a digital input pin -> Option B
Quick Check:
digitalRead() reads pin state [OK]
Hint: digitalRead() always reads input pin state [OK]
Common Mistakes:
Confusing digitalRead() with digitalWrite()
Thinking digitalRead() sets pin output
Mixing digitalRead() with analogRead()
2. Which of the following is the correct syntax to read a digital pin 7 in Arduino?
easy
A. digitalReadPin(7);
B. digitalRead = 7;
C. digitalRead(7);
D. readDigital(7);
Solution
Step 1: Recall the correct function syntax
The correct function call is digitalRead(pinNumber); where pinNumber is the pin to read.
Step 2: Check each option
Only digitalRead(7); matches the correct syntax digitalRead(7); others are invalid function calls or assignments.
Final Answer:
digitalRead(7); -> Option C
Quick Check:
Correct function call [OK]
Hint: digitalRead(pinNumber) reads pin state correctly [OK]
Common Mistakes:
Using assignment instead of function call
Wrong function name like readDigital()
Adding extra words like digitalReadPin()
3. What will be the output on the Serial Monitor if the button connected to pin 2 is pressed (assuming HIGH when pressed)?
Pin 2 is set as INPUT, so digitalRead(2) reads the button state correctly.
Step 2: Understand button press state
When the button is pressed, the pin reads HIGH which is 1, so Serial.println prints 1 repeatedly.
Final Answer:
1 -> Option A
Quick Check:
Pressed button = HIGH = 1 [OK]
Hint: Pressed button reads HIGH (1) on digitalRead() [OK]
Common Mistakes:
Assuming pressed button reads 0 instead of 1
Forgetting to set pinMode to INPUT
Confusing analogRead with digitalRead
4. Identify the error in this code snippet that reads a button state on pin 4:
void setup() {
Serial.begin(9600);
}
void loop() {
int state = digitalRead(4);
Serial.println(state);
delay(1000);
}
medium
A. delay() cannot be used with digitalRead()
B. digitalRead() cannot be used in loop()
C. Serial.begin() should be in loop()
D. Missing pinMode(4, INPUT) in setup()
Solution
Step 1: Check pin configuration
The code does not set pin 4 as INPUT using pinMode(), which is required before reading.
Step 2: Verify other parts
digitalRead() can be used in loop(), Serial.begin() must be in setup(), and delay() is allowed.
Final Answer:
Missing pinMode(4, INPUT) in setup() -> Option D
Quick Check:
Always set pinMode before digitalRead() [OK]
Hint: Always set pinMode(INPUT) before digitalRead() [OK]
Common Mistakes:
Forgetting pinMode() setup
Moving Serial.begin() to loop() incorrectly
Thinking delay() breaks digitalRead()
5. You want to detect if a switch connected to pin 3 is pressed, but the switch is wired so it connects the pin to GND when pressed (active LOW). Which code snippet correctly reads the switch state and prints "Pressed" or "Not Pressed" accordingly?
A)