Bird
0
0
Arduinoprogramming~10 mins

Using sensor libraries 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 sensor library.

Arduino
#include [1]
Drag options to blanks, or click blank then click option'
A<DHT.h>
B"DHT.h"
C<Wire.h>
D"Servo.h"
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes instead of angle brackets for installed sensor libraries.
Including the wrong library like Servo.h.
2fill in blank
medium

Complete the code to create a sensor object named 'sensor'.

Arduino
DHT [1](2, DHT22);
Drag options to blanks, or click blank then click option'
AmySensor
BDHT
CtempSensor
Dsensor
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name 'DHT' as the object name.
Using unrelated names like 'tempSensor' without context.
3fill in blank
hard

Fix 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'
Adht
BSensor
Csensor
DDHT
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect capitalization like 'Sensor' or 'DHT'.
Calling begin() on the class name instead of the object.
4fill in blank
hard

Fill 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'
Asensor
BtempSensor
CSensor
Ddht
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.
5fill in blank
hard

Fill 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'
Ahumidity
Btemperature
CDHT
Dsensor
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.