Skip to content

Robotics

How to soft start a motor with a PWM ramp

A soft start brings a motor up to speed gradually instead of all at once. On an Arduino, write the PWM speed in small steps with a short wait between them: 0, 5, 10 and so on up to 255, 20 ms apart. Fifty-two small steps feel like one smooth push, the wheels grip instead of spinning, and whatever the robot is carrying stays put.

Why a jump is rough

analogWrite(9, 255) to a stopped motor asks for full speed now. The motor delivers its biggest torque from a standstill, so the robot lurches. If that acceleration is more than the tyres' grip allows, the wheels spin on the floor before they bite. The current surge is hard on gears and batteries, and it can make the supply sag enough to reset the board.

The ramp

void setup() {
  for (int speed = 0; speed <= 255; speed = speed + 5) {   // 0 -> 255 in fives
    analogWrite(9, speed);
    analogWrite(10, speed);
    delay(20);
  }
}
ramp time = steps × delay = 52 × 20 ms ≈ 1 s

The for loop counts speed from 0 to 255 in fives, writing it to both wheels each time and waiting 20 ms. That's 52 values, counting the 0, so the climb takes just over a second. It lives in setup(), which runs once; when it finishes, loop() simply writes 255 to both wheels on every pass and the robot carries on at full speed.

Step and delay

The step sets how smooth the ramp is; the delay sets how long it takes:

StepDelayPassesRamp
520 ms52about 1 s, smooth
51 ms52about 52 ms: a jump in disguise
1520 ms18about 0.36 s
5020 ms6about 0.12 s, six lumps, ending at 250

A ramp of 52 ms is quicker than the wheels can even follow, so it lurches almost as hard as no ramp at all.

Live experiment

Pull away without spilling

The rover pulls away carrying a dish of soup filled to the brim, ramping both wheels from 0 to 255 in steps of 5 with a delay between steps. With no ramp, or delay(1), it lurches and the soup spills; delay(5) sloshes it up to the brim; delay(20) glides away over about a second.

Try it yourself: free lesson

“Soft start” is lesson 4 of 6 in Rover Ridge, Robotics World 1. Free with an account. Lessons unlock in order, so you’ll do the 3 before it first.

Where you'll meet it

Lifts and trains ramp their speed up and down so nobody falls over. Big factory motors have soft starters that do it in hardware, and the speed controllers on drones and electric skateboards limit how fast the throttle can rise for the same reasons: grip, gears and current.

Free lesson

Now build it yourself

Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.

Try it yourself: free lesson

“Soft start” is lesson 4 of 6 in Rover Ridge, Robotics World 1. Free with an account. Lessons unlock in order, so you’ll do the 3 before it first.

Or start from the very first lesson, no account needed

Practice questions

Three quick questions from the lessons. Pick an answer to check it.

  1. Question 1 of 3Why does a sudden start make wheels slip?
    Show the answer

    Answer: The wheels try to speed up faster than the grip on the floor allows. Grip has a limit. Ask for too much acceleration at once and the wheels spin instead of pushing.

    • Why not “The motor is too weak”? A weak motor would struggle to spin the wheels at all. Slip means the wheels are turning faster than the grip can follow.
    • Why not “It doesn't”? Grip has a limit, so asking for full speed at once can spin the wheels, especially on a smooth floor.
    • Why not “The battery is too strong”? The slip comes from asking for too much acceleration at once, not from the battery. A ramp fixes it with the same battery.
  2. Question 2 of 3A ramp counts up in fives with delay(1) between steps. Pulling away, the rover…
    Show the answer

    Answer: Lurches almost as hard as with no ramp: the whole climb takes about 52 ms. 52 steps of 1 ms is about a twentieth of a second, quicker than the wheels can even follow, so it's a jump in disguise and the soup goes over. delay(20) spreads the same 52 steps over about a second.

    • Why not “Glides away over about a second”? That's the delay(20) ramp. With delay(1) the same 52 steps are over in about 52 ms.
    • Why not “Starts more gently than with delay(20)”? A shorter delay makes the ramp shorter and harsher, not gentler.
    • Why not “Never reaches full speed”? The loop still counts all the way to 255, just very quickly.
  3. Question 3 of 3Steps of 50 instead of 5, same 20 ms delay. The ramp is…
    Show the answer

    Answer: Over in about 0.1 s, in six coarse jumps. speed goes 0, 50, … 250, six passes, and six lots of 20 ms is about a tenth of a second. Big steps make a short, lumpy ramp. Small steps and a longer delay make a smooth one.

    • Why not “Ten times longer”? Fewer steps with the same delay make the ramp shorter, not longer.
    • Why not “The same”? With steps of 50 there are only six passes instead of 52, so it's over far sooner.
    • Why not “Smoother”? Bigger steps make bigger jumps in speed, so the ramp is lumpier, not smoother.
Keep practising: free lesson

“Soft start” is lesson 4 of 6 in Rover Ridge, Robotics World 1. Free with an account. Lessons unlock in order, so you’ll do the 3 before it first.

Questions people ask

How long should a motor soft start take?

Long enough that the wheels never slip or the load never jolts, short enough not to feel sluggish. For a small robot, about a second is a good start. The time is the number of steps times the delay: 52 steps of 20 ms is about 1 s.

Why does my motor jerk when it starts?

Writing 255 to a stopped motor asks for full speed at once. The motor makes its biggest torque from a standstill, so the robot lurches and the wheels can spin before they grip. The surge of current can also make the supply dip and reset the board.

Can I ramp the speed without delay()?

Yes. Keep the speed in a variable and, each time millis() shows another 20 ms has passed, add 5 until it reaches 255. loop() keeps running between steps, so sensors are still read during the ramp.

Should a robot ramp down to stop as well?

Often, yes. A soft stop keeps a load from sliding forward and is easier on gears. An emergency stop is the exception: then you want the wheels off at once.

Every topic