Bird
0
0
Arduinoprogramming~10 mins

Humidity and temperature (DHT11/DHT22) in Arduino - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to include the DHT sensor library.

Arduino
#include [1]
Drag options to blanks, or click blank then click option'
A<Wire.h>
B<DHT.h>
C<SPI.h>
D<Servo.h>
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.
2fill in blank
medium

Complete the code to define the DHT sensor type as DHT22.

Arduino
#define DHTTYPE [1]
Drag options to blanks, or click blank then click option'
ADHT11
BDHT12
CDHT22
DDHT33
Attempts:
3 left
💡 Hint
Common Mistakes
Using DHT11 when the sensor is actually DHT22.
Using undefined sensor types like DHT33.
3fill in blank
hard

Fix 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'
A2
BDHTTYPE
C3
DDHT
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.
4fill in blank
hard

Fill 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'
AreadHumidity
BreadTemperature
CreadTemp
DgetHumidity
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.
5fill in blank
hard

Fill 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'
Atemperature
Bhumidity
Dtemp
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.