Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to read an analog value from pin A0.
Arduino
int sensorValue = analogRead([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using a digital pin number instead of an analog pin name.
Confusing analogRead with digitalRead.
✗ Incorrect
The analogRead function reads the voltage on an analog pin like A0.
2fill in blank
mediumComplete the code to print the analog sensor value to the serial monitor.
Arduino
Serial.println([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Trying to print a digital pin state instead of the analog value.
Using undefined variables.
✗ Incorrect
sensorValue holds the analog reading and should be printed.
3fill in blank
hardFix the error in the code to correctly read and print an analog value.
Arduino
void setup() {
Serial.begin(9600);
}
void loop() {
int value = analogRead([1]);
Serial.print("Value: ");
Serial.println(value);
delay(1000);
}Attempts:
3 left
💡 Hint
Common Mistakes
Using a digital pin number with analogRead causes wrong readings.
Confusing pin numbers with pin labels.
✗ Incorrect
analogRead needs an analog pin like A0 to read the sensor value.
4fill in blank
hardFill both blanks to create a dictionary of sensor readings greater than 500.
Arduino
int readings[] = {450, 520, 610, 480};
for (int i = 0; i < 4; i++) {
if (readings[i] [1] 500) {
Serial.println(readings[[2]]);
}
}Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' causes wrong filtering.
Using wrong index to access array elements.
✗ Incorrect
The code prints readings greater than 500 using the index i.
5fill in blank
hardFill all three blanks to create a map of sensor names to values above 300.
Arduino
String sensors[] = {"temp", "light", "sound"};
int values[] = {250, 400, 350};
for (int [1] = 0; [1] < 3; [1]++) {
if (values[[2]] [3] 300) {
Serial.print(sensors[[2]]);
Serial.print(": ");
Serial.println(values[[2]]);
}
}Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables for indexing sensors and values.
Using '<' instead of '>' in the condition.
✗ Incorrect
The loop variable i is used to check values greater than 300 and print sensor names with values.
