A servo rotates a shaft or arm to a selected angle.
These small servos are commonly used in RC (radio controlled) model airplanes.
Here's an example project which uses a pair of Arduino Pro Micro and WiFi boards.
The XRP Code Editor includes one block to control servos -->
Write a program to explore the servo.
Use the text ... "prompt for number" block to prompt the user to enter the servo angle.
(Follow the example from Polygons )
Put this in a repeat while true loop so you can enter different angles.
Note that there is an XRP Code Editor bug that prevents keyboard input:
https://github.com/Open-STEM/XRPCode/issues/61
Workaround:
RUN (uploads the program, but won't accept keyboard input)
STOP (stops the program)
In the shell area of the window, type CTRL-D, which restarts the program and allows keyboard input
Remove the black pickup arm from the servo. Place the servo "horn" on the servo so you can readily see the servo motion.
Turn on the battery power switch, as the servo motor uses the battery for its power source.
Run the program
What is the minimum and maximum ranger of the servo angle?
Remove the servo horn and install the servo arm such that the arm can move through the entire servo angle range without hitting the XRP chassis.
Test
Do something else with the servo. Ideas:
Use 2 "count with" loops to move the servo through the entire rangle of motion is each direction. Put this in a "while true" loop.
(Hint: you'll need to include some "sleep" block to give the servo enough time to move to the selected angle before going to the next angle.)
Use the button to select a random angle within the range of the servo.
(math ... random integer)
Your ideas?
Be sure to turn OFF the motor power switch when you are done!
(And especially during classroom breaks and after the end of class.
Otherwise, the battery will drain and you won't be able to drive.. 😞