Servo Motor

A Servo Motor contains a DC motor, some gears with a simple encoder (like a potentiometer), and an on-board electronic controller that will read instructions in and convert them to either a position to hold (180 degree servos) or a direction and speed to spin (360 versions).

Servo Horns

Usually a servo will be provided with some servo horns for various use cases. The common Tower sg90 servo comes with three:

If you want to put a long popsicle stick over the middle of the servo's rotating shaft, then use one of the two bigger double-sided horns. If you want to make a gantry, or connect a rudder, or have some space constraint then the smaller half-horn is more suitable.

Screws

There are 2 types of screws, the mall one is for securing the horn onto the servo shaft. A lot of times that isn't needed because the servo horn has a good tight fit over the shaft.

The other two screws can be used to secure thehorn onto an external bit of hardware like plastic or wood.

Wiring

The Servo has 3 cables:

Red - Power (+)

Brown - Power (-/Gnd)

Orange - Signal (coded behavior)

Connecting Directly to ESP32

We cannot use the Servo wire connector directly with the ESP32 board, so we will utilize extra Male-to-Female Dupont wires. The colors on these extra wires is irrelevant. As long as:

Servo Wire Color ESP32 Pin
Red VIN
Brown GND
Orange Dxx (D04 in coding example)

Connecting with Breadboard

Similar to above. Now we need Male to Male Dupont wires...

Connecting with Expansion Board

TBD

Coding

Coding the servo is faily simple. Assuming the most basic servo type (holds positions 0-180 degrees):

The pin denotes the pin that the Servo Signal (orange) wire is connected to.

The second number is the angle position to hold.

In order to move from one position to another you need to give the servo some time to reach the desired position:

ALSO: Note that 0 and 180 may not be exactly 0 and 180. They map to some API number that is not the same across all servos.

You may try the range from roughly -100 to 300 and once you find the true range, you can utilize the map block like this:

Challenge

Make repetitive motion like a car's windshield wiper - use loops, and don't forget to sleep.