N20 gear motor with hall encoder with ESP32

Supply 3.3-5 V Bus GPIO
M1GNDC1C2VCCM2

Pins and ESP32 wiring

PinRoleESP32 pinNotes
M1Not wired to the ESP32—Pin order varies between boards: match by the printed label. Motor. Never to an ESP32 pin: use a motor driver
GNDGroundGNDEncoder ground
C1Output (the part drives it)D25Encoder channel A
C2Output (the part drives it)D26Encoder channel B
VCCPower3V3Encoder supply 3.3 to 5 V: use 3V3 so the outputs stay at 3.3 V
M2Not 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

Try it in 3D in BoardPilot

BoardPilot Part data (JSON)

Related parts

Part data: CC BY 4.0, free to reuse with credit to BoardPilot.