Component guide · Beginner · 3 min read
FS-IR02 Photoelectric Liquid Level Sensor

How It Works, Wiring and Code
By Geekobot Learning Team · Updated 29 Oct 2026
On this page
A photoelectric level sensor has an infrared LED and receiver behind a clear prism tip. In air, light reflects back to the receiver; when liquid covers the tip, light escapes into the liquid and the output changes. With no moving parts it suits small tanks, coffee machines and dosing systems. It detects a single point and is mounted through the tank wall.
Key specs at a glance
- Principle
- Total internal reflection in a prism tip
- Supply
- 5 V DC
- Output
- Digital high/low (DFRobot board) or open collector
- Response
- Under 50 ms
- Body
- Polycarbonate, threaded with locking nut
- Media
- Clear and moderately dirty water, oils; not thick foam
Models in this guide
These are alternatives. Pick the one that fits your project; you only need one.
What the Photoelectric liquid level sensor is
Photoelectric liquid level sensors use an infrared LED and receiver in a clear tip to detect whether liquid covers the tip, giving a simple on or off level signal.
Because the sensor looks for light escaping into the liquid, droplets clinging to the tip or heavy scale can give false readings. Mount it horizontally or angled down so liquid drains off the tip.
The DFRobot Gravity version includes a small interface board that gives a clean digital signal for Arduino.
Photoelectric liquid level sensor pinout
The pins on the Photoelectric liquid level sensor and what each one does.
| Pin | Function |
|---|---|
| Red / VCC | 5 V |
| Black / GND | Ground |
| Yellow / OUT | Digital output |
- Red / VCC
- 5 V
- Black / GND
- Ground
- Yellow / OUT
- Digital output
Wiring the Photoelectric liquid level sensor
Connect the Photoelectric liquid level sensor like this.
| Photoelectric liquid level sensor pin | Arduino Uno | ESP32 |
|---|---|---|
| VCC | 5V | 5V (VIN) |
| GND | GND | GND |
| OUT | D2 | GPIO 27 via divider if output is 5 V |
- VCC
- Arduino Uno:
- 5V
- ESP32:
- 5V (VIN)
- GND
- Arduino Uno:
- GND
- ESP32:
- GND
- OUT
- Arduino Uno:
- D2
- ESP32:
- GPIO 27 via divider if output is 5 V
Example code
Some versions go LOW in liquid; test in a glass of water and swap the comparison if needed.
const int SENSOR = 2, BUZZER = 8;
void setup() { pinMode(SENSOR, INPUT); pinMode(BUZZER, OUTPUT); Serial.begin(9600); }
void loop() {
bool liquid = digitalRead(SENSOR) == HIGH; // check your version's logic
digitalWrite(BUZZER, liquid);
Serial.println(liquid ? "Liquid at sensor" : "Dry");
delay(200);
}Setup and tuning
VCC (often 5 V), GND and OUT to a digital pin; check the output logic.
fit the sensor at the level you want to detect, through the tank wall with the seal.
works with clear and most coloured liquids; very dark or foamy liquids can confuse it.
keep the tip clean, because residue can hold a false level.
decide whether the pump runs on high or low level in code.
What you need
Shop this list7 of 8 found in our store · ₹2,967
DFRobot Gravity FS-IR02 Photoelectric Liquid Level Sensor – High Accuracy Probe with Interface Adapter: the part this guide coversDFRobot Gravity FS-IR02 Photoelectric Liquid Level Sensor – High Accuracy Probe with Interface Adapter₹909
FS-IR02B Photoelectric Water Level Sensor – 14mm Diameter, Polycarbonate, 5V DC: another version this guide coversFS-IR02B Photoelectric Water Level Sensor – 14mm Diameter, Polycarbonate, 5V DC₹339
Generic Optical Liquid Level Sensor – 5V DC, 50cm Cable, Locking Nut Mount: another version this guide coversOptical Liquid Level Sensor – 5V DC, 50cm Cable, Locking Nut Mount₹1,009- Uno R3 development board: the controller used in the wiring tableFind this part
ESP32-WROOM-32 38-pin development board: for Wi-Fi logging and dashboardsESP32-WROOM-32 38-Pin Development Board₹389
Buzzer module 3.3-5 V: for an audible alarmBuzzer Module 3.3–5V₹27
5V relay module with optocoupler: to switch a pump or valve5V Relay Module with Optocoupler₹74
R385 diaphragm water pump 12V: a pump to controlR385 / R365 Diaphragm Water Pump 12V₹220
Alternatives and when to choose them
- Float level switch: mechanical alternative.
- XKC-Y25 non-contact sensor: mounts outside the tank.
- Liquid level sensors: every method compared.
Common mistakes to avoid
- Mounting the tip horizontally where drops collect.
- Driving a pump straight from the output.
- Using it in foamy liquids without testing.
- Skipping cleaning.
Frequently asked questions
How does a photoelectric level sensor work?
Light reflects inside the tip in air, and escapes into liquid, so the receiver sees the difference.
Does it work with milk or oil?
Usually yes, but very dark or sticky liquids may need testing.
Why does it read liquid when the tank is empty?
Residue or droplets on the tip; clean it and mount it so liquid drains off.
Can it switch a pump directly?
No. Use the output to drive a relay or MOSFET for the pump.
Is it better than a float switch?
It has no moving parts, so it does not stick, but it needs power.
Parts for this guide
Keep learning
Sources
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.

