Moving a magnetic (exercise bike control)

So here's what I've got: a spin bike with a flywheel that is controlled by magnetic resistance. The magnets sit in a u-shaped shoe which gets pushed down around the wheel using a knob - the knob is connected to a ~16tpi threaded rod which, with each full turn, lowers the magnetic around the wheel to create resistance.

What I'd love to be able to do is wire up two switches to control this, like gearing on a bike (though I will settle for two simple buttons!) And each press could be 1/4 turn. My first though was an actuator of some kind which, as it pushes forward, lowers the magnet. Finer control might be had with a small motor though, stepper or otherwise.

What do I need to get started? Is there any code that is already premade for doing something like this, that I could.adapt? Has anyone tried a similar project?

You first have to find out what hardware you need.
Probably a motor of sorts that you can connect to the existing knob - a stepper would be the easiest to control. Find one that has sufficient torque to turn the knob. Try to find a stepper with built-in control, again makes it easier for you. Make sure it can run both directions.
Find buttons that you like to do the control.
A nice project box that fits your Arduino.
And finally a few lines of code. Very easy - no need to worry about debouncing or anything. Code will look like this:

void setup() {
  // init stepper
  pinMode (upButton, INPUT_PULLUP);
  pinMode (downButton, INPUT_PULLUP);

void loop() {
  if (digitalRead(upButton) == LOW) {
  if (digitalRead(downButton) == LOW) {

That's all you need. May need some minor refinement in the stepper code.

I think even an ATtiny13 could do this, very easy control wise. Rigging up the motor to the bike and doing the wiring and making it look good is going to be the hard part.

Before choosing a motor measure the force required to turn the shaft that controls the position of the magnets - especially when the magnets are closest to the wheel. Magnetic forces can be very strong.

There is a simple idea for measuring torque in Stepper Motor Basics


A very good suggestions, thanks guys! I might take a photo to show what I’m up against - my first thought was to do what you describe, but then I started to think that a concealed mechanism would be a better approach (which is why i started thinking about actuators, which I thought might be easier than a stepper motor because of the torque issue).

Here’s a photo of what I’m looking at (sort of, this is a newer version of my bike)

You can see where the knob is, right between the rider’s legs… so it might not be a great place to put a motor unless I can get a small one and get a cover fabricated for it. The last photo shows where the magnet sits above the wheel - it has a hinge on one side and on the other is where the threaded rod pushes to lower it.

Is using an actuator tougher than a stepper motor, in terms of coding for it?

My ultimate dream would be to have the device be able to interface with Trainerroad or Zwift, as those programs can send a bluetooth 4.0 signal that raises/lowers resistance on so-called “smart trainers”. But I might be dreaming when it comes to getting that kind of functionality! If you have any tips/ideas, though…

Is using an actuator tougher than a stepper motor, in terms of coding for it?

Depends on the actuator and what driver libraries are available for the specific type. It can indeed be as simple as the code I gave before if you have a library that's doing all the hard work ready made.

The kind you need are basically screws with a DC motor attached to it, and some form of position feedback, probably an encoder attached to the motor.

Come to think of it, in your case a DC motor with encoder could be a better solution. When you gear them down you can get great torque out of a remarkably small motor - I don't think it matters much to you if it takes as much as a second at full speed to make a turn of the knob. Add an optical encoder for position feedback and you're there - just instead of asking the motor to do 1/4 turn, you have it do 1,000 turns or so (with a 1:4000 gearing).