Lab 8: Servo Motor

Sam Stromberg
4 min readOct 30, 2021

The servo motor is designed to precisely reach any orientation within a fixed range of motion — while the specs for mine say 180°, I found it was more like 195°, so trying to fit it into an encasement ran into some issues when it attempted to turn further than I had anticipated. So whereas the DC motor generates rotational motion at low torque and high(-ish) frequency, the servo motor has more force behind it but is about actuation/control rather than continuous motion. The servo library provides a Servo class and a bunch of useful functions to actually control it, so we can feed it fairly straightforward instructions.

With that out of the way, the goal of this lab was to construct a “crawler”, that is propelled by a servo motor (and doesn’t use wheels). Some options for inputs to control the servo include the serial monitor/keyboard, wiring a pot into the circuit (with output rescaled before being sent on — not directly connected to the control wire), or just letting the loop alternate between states. With the latter two schema, the Arduino and servo could even be run off a 9V battery, so that the crawler wouldn’t need a cable running back to a computer.

I attempted to build an enclosure for the servo, Arduino, and breadboard using LEGO bricks, which did not work out. I attached a chopstick to the servo arm to push it along, but the ground reaction force on the enclosure was strong enough to break it apart. Similar to the issue I had with vibration in the DC motor, encasing the servo in more robust materials would have enabled me to at least see whether the relatively-more-interesting part of the idea would have worked. To prevent the crawler from rocking back and forth, I initially considered trying to create a mechanism that would retract the propulsion arm on the return stroke (like how a click-pen toggles between states) but recognized that I don’t have the engineering background to readily sketch the necessary system. Instead, I decided to rely on friction and angle-of-attack, by positioning a vinyl eraser so that it would be pulled (at a low angle) on the forward stroke but then pushed (at a high angle) on the return stroke, lifting the crawler instead of letting the servo arm crawl it backward. But, as I said, the servo had other ideas, and wouldn’t stay contained.

LEGO enclosure is shown; servo is activated and immediately breaks enclosure.

Rubber bands might help? But if I’m working with more force than LEGOs can handle, it’s probably not going to hold together over the long run anyway. That said, I would suspect that the push-pull eraser acting as a backstop could help improve the efficiency of a variety of designs.

Components

The components and wiring weren’t dramatically different for this device — the servo motor is the new element, but most of the important differences between it and the DC motor are either inaccessible (the control chip within the servo itself) or reside in the software layer, as the servo library does the heavy lifting of converting an integer input into what the servo PCB can read. And unlike the DC motor, we don’t need to run a diode parallel to the motor to protect the other components — which I believe is because it’s already inside the servo, not because it doesn’t generate its own current when it spins up.

  • Arduino
  • breadboard
  • servo motor
  • potentiometer (at first)
  • jumper wires
  • LED + resistor (always useful for debugging)
  • some LEGOs to build (and rebuild) a housing

Code

This is more or less stock code — I originally had a little more that was of interest, until one of the wire leads on my pot broke (the wire itself, not the solder, thank you) and I switched to console control. The plan was to test / debug with full control of the servo, then to write a loop that would toggle between states automatically, but the dang thing kept breaking apart before I could get that far.

#include <Servo.h>

int servoPin = 7; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
Servo myservo; // create servo object to control a servo
int pos; // the position we want to move the servo to

void setup() {
myservo.attach(servoPin); // attaches the servo on pin servoPin to the servo object
Serial.begin(9600);
Serial.println(“Servo control program ready”);
}

void loop() {
while (Serial.available()) {
val = Serial.read();
if (val >= ‘1’ && val <= ‘9’ ) {
Serial.println();Serial.println();
// interpret the user’s input to get a number from 1 to 9
val = val — ‘0’; // convert val from character variable to number variable
// (see http://forum.arduino.cc/index.php?topic=103511.0 for a forum discussing more about this)
Serial.print(“val = “);Serial.println(val);

// calculate the position that we should move the servo to
pos = map(val, 1, 9, 0, 180); // (see https://www.arduino.cc/en/Reference/Map)
Serial.print(“pos = “);Serial.println(pos);

// tell the servo to go to the position
myservo.write(pos);
// wait a few milliseconds so we don’t overload the servo with commands
delay(15);
}
}

}

Exploration

Following the crawler race conducted during class, it became clear that one of the probable flaws in my design was the attempt to utilize the full 180-degree range of motion of the servo —an approach eschewed by the top performers. Particularly once I attached a boom to it, the full swivel shifted the center of gravity of the device dramatically, and it may have helped to counterweight the opposing blade of the servo to balance the load around the pivot.

--

--

Sam Stromberg

2nd-year Masters student at the UC Berkeley School of Information. Moving into Product; interested in data and uncertainty, sensor data, behavioral change.