Digital Input/Output (I/O) lets your Arduino talk to the outside world by reading simple ON/OFF signals or turning things ON/OFF. It is the basic way to control and sense devices.
Why digital I/O is the foundation in Arduino
Start learning this pattern below
Jump into concepts and practice - no test required
pinMode(pin, INPUT); pinMode(pin, OUTPUT); digitalWrite(pin, HIGH); digitalWrite(pin, LOW); digitalRead(pin);
pinMode sets a pin as input or output.
digitalWrite sets an output pin HIGH (on) or LOW (off).
digitalRead reads if an input pin is HIGH or LOW.
pinMode(13, OUTPUT); // Set pin 13 as output // Turn LED on digitalWrite(13, HIGH); // Turn LED off digitalWrite(13, LOW);
pinMode(2, INPUT); // Set pin 2 as input int buttonState = digitalRead(2); // Read button state
This program reads a button on pin 2. When pressed, it turns on an LED on pin 13 and prints a message. When released, it turns off the LED and prints another message.
void setup() {
pinMode(13, OUTPUT); // LED pin
pinMode(2, INPUT); // Button pin
Serial.begin(9600);
}
void loop() {
int buttonState = digitalRead(2);
if (buttonState == HIGH) {
digitalWrite(13, HIGH); // Turn LED on
Serial.println("Button pressed: LED ON");
} else {
digitalWrite(13, LOW); // Turn LED off
Serial.println("Button not pressed: LED OFF");
}
delay(500); // Wait half a second
}Digital I/O only reads or writes two states: HIGH (on) or LOW (off).
Use pull-up or pull-down resistors to avoid false readings on input pins.
Always set pinMode before using digitalRead or digitalWrite.
Digital I/O is the simplest way for Arduino to interact with the world.
It controls devices by turning pins ON or OFF and reads simple ON/OFF signals.
Understanding digital I/O is the first step to building interactive projects.
Practice
Solution
Step 1: Understand digital I/O function
Digital I/O pins can read or send signals that are either ON (HIGH) or OFF (LOW).Step 2: Compare options with function
Only To read or send simple ON/OFF signals describes this simple ON/OFF signal role correctly.Final Answer:
To read or send simple ON/OFF signals -> Option AQuick Check:
Digital I/O = ON/OFF signals [OK]
- Confusing digital I/O with memory storage
- Thinking digital I/O connects directly to internet
- Assuming digital I/O powers the board
Solution
Step 1: Recall pinMode function usage
pinMode(pin, mode) sets a pin as INPUT or OUTPUT.Step 2: Identify correct syntax for output
pinMode(7, OUTPUT); correctly sets pin 7 as output.Final Answer:
pinMode(7, OUTPUT); -> Option BQuick Check:
pinMode + OUTPUT = pinMode(7, OUTPUT); [OK]
- Using digitalWrite instead of pinMode to set pin mode
- Setting pin as INPUT instead of OUTPUT
- Passing OUTPUT to digitalRead or digitalWrite incorrectly
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}Solution
Step 1: Analyze pinMode and digitalWrite usage
Pin 13 is set as output, then turned HIGH (ON) and LOW (OFF) with 1 second delay each.Step 2: Understand loop behavior
The loop repeats turning LED ON for 1 second, then OFF for 1 second, causing blinking.Final Answer:
LED blinks ON and OFF every second -> Option CQuick Check:
digitalWrite + delay = blinking LED [OK]
- Thinking LED stays ON or OFF permanently
- Confusing delay units (milliseconds vs seconds)
- Assuming code has syntax errors
void setup() {
pinMode(2, OUTPUT);
}
void loop() {
int buttonState = digitalRead(2);
}Solution
Step 1: Check pinMode for reading input
To read a button, pin 2 must be set as INPUT, not OUTPUT.Step 2: Verify digitalRead usage
digitalRead reads the state of an input pin correctly if pinMode is INPUT.Final Answer:
Pin 2 should be set as INPUT, not OUTPUT -> Option DQuick Check:
Reading pin requires INPUT mode [OK]
- Setting pin as OUTPUT when reading input
- Thinking digitalRead is invalid inside loop
- Declaring variables only globally is required
Solution
Step 1: Set pin modes correctly
Button pin 2 must be INPUT to read its state; LEDs pins 8 and 9 must be OUTPUT to control them.Step 2: Check button press condition
When button is pressed, digitalRead(2) returns HIGH, so LEDs are set accordingly.Final Answer:
pinMode(2, INPUT); pinMode(8, OUTPUT); pinMode(9, OUTPUT); if(digitalRead(2) == HIGH) { digitalWrite(8, HIGH); digitalWrite(9, LOW); } -> Option AQuick Check:
Button INPUT + LEDs OUTPUT + condition HIGH = correct [OK]
- Setting button pin as OUTPUT instead of INPUT
- Setting LEDs as INPUT instead of OUTPUT
- Checking LOW instead of HIGH for button press
