Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to include the sensor library.
Arduino
#include [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes instead of angle brackets for installed sensor libraries.
Including the wrong library like Servo.h.
✗ Incorrect
The sensor library DHT.h is included using angle brackets because it is an installed Arduino library.
2fill in blank
mediumComplete the code to create a sensor object named 'sensor'.
Arduino
DHT [1](2, DHT22);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name 'DHT' as the object name.
Using unrelated names like 'tempSensor' without context.
✗ Incorrect
The sensor object is named 'sensor' to match the example.
3fill in blank
hardFix the error in the setup function to start the sensor.
Arduino
void setup() {
Serial.begin(9600);
[1].begin();
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect capitalization like 'Sensor' or 'DHT'.
Calling begin() on the class name instead of the object.
✗ Incorrect
The sensor object is named 'sensor' and must be called with .begin() to initialize.
4fill in blank
hardFill both blanks to read temperature and humidity from the sensor.
Arduino
float humidity = [1].readHumidity(); float temperature = [2].readTemperature();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different or incorrect object names for humidity and temperature.
Using capitalized names that do not match the object.
✗ Incorrect
The sensor object named 'sensor' is used to call both readHumidity() and readTemperature() methods.
5fill in blank
hardFill all three blanks to check if readings are valid and print them.
Arduino
if (isnan([1]) || isnan([2])) { Serial.println("Failed to read from [3] sensor!"); return; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names in isnan checks.
Mentioning the object name instead of the class name in the message.
✗ Incorrect
We check if humidity or temperature is NaN and print an error message mentioning the DHT sensor.
