Robotics & Arduino
Lesson 2 · Refinement

The same starting point.

The first part of our code is shared by all three versions.

INCLUDE — our servo helper.

Load the header. Create a Servo object named myServo — our named “box” for controlling this servo.

DECLARE — which pin?

Name the pin that sends the servo control pulses.

DECLARE — our ranges.

Name the library defaults, the proposed test limits, and the angle endpoints.

The Pwm values are pulse widths in microseconds. Here the proposed lower test value is 400 µs. These test limits are guesses, not confirmed safe endpoints for your servo.

INIT — start the terminal and attach the servo.

Start Serial, tell myServo which pin carries its signal, and print a welcome message.

Match the Serial Monitor to 9600 baud. With attach(servoPin), the library uses its default 544–2400 µs limits and clamps commands to that range. Declaring testMinPwm and testMaxPwm does not change those limits; a wider range needs explicit configuration after checking the servo’s specifications.

This is the shared beginning of the sketch. We’ll add RUN and the movement logic in the next steps.