XKC-Y25-V + ESP32: Wire Colours, Wiring Diagram and Working Code

XKC-Y25-V + ESP32: Wire Colours, Wiring Diagram and Working Code

Quick answer: connect brown to a 5 V supply, blue to GND, and the yellow output to GPIO27 through a small Schottky diode, with the diode's band toward the sensor and the GPIO's internal pull-up enabled. Leave the black wire unconnected so the output goes high when liquid is present. Never wire yellow straight to the ESP32: the sensor runs from 5–24 V and its output is not a 3.3 V signal.

White round XKC-Y25-V non-contact liquid level sensor with a black cable sold by Compoden
XKC-Y25-V. The label on the sensor prints its wire legend: 5-24V, OUT, GND and M. Distributor-permissioned Compoden catalogue photo.

What are the XKC-Y25-V wire colours?

The XKC-Y25-V has a four-wire cable, not a header. The maker's datasheet lists the terminal sequence, and the label on the sensor in our listing photo prints the same legend (brown, yellow, blue, black above 5-24V, OUT, GND, M).

XKC-Y25-V wires (maker datasheet, confirmed by the sensor's printed label)
Wire Function Source
Brown Supply positive, 5–24 V DC Datasheet + sensor label
Blue Supply negative (0 V) Datasheet + sensor label
Yellow Signal output, high/low level Datasheet + sensor label
Black (M) Mode: floating = output high when liquid is sensed; tied to 0 V = inverted Datasheet + sensor label

How do you wire the XKC-Y25-V to an ESP32?

XKC-Y25-V to ESP32 DevKit (30-pin) wiring
XKC-Y25-V pin ESP32 DevKit pin Why this pin
Brown 5 V supply (VIN/5V pin or a separate 5–12 V supply) Datasheet minimum is 5 V
Blue GND Must be shared with the ESP32 ground
Yellow GPIO27 through a Schottky diode (band toward yellow), INPUT_PULLUP The diode blocks the sensor's high level; the ESP32 pull-up provides 3.3 V
Black (M) Not connected Positive output: HIGH = liquid

Why the diode works: when the sensor pulls its output low, current flows from the GPIO pull-up through the diode and the pin reads LOW. When the sensor's output is high, the diode is reverse-biased, nothing from the sensor reaches the pin, and the internal pull-up holds it at 3.3 V. Use a Schottky type (for example 1N5819) so the LOW level stays well under the ESP32's logic threshold. A bidirectional logic-level shifter module is an equally safe alternative.

Which ESP32 pins should you avoid?

Every GPIO choice on this page follows the same rules for the 30-pin ESP32-WROOM-32 DevKit (the board Compoden stocks as the ESP32 30-pin CP2102 development board). Espressif's ESP32 GPIO reference is the source:

  • Never use GPIO6–11. They connect to the module's SPI flash.
  • Avoid the strapping pins GPIO0, 2, 5, 12 and 15 for sensors. Their level at reset decides boot mode and flash voltage, so a sensor holding one of them can stop the board booting. GPIO0 is not even on the 30-pin header; it only goes to the BOOT button.
  • GPIO34, 35, 36 and 39 are input-only and have no internal pull-up or pull-down. They are ideal for analog inputs and useless for outputs or clocks.
  • Use ADC1 (GPIO32–39) for analog readings. ADC2 pins (GPIO0, 2, 4, 12–15, 25–27) cannot be read while Wi-Fi is running.
  • Leave GPIO1 and GPIO3 alone. They carry the USB serial link used for uploads and the Serial Monitor.
  • ESP32 GPIOs are 3.3 V only. They are not 5 V tolerant.

What voltage does the XKC-Y25-V need, and is its output safe for an ESP32?

The datasheet specifies 5–24 V DC, at most 5 mA, and a 500 ms response time. It does not give the output's exact high-level voltage, so assume it can approach the supply voltage. That is the reason for the diode.

On many ESP32 DevKit boards the VIN/5V pin carries USB power through a protection diode, so it can sit a little below 5 V. If detection is unreliable on USB power, feed the sensor from a separate regulated 5–12 V supply and join its ground to the ESP32 ground.

Working Arduino code for the XKC-Y25-V on ESP32

No library is needed. With the black wire floating, the datasheet says the output is high when liquid is sensed and low when it is not, so the sketch treats HIGH as “liquid detected”.

// XKC-Y25-V non-contact liquid level sensor + ESP32 DevKit (ESP32-WROOM-32)
// Wiring: brown -> 5 V supply, blue -> GND (shared with the ESP32),
//         yellow -> Schottky diode -> GPIO27 (diode band/cathode toward the yellow wire),
//         black (M, mode) -> leave unconnected = output HIGH when liquid is sensed.
// The diode keeps the sensor's 5-24 V output off the 3.3 V GPIO: the ESP32's internal
// pull-up supplies the HIGH level and the sensor pulls the pin LOW through the diode.
const int LEVEL_PIN = 27;

void setup() {
  Serial.begin(115200);
  pinMode(LEVEL_PIN, INPUT_PULLUP);
}

void loop() {
  bool liquid = digitalRead(LEVEL_PIN) == HIGH;   // black wire floating = positive output
  Serial.println(liquid ? "Liquid detected" : "No liquid");
  delay(500);
}

Compile check: this exact sketch compiled for the esp32:esp32:esp32 board (ESP32 Dev Module, ESP32 Arduino core 3.3.10) on 5 October 2026. A clean compile proves the code and libraries agree. It does not prove your wiring, so test it on the bench with the Serial Monitor at 115200 baud.

Common mistakes with the XKC-Y25-V and ESP32

  • Yellow wired straight to a GPIO. The sensor's high level is not limited to 3.3 V.
  • Black wire grounded by accident. That inverts the output, so the code reports the opposite.
  • Air gap between sensor and tank. The datasheet asks for the face to be glued tight to the wall, with any gap under 0.5 mm.
  • Metal tank. The listing notes that metal blocks the sensing field; use plastic or glass walls.
  • Wall too thick. The datasheet allows up to 20 mm of container wall.
  • No shared ground when using a separate supply. Without it, the GPIO reading floats.

Where can you get the parts?

Parts used in this guide (Compoden catalogue)
Item Role Link
XKC-Y25-V non-contact liquid level sensor Detects liquid through a non-metallic wall View XKC-Y25-V
ESP32 30-pin CP2102 development board Controller with Wi-Fi and Bluetooth View ESP32 board

Want this sensor in a bigger build? Describe the whole device in Soldr, for example “I want to build an overhead tank overflow alarm with an ESP32 and an XKC-Y25-V”. Soldr returns the exact parts, a wiring map and code that compiles, all from one parts list, so the pins in the code match the pins in the wiring. Compoden stocks the parts and delivers across India.

Sources

Wire colours, supply range, output modes, wall thickness and mounting: XingKeChuang XKC-Y25-V datasheet (retailer-hosted copy of the maker document). ESP32 pin rules: Espressif ESP32 GPIO reference. Product photo and listing: Compoden XKC-Y25-V.

Related ESP32 wiring guides

Frequently asked questions

Can I connect the XKC-Y25-V output directly to an ESP32?

No. The sensor runs from 5 to 24 V and the datasheet does not limit its high output to 3.3 V. Use a Schottky diode with the GPIO's internal pull-up, or a logic-level shifter.

What do the four XKC-Y25-V wires do?

Brown is supply positive (5 to 24 V), blue is ground, yellow is the output and black selects the output mode. Leave black floating for a high output when liquid is present.

Does the XKC-Y25-V work through a metal tank?

No. It senses through non-metallic walls such as plastic or glass, up to 20 mm thick according to the datasheet, mounted flush against the wall.

Back to blog

Open this project in the Soldr app → What is Soldr.ai → parts, wiring and code for what this guide builds