Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to include the DHT sensor library.
Arduino
#include [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Including the wrong library like Wire.h or SPI.h which are for other sensors.
Forgetting the angle brackets <> around the library name.
✗ Incorrect
The DHT sensor library is included with #include to use the DHT11 or DHT22 sensors.
2fill in blank
mediumComplete the code to define the DHT sensor type as DHT22.
Arduino
#define DHTTYPE [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using DHT11 when the sensor is actually DHT22.
Using undefined sensor types like DHT33.
✗ Incorrect
Defining DHTTYPE as DHT22 tells the code which sensor model is used.
3fill in blank
hardFix the error in initializing the DHT sensor object on pin 2.
Arduino
DHT dht([1], DHTTYPE); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the sensor type or class name instead of the pin number.
Using a pin number that does not match the hardware connection.
✗ Incorrect
The first argument is the pin number where the sensor data line is connected, here pin 2.
4fill in blank
hardFill both blanks to read humidity and temperature values from the sensor.
Arduino
float humidity = dht.[1](); float temperature = dht.[2]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect function names like readTemp or getHumidity which do not exist.
Mixing up humidity and temperature function calls.
✗ Incorrect
Use readHumidity() to get humidity and readTemperature() to get temperature from the sensor.
5fill in blank
hardFill all three blanks to check if readings are valid and print them to the serial monitor.
Arduino
if (isnan([1]) || isnan([2])) { Serial.println("Failed to read from DHT sensor!"); return; } Serial.print("Humidity: "); Serial.print([3]); Serial.println(" %");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking variables that do not exist or are misspelled.
Printing temperature instead of humidity in the last print statement.
✗ Incorrect
We check if humidity or temperature is NaN (not a number) to detect errors. Then we print humidity value.
