Example Code for Arduino-Get Liquid Level

Last revision 2026/01/15

This example is to get liquid level. (Liquid Level Sensor-XKC-Y25-T12V)

Hardware Preparation

Software Preparation

Wiring Diagram

sen0204 Gravity: Non-contact Digital Water / Liquid Level Sensor For Arduino Connection Diagram sen0204 Gravity: Non-contact Digital Water / Liquid Level Sensor For Arduino Connection Diagram sen0204 Gravity: Non-contact Digital Water / Liquid Level Sensor For Arduino Connection Diagram

Other Preparation Work

If using V2.0 version: Open the sensor back cover and use a small screwdriver to adjust the sensitivity knob.

  • Turn counterclockwise to increase sensitivity.
  • Turn clockwise to decrease sensitivity.

Sample Code

/*!
 * @file  SEN0204.ino
 * @brief  This example is to get liquid level. (Liquid Level Sensor-XKC-Y25-T12V)
 * @copyright  Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @license  The MIT License (MIT)
 * @author  jackli([email protected])
 * @version  V1.0
 * @date  2016-1-30
 */

int liquidLevel = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(5, INPUT);
}

void loop()
{
  liquidLevel = digitalRead(5);
  Serial.print("liquidLevel= "); Serial.println(liquidLevel, DEC);
  delay(500);
}

Result

If the liquid level sensor detects the presence of liquid, it will output HIGH and turn the LED ON. If no liquid is detected it output LOW and turn the LED off.

Additional Information

Touble Shooting

Symptom Possible Cause Solution
No reaction when powered on(the indicator keeps off when the liquid level reached the induction point, no reaction when adjusting sensitivity) 1.Power connection problem Check and connect the power supply properly
2.The negative and positive are disconnected Connect the power properly
3.Power module is damaged Change the power module
4.Sensitivity is too low Increase the sensitivity
The indicator always keeps on 1.Sensitivity is too high Decrease the sensitivity
2.There are impurities in the inductor, or other metal objects near the inductor Clean the inductor, and keep it away from other metal objects
3.The liquid container is not insulative completely Change the container or drill mount holes on the container to install the inductor

Was this article helpful?

TOP