Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to set the LED pin as output.
Arduino
void setup() {
pinMode([1], OUTPUT);
}
void loop() {
// LED control code
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using analog pins like A0 instead of digital pins.
Choosing pins not connected to the LED.
✗ Incorrect
The built-in LED on most Arduino boards is connected to pin 13, so we set pin 13 as output.
2fill in blank
mediumComplete the code to turn the LED on.
Arduino
void loop() {
digitalWrite(13, [1]);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using LOW instead of HIGH to turn on the LED.
Confusing pin modes with output values.
✗ Incorrect
To turn the LED on, we set the pin to HIGH.
3fill in blank
hardFix the error in the code to correctly read battery voltage on analog pin A0.
Arduino
int sensorValue = analogRead([1]); float voltage = sensorValue * (5.0 / 1023.0);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'A0' as a string instead of 0.
Using digital pin numbers for analogRead.
✗ Incorrect
analogRead expects the analog pin number as an integer, so A0 is pin 0.
4fill in blank
hardFill both blanks to calculate battery voltage with a voltage divider.
Arduino
float batteryVoltage = sensorValue * ([1] / 1023.0) * ([2] + 10.0) / 10.0;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong reference voltage.
Incorrect resistor values in formula.
✗ Incorrect
The Arduino uses 5V reference, and the voltage divider resistors are 10k and 20k ohms, so we multiply by (20+10)/10.
5fill in blank
hardFill all three blanks to print battery voltage with 2 decimal places.
Arduino
Serial.print("Battery Voltage: "); Serial.print([1], [2]); Serial.println([3]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable name.
Forgetting to print the unit.
✗ Incorrect
We print the variable batteryVoltage with 2 decimals, then print the unit " V" on a new line.