Challenge - 5 Problems
Multi-Library Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of combined sensor readings
What is the output of this Arduino sketch that uses two libraries to read temperature and humidity?
Arduino
#include <DHT.h> #include <Wire.h> #define DHTPIN 2 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); dht.begin(); } void loop() { float h = dht.readHumidity(); float t = dht.readTemperature(); Serial.print("Humidity: "); Serial.print(h); Serial.print(" %"); Serial.print(", Temperature: "); Serial.print(t); Serial.println(" *C"); delay(2000); }
Attempts:
2 left
💡 Hint
Check if the sensor is properly initialized and if the readings are valid.
✗ Incorrect
Without a real sensor connected, the DHT library returns 'nan' for humidity and temperature. The Wire library is included but not used here, so no error occurs.
🧠 Conceptual
intermediate1:30remaining
Reason for including multiple libraries
Why do Arduino sketches often include multiple libraries like and together?
Attempts:
2 left
💡 Hint
Think about what each library controls in hardware communication.
✗ Incorrect
Wire.h is for I2C communication and SPI.h is for SPI communication. Including both allows the sketch to communicate with devices using different protocols.
🔧 Debug
advanced2:00remaining
Identify the error when using two libraries
What error will this Arduino code produce when compiling?
Arduino
#include <Wire.h> #include <SPI.h> void setup() { Wire.begin(); SPI.begin(); } void loop() { Wire.beginTransmission(0x3C); SPI.transfer(0xFF); Wire.endTransmission(); delay(1000); }
Attempts:
2 left
💡 Hint
Check the correct usage of SPI.transfer() in SPI communication.
✗ Incorrect
SPI.transfer() must be called between SPI.beginTransaction() and SPI.endTransaction() for proper operation. Calling it directly causes an error or undefined behavior.
📝 Syntax
advanced1:00remaining
Correct syntax for using two libraries
Which option shows the correct way to initialize both Wire and SPI libraries in Arduino?
Attempts:
2 left
💡 Hint
Check the official Arduino library functions for starting communication.
✗ Incorrect
Wire.begin() and SPI.begin() are the correct functions to initialize I2C and SPI communication respectively.
🚀 Application
expert3:00remaining
Combining sensor data with display using multiple libraries
You want to read temperature from a DHT sensor and display it on an OLED screen using Wire and Adafruit_SSD1306 libraries. Which code snippet correctly initializes and uses both libraries together?
Attempts:
2 left
💡 Hint
Check how the display object is constructed and which communication protocol it uses.
✗ Incorrect
The Adafruit_SSD1306 display must be constructed with the Wire object for I2C communication. Option C correctly passes &Wire and initializes both libraries properly.