Component guide · Beginner · 3 min read
N20 Micro Metal Gear Motor

RPM, Wiring, Encoder and Code
By Geekobot Learning Team · Updated 29 Oct 2026
On this page
The N20 is a 12 mm micro metal gear motor with a 3 mm D-shaft, used in mini robots, line followers, locks and small mechanisms. It comes in 3, 6 and 12 V versions with gear ratios giving about 30 to 1000 RPM. The encoder version adds a magnetic Hall encoder (two channels) on the back so you can measure speed and distance.
Key specs at a glance
- Size
- 12 x 10 mm gearbox, 3 mm D-shaft, about 25 to 35 mm long
- Voltage
- 3, 6 or 12 V versions
- Speed
- About 30 to 1000 RPM depending on gear ratio
- Current
- About 0.05 A free running, 0.5 to 1.6 A stall (6 V)
- Encoder (GB-MOTR-0151)
- Magnetic Hall, 2 channels, 7 pulses per motor turn per channel (times the gear ratio at the shaft)
- Gears
- All-metal spur gears
Models in this guide
These are alternatives. Pick the one that fits your project; you only need one.
Option 1N20 Micro Metal Gear Motor₹229
Option 2Waveshare N20 DC Gear Motor with Magnetic Hall Encoder₹460
What the N20 gear motor is
Lower RPM means more torque from the same motor. For a small robot car with 34 mm wheels, 200 to 300 RPM at 6 V is a good start; for a line follower, 500 to 1000 RPM.
The encoder board has six wires: two motor wires, encoder power and ground, and the A and B channels. Counting A and B gives speed and direction for PID speed control.
N20 gear motor pinout
The pins on the N20 gear motor and what each one does.
| Pin | Function |
|---|---|
| M1 / M2 | Motor terminals (swap to reverse) |
| VCC | Encoder power, 3.3 to 5 V |
| GND | Encoder ground |
| A (C1) | Encoder channel A |
| B (C2) | Encoder channel B |
- M1 / M2
- Motor terminals (swap to reverse)
- VCC
- Encoder power, 3.3 to 5 V
- GND
- Encoder ground
- A (C1)
- Encoder channel A
- B (C2)
- Encoder channel B
Wiring the N20 gear motor
Drive the motor through a driver such as a TB6612FNG or DRV8833, never straight from a GPIO pin. On ESP32 GPIO 34 and 35 are input-only, which suits encoder signals.
| N20 gear motor pin | Arduino Uno | ESP32 |
|---|---|---|
| M1 / M2 | TB6612 AO1 / AO2 | TB6612 AO1 / AO2 |
| Encoder VCC / GND | 5V / GND | 3V3 / GND |
| Encoder A | D2 (interrupt) | GPIO 34 |
| Encoder B | D4 | GPIO 35 |
- M1 / M2
- Arduino Uno:
- TB6612 AO1 / AO2
- ESP32:
- TB6612 AO1 / AO2
- Encoder VCC / GND
- Arduino Uno:
- 5V / GND
- ESP32:
- 3V3 / GND
- Encoder A
- Arduino Uno:
- D2 (interrupt)
- ESP32:
- GPIO 34
- Encoder B
- Arduino Uno:
- D4
- ESP32:
- GPIO 35
Example code
This counts rising edges on channel A only; count both edges of A and B for four times the resolution. Change PPR to match your gear ratio.
const int ENC_A = 2, ENC_B = 4;
const float PPR = 7 * 100.0; // 7 pulses x gear ratio 100:1 (change to yours)
volatile long count = 0;
void onA() { count += digitalRead(ENC_B) ? -1 : 1; }
void setup() {
Serial.begin(115200);
pinMode(ENC_A, INPUT_PULLUP);
pinMode(ENC_B, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(ENC_A), onA, RISING);
}
void loop() {
noInterrupts(); long c = count; count = 0; interrupts();
float rpm = c / PPR * 600.0; // counts per 100 ms -> RPM
Serial.println(rpm);
delay(100);
}Setup and tuning
a 6 V N20 runs well from 2 AA cells less driver loss, or 1S Li-ion through a TB6612.
use N20 brackets with M1.6 screws; do not clamp the gearbox hard.
wheels need a 3 mm D-hole; press them on, do not hammer.
stalling a high-ratio N20 can strip the last gear; add a limit or current sense.
What you need
Shop this list5 of 7 found in our store · ₹1,257
N20 Micro Metal Gear Motor: the part this guide coversN20 Micro Metal Gear Motor₹229
Waveshare N20 DC Gear Motor with Magnetic Hall Encoder: another version this guide coversWaveshare N20 DC Gear Motor with Magnetic Hall Encoder₹460- 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
TB6612FNG motor driver module: an efficient driver for two small motorsTB6612FNG Dual Motor Driver Module₹130Closest match, check the specs- Wheel for BO and N20 motors: 3 mm D-shaft wheelsFind this part
Dupont jumper wires: for the connectionsDupont Jumper Wires (40 pcs)₹49Closest match, check the specs
Alternatives and when to choose them
- TT and BO gear motors: bigger, cheaper plastic-gear motors.
- Motor encoders: how encoders measure speed and position.
- DC motors: choosing motor size and speed.
Common mistakes to avoid
- Driving the motor straight from a GPIO pin.
- Picking a 12 V N20 for a 3.7 V robot.
- Leaving encoder pins floating without pull-ups.
- Stalling a 1000:1 gearbox until the gears strip.
Frequently asked questions
What RPM should I choose?
200 to 300 RPM for small robot cars, 500 to 1000 RPM for line followers, under 100 RPM for mechanisms.
How many pulses per turn does the encoder give?
7 per motor turn per channel; multiply by the gear ratio for the output shaft.
Can I run a 6 V N20 at 3.7 V?
Yes, slower and with less torque.
Which driver should I use?
A TB6612FNG or DRV8833 for two N20s; an L298N wastes too much voltage.
Does the shaft fit LEGO?
Not directly; use a 3 mm D-shaft adapter.
Parts for this guide
Projects that use it
Put this into practice: 1 step-by-step build in our project library uses parts from 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.


