DEV Community

張旭豐
張旭豐

Posted on

Why Your Servo Motor Stutters and How to Fix It

Your Servo Motor Moves Like a Robot — Animals Never Do This

Reaction vs Response — two ways a machine moves when you touch it.

Reaction: You walk up, light turns on. Instantly. Zero delay. A switch.

Response: You walk up, light notices you, slowly brightens toward you. Not instant. Something closer to alive.

The difference is not speed. It is trajectory — whether the motion has a beginning, middle, and end your body recognizes as intentional.

The Moment Everything Went Wrong

Xiao-Mei is a visual designer. Six months into hardware.

She built her first interactive piece: an HC-SR04 sensor and an LED. When someone walked close, the light turned on.

She tested it in her apartment. It worked.

She put it in a gallery. Someone walked toward the piece. The light snapped on.

The person stepped back. Not impressed — startled. They felt like the light was broken.

Xiao-Mei could not explain why. The timing was correct. The sensor worked. But something about the light's behavior read as malfunction, not interaction.

She tried adjusting delay values. 500ms — too slow, like broken. 50ms — still too fast, like a machine.

She did not know what she was looking for.

The Question You Are Actually Asking

When makers describe the problem, they say:

  • "The motion looks mechanical."
  • "The light feels fake."
  • "It works but it doesn't feel right."

What they are describing is the same thing: the motion has no trajectory.

Trajectory means the motion has a shape. It starts somewhere, passes through somewhere, arrives somewhere. A light that snaps on has no trajectory. A light that brightens toward you over 400ms does.

The Perception Check: Five Questions

Before you write any code, check your project:

  1. Does it respond instantly? Instant = dead. Real responses have latency your nervous system expects.
  2. Does it stop cleanly? Instant stop = dead. Real motion decelerates.
  3. Is the motion consistent throughout? Constant speed = dead. Real motion accelerates and decelerates.
  4. Do multiple elements move simultaneously? Simultaneous = coordinated-by-accident. Real coordination has slight time offsets.
  5. Does it go full intensity immediately? Full-on instantly = dead. Biological responses are proportional, not binary.

If three or more are "yes": your piece reads as a switch, not a living system.

Servo Motor: The Five-Line Fix

The servo moves from angle A to angle B. Default: get there as fast as possible, stop exactly when it arrives.

That is reaction. Here is response:

#include <Servo.h>
Servo myServo;
int targetAngle = 0;
int currentAngle = 0;
unsigned long lastMoveTime = 0;
int moveInterval = 15; // ms between each degree

void loop() {
  if (Serial.available()) {
    targetAngle = Serial.parseInt();
  }

  if (millis() - lastMoveTime > moveInterval) {
    if (currentAngle < targetAngle) {
      currentAngle++;
      myServo.write(currentAngle);
    } else if (currentAngle > targetAngle) {
      currentAngle--;
      myServo.write(currentAngle);
    }
    lastMoveTime = millis();
  }
}
Enter fullscreen mode Exit fullscreen mode

The servo now moves one degree at a time, 15ms apart. 180 degrees takes about 2.7 seconds. It accelerates into motion and decelerates into position. It looks like something deciding where to go.

That is response. That is what alive looks like.

Top comments (0)