Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to include the SD library.
Arduino
#include [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Including SPI.h instead of SD.h
Forgetting to include any library
✗ Incorrect
The SD library is included with #include to work with SD cards.
2fill in blank
mediumComplete the code to initialize the SD card in setup().
Arduino
if (!SD.[1](4)) { Serial.println("Initialization failed!"); return; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using SD.init() instead of SD.begin()
Using wrong pin number
✗ Incorrect
SD.begin(4) initializes the SD card on pin 4.
3fill in blank
hardFix the error in opening the file for reading.
Arduino
File dataFile = SD.[1]("test.txt", FILE_READ);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using SD.read() which reads data, not opens file
Using non-existent functions like openFile
✗ Incorrect
Use SD.open() to open a file for reading or writing.
4fill in blank
hardFill both blanks to read and print each character from the file.
Arduino
while (dataFile.[1]()) { char c = dataFile.[2](); Serial.print(c); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using open() or close() instead of available() or read()
Not checking if data is available before reading
✗ Incorrect
Use available() to check if data remains and read() to get each byte.
5fill in blank
hardFill all three blanks to close the file and print a message.
Arduino
dataFile.[1](); Serial.[2]("File closed."); while (!Serial.[3]()) {}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to close the file
Using print() instead of println() for message
Not waiting for serial data before continuing
✗ Incorrect
Close the file with close(), print message with println(), and wait for serial data with available().