Bafang Error 21: Wheel Speed Sensor Fix

Bafang Error 21 indicates that the motor controller has stopped receiving speed signal pulses from the rear wheel speed sensor while the bicycle is in motion, or that the sensor circuit is broken. When the controller cannot determine road speed, it cuts motor assist within 5 to 10 seconds as a regulatory and safety precaution. The vast majority of Error 21 faults are caused by a loose spoke magnet that has twisted away from the chainstay sensor pickup.

Fast Fix

Locate the speed sensor mounted to your rear chainstay and the small magnet clamped to an adjacent wheel spoke. Loosen the spoke magnet screw, reposition the magnet so its center passes directly across the alignment notch on the sensor face with a 2 mm to 4 mm gap, and tighten the screw securely.


Quick Status & Safety

  • Severity: Low to Moderate. Electric motor assistance is disabled, but manual pedaling and braking operate normally.
  • Safe to ride: Yes. Riding without the speed sensor will not damage the mechanical drivetrain or motor internals.
  • Likely cause: Displaced spoke magnet, excessive sensor gap, severed chainstay sensor wire, or an unplugged 3-pin connector.

What This Means

To comply with e-bike speed limits and maintain smooth pedal assist, the motor controller must know how fast the bike is traveling. Bafang systems accomplish this using an external speed sensor assembly:

  • A magnetic reed switch or hall-effect sensor bolted to the inside of the non-drive-side chainstay.
  • A small permanent magnet clamped to a rear wheel spoke (or integrated into the disc brake rotor).

Every time the wheel turns, the magnet sweeps past the sensor, closing a circuit and sending a voltage pulse to the controller. The controller measures the time between pulses and calculates road speed based on the wheel diameter programmed in the display. If the pedals are turning and the motor outputs power, but zero wheel pulses register over several consecutive seconds, the controller logs Error 21 and shuts down power assist.


Diagnostic Path

Follow this checklist to identify the exact cause:

  1. The display turns on normally, but shows 0.0 mph / km/h while pedaling, followed shortly by Error 21:
  2. Error 21 appears instantly the moment the display powers on, before the wheels move:
    • Suspect: An electrical open circuit or short. The speed sensor is unplugged, a connector pin is bent, or the wire along the chainstay has been severed.
  3. The speedometer jumps erratically (e.g., flashes between 8 mph and 50 mph) before triggering Error 21:
  4. The sensor’s red indicator light fails to blink when the wheel turns:
    • Suspect: If your sensor has an integrated LED, a failure to flash means the magnet is too far away, misaligned, or the sensor has lost operating power from the motor harness.

Likely Causes

1. Rotated or Slid Spoke Magnet

Vibrations from riding over bumps, washing the bike, or brush snagging the spokes can twist the magnet on its mount. If the magnetic face points sideways or outward rather than directly at the sensor body, the hall switch will not trigger.

2. Excessive Magnet Gap

The sensing threshold requires the magnet to pass within 2 mm to 4 mm of the pickup face. If the sensor has pivoted away on the chainstay, or if the magnet was installed too far out on the spoke, the gap becomes too wide for the magnetic field to close the switch.

3. Pinched or Severed Sensor Cable

The thin cable running along the chainstay is vulnerable. Tire rub, chain slap, or overly tightened plastic zip ties can slice into the outer jacket and break the internal conductors. See Repairing a Frayed Speed Sensor Cable at the Chainstay.

4. Disconnected or Corroded 3-Pin Plug

The speed sensor connects to the motor harness via a compact, 3-pin round waterproof connector (typically color-coded yellow or red). If this plug pulls loose or suffers pin corrosion from water ingress, the signal drops out.


Commonly Confused Problems


What To Do

Step 1: Realign the Magnet and Sensor

  1. Spin the rear wheel slowly by hand and watch where the spoke magnet passes the chainstay sensor.
  2. Look closely at the sensor housing. Locate the small raised line, notch, or crosshair molded into the plastic face.
  3. Loosen the magnet’s retaining screw with a screwdriver.
  4. Slide the magnet along the spoke until its center aligns directly with the sensor’s raised mark.
  5. Adjust the sensor body on the chainstay so the gap between the magnet face and sensor surface is 2 mm to 4 mm (about the thickness of two credit cards).
  6. Tighten the magnet screw and the sensor mounting bolt securely. If your bike uses a brake-rotor magnet, see Fixing Speed Sensor Magnet Disc Displacement and Errors.

Step 2: Monitor the Sensor Indicator LED

  1. If your Bafang sensor features a small built-in red LED, spin the wheel in a dimly lit area.
  2. Watch for a distinct red flash each time the magnet sweeps past.
  3. If the LED flashes with every revolution, the sensor and magnet alignment are working properly. Proceed to Step 3 to trace the upstream wiring.
  4. If the LED does not flash, the gap is still too wide, the magnet has lost its charge, or the sensor has lost its 5V operating power.

Step 3: Inspect the Cable and Reseat the Connector

  1. Trace the thin wire from the sensor along the chainstay toward the motor housing.
  2. Inspect every inch of the cable for cuts, flattened spots from zip ties, or rub marks from the rear tire or disc brake rotor.
  3. Locate the round 3-pin connector. Pull the connector straight apart—do not twist it.
  4. Check for backed-out, bent, or corroded pins. Spray with contact cleaner, let dry, align the directional arrows, and push the halves firmly together until fully seated.

Step 4: Perform the Manual Magnet Bypass Test

  1. Elevate the rear wheel and power on the display.
  2. Take a small, strong household refrigerator magnet in your hand.
  3. Wave the magnet back and forth across the sensor mark rapidly, maintaining a 2 mm gap.
  4. Watch the display speedometer. If the display registers a speed readout, the sensor and controller circuit are completely functional, confirming that your original spoke magnet was mispositioned, weak, or missing.
  5. If the display stays at 0.0 mph during the test, the sensor pickup or its cable is defective.

Stop Riding & Escalation Signs

Because Error 21 disables motor assist while leaving standard bicycle controls operational, it poses no mechanical danger. However, you should stop attempting DIY repairs and replace the hardware if:

  • The sensor wire is physically severed with exposed copper wires shorting together.
  • The sensor casing is cracked, broken, or has water trapped inside its housing.

Replacement Bafang speed sensors are affordable, standardized, and plug directly into the motor harness without requiring controller reprogramming. If installing a brand-new sensor fails to resolve Error 21, the internal speed-sensing input port on the motor controller has failed, necessitating a controller replacement.