Example Code for Arduino-Liquid Level Detection

Last revision 2026/01/12

This example is to get liquid level. (Liquid Level Sensor-FS-IR02)

Hardware Preparation

  • DFRduino UNO x1
  • Liquid Level Sensor-FS-IR02 x1

Software Preparation

Sample Code

/*!
 * @file  SEN0205.ino
 * @brief  This example is to get liquid level. (Liquid Level Sensor-FS-IR02)
 * @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

Installation

When liquid comes in to contact with the sensor probe the microcontroller will output HIGH logic. When the liquid is not in contact with the probe the microcontroller will output LOW logic.

Additional Information




SEN0205 Photoelectric Water Installation

Avoid placing the sensor near bright lights or in direct sunlight as these can cause interference.

Was this article helpful?

TOP