The servo object is declared as Servo servo1; and attached to pin 5, which is valid.
Step 2: Review write and delay usage
The write() commands set angles 0 and 180 with delays of 1000 milliseconds, all correctly terminated with semicolons.
Final Answer:
No error; the code will run correctly -> Option C
Quick Check:
Correct syntax and logic = A [OK]
Hint: Check semicolons and valid pin numbers [OK]
Common Mistakes:
Assuming pin 5 is invalid without checking board specs
Missing semicolons after delay calls
Incorrect servo object declaration syntax
5. You want to sweep a servo motor smoothly from 0 to 180 degrees and back repeatedly. Which code snippet correctly implements this using the Servo library?
Sweeping smoothly means moving the servo in small steps with short delays between each step.
Step 2: Analyze each option
for(int pos=0; pos<=180; pos+=1) { myServo.write(pos); delay(15); } for(int pos=180; pos>=0; pos-=1) { myServo.write(pos); delay(15); } uses two for-loops to increment and decrement the angle by 1 degree with 15 ms delay, creating a smooth sweep. Options A, C, and D do not create smooth back-and-forth movement.