Example Code for Arduino-Liquid Level Detection
Detect the status of IO3 and print it in serial port. Users can learn how to use the 5V Non-contact Liquid Level Sensor with Arduino to detect liquid levels.
Hardware Preparation
- DFRduino UNO R3 (or similar) × 1
- 5V Non-contact Liquid Level Sensor × 1
Software Preparation
Wiring Diagram

Sample Code
/*!
* @File Infrared_Approach_Sensor.ino
* @brief Detect the status of IO3 and print it in serial port
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @licence The MIT License (MIT)
* @version V1.0
* @date 2021-03-15
*/
int OUT = 3;
int i = 0;
void setup()
{
Serial.begin(9600);
pinMode(OUT, INPUT);
}
void loop()
{
i = digitalRead (OUT);
Serial.println(i);
delay(5);
}
Result
Read the status of IO3 in real time. When the sensor detects the existence of a liquid at a particular level in a container, the serial port prints 0. Otherwise, the serial port prints 1.

Was this article helpful?
