Sharp GP2Y0A21 IR distance (10-80 cm) with ESP32

Supply 5 V Bus ANALOG Measures distance
VOGNDVCC

Pins and ESP32 wiring

PinRoleESP32 pinNotes
VOAnalog outputD34Output about 0.4 V (80 cm) to 3.1 V (10 cm). To an ADC pin (prefer ADC1: GPIO 32 to 39)
GNDGroundGND
VCCPowerVINNeeds 5 V: use VIN

Suggested wiring for the 30-pin ESP32 DevKit, avoiding flash, input-only and strapping pins. BoardPilot checks it for you as you wire.

This module is sold for 5 V. Its outputs may be 5 V: use a level shifter or a voltage divider on ESP32 inputs.

Starter code (Arduino)

void setup() { Serial.begin(115200); }

void loop() {
  int mv = analogReadMilliVolts(34);  // VO on GPIO 34
  Serial.println(mv);
  delay(200);
}

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.