Component guide · Intermediate · 3 min read
25mm and 37mm DC Gear Motors with Hall Encoder

Wiring and PID Code
By Geekobot Learning Team · Updated 29 Oct 2026
On this page
The 25 mm (JGA25-370 style) and 37 mm metal gear motors with a Hall encoder are the standard wheel motors for robots that need speed or distance control. They run from 6 or 12 V at 12 to 1000 RPM, and the two-channel magnetic encoder on the back gives 11 pulses per motor turn per channel, multiplied by the gear ratio at the output shaft.
Key specs at a glance
- Diameter
- 25 mm or 37 mm gearbox, 4 mm or 6 mm D-shaft
- Voltage
- 6 V or 12 V versions
- Speed
- About 12 to 1000 RPM depending on ratio
- Stall current
- About 1 to 2 A (25 mm), 3 to 5 A (37 mm) at 12 V
- Encoder
- Hall, 2 channels (A/B), 11 pulses per motor turn per channel, 3.3 to 5 V
- Wires
- 6: motor + and -, encoder VCC, GND, A, B
Models in this guide
These are alternatives. Pick the one that fits your project; you only need one.
Option 1Metal Gear DC Motor with Hall Encoder (25mm / 37mm)₹480
Option 225mm DC Metal Encoder Gearmotor (by Voltage and RPM)₹1,180
What the 25mm encoder gear motor is
With the encoder you can drive both wheels at exactly the same speed, turn by a set angle and measure distance. A PID loop compares the measured speed with the target and corrects the PWM many times a second.
Output pulses per revolution = 11 x gear ratio (x4 if you count every edge of both channels). A 30:1 motor gives 330 pulses per channel per wheel turn.
25mm encoder gear motor pinout
The pins on the 25mm encoder gear motor and what each one does.
| Pin | Function |
|---|---|
| Red / white (M+ / M-) | Motor terminals |
| Blue (or black) VCC | Encoder power, 3.3 to 5 V |
| Green / black GND | Encoder ground |
| Yellow (A) | Encoder channel A |
| White / green (B) | Encoder channel B |
- Red / white (M+ / M-)
- Motor terminals
- Blue (or black) VCC
- Encoder power, 3.3 to 5 V
- Green / black GND
- Encoder ground
- Yellow (A)
- Encoder channel A
- White / green (B)
- Encoder channel B
Wiring the 25mm encoder gear motor
Wire colours vary between makers, so check the label on the encoder board. Use a driver rated above the stall current: a TB6612FNG for 25 mm motors at 6 V, an L298N or MDD3A for 12 V, and a larger driver for 37 mm motors.
| 25mm encoder gear motor pin | Arduino Uno | ESP32 |
|---|---|---|
| M+ / M- | Driver OUT1 / OUT2 | Driver OUT1 / OUT2 |
| Encoder VCC / GND | 5V / GND | 3V3 / GND |
| Encoder A | D2 | GPIO 34 |
| Encoder B | D3 | GPIO 35 |
- M+ / M-
- Arduino Uno:
- Driver OUT1 / OUT2
- ESP32:
- Driver OUT1 / OUT2
- Encoder VCC / GND
- Arduino Uno:
- 5V / GND
- ESP32:
- 3V3 / GND
- Encoder A
- Arduino Uno:
- D2
- ESP32:
- GPIO 34
- Encoder B
- Arduino Uno:
- D3
- ESP32:
- GPIO 35
Example code
Tune the 1.2 (P) and 4.0 (I) gains for your motor and load. Set PPR to 11 times your gear ratio.
const int ENC_A = 2, ENC_B = 3, PWM = 5, IN1 = 7, IN2 = 8;
const float PPR = 11 * 30.0; // 11 pulses x 30:1 gearbox
volatile long ticks = 0;
void onA() { ticks += digitalRead(ENC_B) ? -1 : 1; }
float target = 120, integ = 0; // RPM
void setup() {
Serial.begin(115200);
pinMode(ENC_A, INPUT_PULLUP); pinMode(ENC_B, INPUT_PULLUP);
pinMode(PWM, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW);
attachInterrupt(digitalPinToInterrupt(ENC_A), onA, RISING);
}
void loop() {
noInterrupts(); long t = ticks; ticks = 0; interrupts();
float rpm = t / PPR * 1200.0; // per 50 ms
float err = target - rpm;
integ = constrain(integ + err * 0.05, -255, 255);
int out = constrain(1.2 * err + 4.0 * integ, 0, 255);
analogWrite(PWM, out);
Serial.println(rpm);
delay(50);
}Setup and tuning
run at a known speed, count encoder pulses for one wheel turn, divide by 11.
if the count goes negative when driving forward, swap A and B.
use the matching 25 mm or 37 mm bracket and a 4 or 6 mm coupling hub for wheels.
twist the encoder wires and keep them away from the motor wires.
What you need
Shop this list6 of 7 found in our store · ₹2,680
Metal Gear DC Motor with Hall Encoder (25mm / 37mm): the part this guide coversMetal Gear DC Motor with Hall Encoder (25mm / 37mm)₹480
25mm DC Metal Encoder Gearmotor (by Voltage and RPM): another version this guide covers25mm DC Metal Encoder Gearmotor (by Voltage and RPM)₹1,180- Uno R3 development board: the controller used in the wiring tableFind this part
ESP32-WROOM-32 38-pin development board: for Wi-Fi logging and dashboardsESP32-WROOM-32 38-Pin Development Board₹389
L298N motor driver module: a simple driver for two motorsL298N Dual H-Bridge Motor Driver Module₹128Closest match, check the specs
TB6612FNG motor driver module: an efficient driver for two small motorsTB6612FNG Dual Motor Driver Module₹130Closest match, check the specs
7.4V 2S Li-Po battery: to power the motors7.4V 3800mAh 2S Li-Po Battery (114253)₹373
Alternatives and when to choose them
- N20 gear motor: the smaller encoder motor.
- Motor encoders: quadrature counting explained.
- Cytron MDD10A: a driver for larger 37 mm motors.
Common mistakes to avoid
- Guessing the wire colours instead of checking the label.
- Using an L298N on a 37 mm motor with a 5 A stall current.
- Forgetting to multiply 11 by the gear ratio.
- Polling encoder pins in loop() instead of using interrupts.
Frequently asked questions
How many pulses per revolution?
11 per motor turn per channel, times the gear ratio at the output shaft; four times that if you count all edges.
6 V or 12 V?
Match your battery: 12 V motors on 3S Li-ion or 12 V packs, 6 V motors on 2S.
Can I use the encoder at 3.3 V?
Yes, power it from 3.3 V for an ESP32 or Pi.
Why is my speed reading jumpy?
The sample time is short; average over 100 ms or count both edges.
What wheels fit?
Wheels with a 4 mm (25 mm motor) or 6 mm (37 mm motor) hub, or a coupling hub.
Parts for this guide
Keep learning
Sources
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.

