B. Wire.begin() must be called inside loop, not setup.
C. The sensor object is not declared before use.
D. Missing #include for the sensor's specific library.
Solution
Step 1: Check object declaration
The code calls sensor.begin() and sensor.read() but never declares or creates a sensor object.
Step 2: Verify library usage
Without declaring sensor, the code will not compile or run correctly.
Final Answer:
The sensor object is not declared before use. -> Option C
Quick Check:
Objects must be declared before calling methods [OK]
Hint: Always declare objects before calling their methods [OK]
Common Mistakes:
Thinking Wire.begin() must be in loop
Assuming header file alone creates objects
Ignoring missing object declarations
5. You want to use both the Servo and SoftwareSerial libraries in your Arduino project to control a servo motor and communicate via serial. Which of the following is the best approach to combine them correctly?
hard
A. Include both libraries at the top, create objects for each, initialize in setup(), and use their functions in loop().
B. Include only the Servo library and call SoftwareSerial functions inside Servo methods.
C. Use #include for Servo in setup() and SoftwareSerial in loop().
D. Combine both libraries into one custom library before including.
Solution
Step 1: Properly include and declare libraries
Both libraries must be included at the top with #include and objects created for Servo and SoftwareSerial.
Step 2: Initialize and use in setup() and loop()
Initialize both in setup() and call their functions as needed in loop() to run both tasks simultaneously.
Final Answer:
Include both libraries at the top, create objects for each, initialize in setup(), and use their functions in loop(). -> Option A
Quick Check:
Include, declare, initialize, then use both libraries [OK]
Hint: Include and initialize all libraries before using their functions [OK]
Common Mistakes:
Trying to include libraries inside functions
Assuming one library can call another's functions
Delaying includes until inside setup or loop
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.