Source: https://mokxi.com/parts/encmotor
Updated: 2026-11-10

Part

# Gear motor with encoder

A gearbox motor with a two-channel Hall encoder on its back: count the edges on A and B for how far and how fast, and which way.

See every part

- 6 pins
- 7 settings
- In 1 project

Drawn live by the editor's own code, at the size you see it.

At a glance

## The Gear motor with encoder in brief

What it is, and every setting the properties panel gives it.

An encoder gear motor, the JGA25-370 or N20 kind from robot kits, is a small brushed motor and gearbox with a magnet disc and two Hall sensors on the back of the motor shaft. It has six wires: M1 and M2 go to a motor driver, never to a board pin, while VCC and GND power the encoder from 3.3 or 5 volts and A and B are its two outputs. Mokxi runs the motor on the same model as the plain DC motor, 200 rpm at the wheel on 6 volts with a 120 millisecond lag, and times each encoder edge to the modeled shaft. With 11 pulses per motor turn and a 30 to 1 gearbox, the wheel gives 330 pulses a turn on each channel, and A leads B going forward. On an Uno, put A on pin 2 or 3 and count it in an interrupt, since a loop() with a delay() misses most of the 1100 pulses a second. Forgetting the encoder’s supply is the other classic: the motor turns and the count stays at zero. Load on the shaft and stiction are not modeled.

Family

Outputs

Pins

6

voltage

6

rpm

200

resistance

6

inertia

120

back_emf

0.85

ppr

11

ratio

30

Pins

## 6 pins

Named as the editor names them, so a wire lands where you expect it.

Pin

Role

What it does

M1

Input or output

The motor. To a driver: a board pin cannot run it.

M2

Input or output

The motor. To a driver: a board pin cannot run it.

VCC

Input or output

The encoder's supply, 3.3 V to 5 V.

GND

Input or output

The encoder's ground.

A

Output

The two Hall outputs (C1 and C2 on some boards), driven from VCC.

B

Output

The two Hall outputs (C1 and C2 on some boards), driven from VCC.

How to use it

## How to use an encoder gear motor with an Arduino

The dosing pump example drives the motor from one channel of an L9110S on pins 5 and 6, powered from four AA cells, and gives the encoder its own 5 volts from the Uno. A goes to pin 2 and B to pin 3. attachInterrupt(digitalPinToInterrupt(2), onA, RISING) catches every rising edge of A, and reading B inside the handler gives the direction: low is forward, high is backward.

Keep the count in a volatile long and copy it between noInterrupts() and interrupts(), since a four-byte value can change halfway through a read on an Uno. A motor does not stop the instant it is told, so to land on a count, slow down for the last turn and brake a few pulses early, as the pump sketch does at 8 pulses to go.

Part pin

Board pin

A

Pin 2

B

Pin 3

VCC

5 V

GND

GND

M1

L9110S OA1

M2

L9110S OA2

On an ESP32 any GPIO takes an interrupt; power the encoder from 3.3 volts, since A and B swing to whatever its VCC is.

Hold the button

This is the simulator itself, running here. Click anything to open it in the editor.

Open this project in the editor Read the full tutorial

Counting the encoder with direction

How it is modeled

## What is true about the Gear motor with encoder, here

In its help article’s own words: what the simulation gets right, and where it stops.

### Modeled

The pulses follow the shaft. Each edge happens when the modeled shaft reaches it,
and the shaft chases the applied voltage with the motor's lag. So a sketch sees the
motor run up, coast after a brake, and slow when a battery sags, and can close a
speed or position loop on it. At the default 200 rpm that is 1100 pulses a second on
each channel.

Quadrature. The channels are exactly a quarter of a pulse apart, and the order
flips with the direction.

### Not modeled

What the plain motor leaves out: the load on the shaft and the flyback kick. The Hall sensors' own timing and uneven magnet poles are not modeled, so
the duty is exactly half and the phase exactly 90 degrees. The encoder is on the
motor side of the gearbox, as on the real motors, so gearbox backlash never reaches
it.

From Gear motor with encoder, in full.

Projects

## See the Gear motor with encoder in a project

One built-in project uses it. It opens in the editor, already wired.

Boards

## The boards it is shown on

This board has a built-in project with the Gear motor with encoder in it.

- Arduino Uno R3

More parts

## The rest of the bench

Every one of these is drawn and simulated the same way.

Full-size breadboard

A real 0.1 inch grid with the rails and the center channel, 63 columns wide.

Jumper wires

Drag from any pin or hole to any other. Corners snap, and you can drag them.

Power

A supply rail at the voltage you choose.

Ground

The other end of every circuit.

LED

Lights when current flows. Five colors, and the brightness is what your eye would see.

Filament lamp

A tungsten bulb in a holder: an inrush when it is switched on cold, tens of milliseconds to warm up, and dim on half its voltage.

Resistor

Any value you like, with the color bands drawn to match.

ESP32-C3-DevKitM-1

A RISC-V board that runs your firmware at 160 MHz on the real memory map.

Pushbutton

A 12 mm tactile switch. Hold it while the simulation runs.

Raspberry Pi Pico

The RP2040 board on our own Cortex-M0+ core. Pick a program and press Run.

Raspberry Pi Pico W

Raspberry Pi Pico W (RP2040). The same board and the same pinout as a Pico, with the CYW43439 on it. The WiFi is simulated (no radio; real internet through the Cloud panel’s switch), and the on-board LED, which hangs off that chip rather than off GP25, is driven through the same path. Everything else is the Pico.

Raspberry Pi 4 Model B

Raspberry Pi 4 Model B: the 40-pin header, driven by main.py with RPi.GPIO or gpiozero.

See every part

## Wire up the Gear motor with encoder

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.

Start building free Open the editor
