N20 gear motor with hall encoder with ESP32
Supply 3.3-5 V
Bus GPIO
Pins and ESP32 wiring
| Pin | Role | ESP32 pin | Notes |
|---|---|---|---|
| M1 | Not wired to the ESP32 | — | Pin order varies between boards: match by the printed label. Motor. Never to an ESP32 pin: use a motor driver |
| GND | Ground | GND | Encoder ground |
| C1 | Output (the part drives it) | D25 | Encoder channel A |
| C2 | Output (the part drives it) | D26 | Encoder channel B |
| VCC | Power | 3V3 | Encoder supply 3.3 to 5 V: use 3V3 so the outputs stay at 3.3 V |
| M2 | Not wired to the ESP32 | — | Motor |
Suggested wiring for the 30-pin ESP32 DevKit, avoiding flash, input-only and strapping pins. BoardPilot checks it for you as you wire.
Starter code (Arduino)
void setup() {
Serial.begin(115200);
pinMode(25, INPUT); // C1
}
void loop() {
Serial.println(digitalRead(25));
delay(100);
}
Sources
- N20 micro gear motor with magnetic encoder (vendor datasheet), 6-pin connector M1 GND C1 C2 VCC M2
Try it in 3D in BoardPilot
Related parts
18650 Li-ion cell in holder28BYJ-48 stepper + ULN2003 driver433 MHz transmitter (FS1000A)74HC595 shift registerA4988 stepper driverActive buzzer
Part data: CC BY 4.0, free to reuse with credit to BoardPilot.