Two-hand gauge (biaxial stepper)
Drive both hands of a biaxial stepper from two knobs, as a speedometer and a tachometer share one dial.
Motors · Intermediate
In a real product: Car instrument cluster (Automotive): The speedometer and tachometer needles are steppers driven from the car's data.
Car instrument clusters and some clocks put two hands on one centre: a biaxial stepper is two motors with concentric shafts. Each hand here follows a potentiometer.
What you'll learn
- Driving two bipolar steppers with the Stepper library
- Closing the loop in software: step towards a target position
- Mapping an analog input onto an angle
How it works
Each motor has its own pair of coils: A1/B1 turn the outer hand and A2/B2 the inner one. A real stepper needs a driver for its coil current; the simulation lets the pins drive the coils directly so the wiring stays readable.
The sketch keeps where each hand is, in steps. Every loop it reads the knobs, maps 0–1023 onto 0–150 steps (270°) and moves each hand one step towards its target. Moving a step at a time keeps both hands moving together instead of one waiting for the other.
Try this
- Turn the knobs while it runs: each hand follows its knob.
- Make the hands move faster when they are far from the target, and slower as they arrive.
- Add a home position: start by driving both hands to 0.
sketch.ino
// A biaxial stepper: the outer hand (pins 4-7) follows the knob on A0, the inner hand (pins 8-11) the knob on A1.
#include <Stepper.h>
const int STEPS = 200;
Stepper outer(STEPS, 4, 5, 6, 7);
Stepper inner(STEPS, 8, 9, 10, 11);
int outerAt = 0, innerAt = 0;
void follow(Stepper &motor, int &at, int knob) {
int target = map(analogRead(knob), 0, 1023, 0, 150);
if (target > at) { motor.step(1); at++; }
else if (target < at) { motor.step(-1); at--; }
}
void setup() {
outer.setSpeed(60);
inner.setSpeed(60);
}
void loop() {
follow(outer, outerAt, A0);
follow(inner, innerAt, A1);
}