Same-day dispatch before 2 PM · Free delivery over ₹999 · GST invoices Get the appPrices incl. GST
Geekobot
Snap & SendNEWGeeko AIWhere's myOrder
Log in
Products
  • Projects
    • Component guidesHow parts work, with code you can run
    • Learning pathsFrom your first LED to your first robot
    • Workshops & eventsOnline sessions for makers and classes
    • ElectrolarkFree guided builds, simulator and certificates
    • Students & teachersStudent discount and classroom help
    • CommunityShare builds and ask other makers
    • CalculatorsOhm's law, LED resistor, 555 and 100+ more
    • Circuit builderWire parts and run the circuit, powered by Electrolark
    • Geeko AIAsk what to buy or how to wire it
    • Snap & SendPhotograph a part or list, we find it
    • Part finderAnswer a few questions, get the right part
    • Compatibility checkWill these two parts work together?
    • Compare partsSpecs side by side
    • Business & bulk ordersGST invoices, credit and volume prices
    • Request a quotationSend your list, get a quote
    • Classroom kitsPer-student kits and lab bundles
    • Gift cardsFor students, teams and events
  • Atal Tinkering Lab
BOM to cart
Geekobot

Components, kits and know-how for makers, students, engineers, labs and businesses across India.

Ask Geeko AIOrders, parts and projects, any timeEmail supportReply within 1 working dayGet the Geekobot appAdd it to your home screen, free

Follow us

Shop

  • Boards & SBCs
  • Sensors & Modules
  • IoT & Wireless
  • Drone & FPV
  • 3D Printing
  • Filaments & Resins
  • Motors & Drivers
  • Power & Batteries
  • Semiconductors
  • Passive
  • Displays & LEDs
  • Switches & Relays
  • Wires & Cables
  • Prototyping
  • Tools & Test
  • Robotics
  • STEM Kits
  • Atal Tinkering Lab
  • Mechanical Parts
  • Audio

Orders

  • Track your order
  • Help & support
  • Shipping and delivery
  • Refunds and cancellation
  • Contact us

Learn

  • Projects
  • Geeko AI project assistant
  • Learning paths
  • Guides
  • Calculators
  • Electrolark: free guided builds

Part tools

  • Part finder
  • Compare parts
  • Will it work with my board?

Institutions

  • Classroom kits
  • Atal Tinkering Lab
  • Students & teachers
  • Workshops & Events

Business

  • Business & education
  • Request a quotation
  • BOM bulk upload
  • Quick order by SKU

Company

  • About Geekobot
  • Community
  • Gift cards
  • Terms & conditions
  • Privacy policy
  • Product directory
  • Sitemap

© 2026 Geekobot, a trade name of OLatus Systems Private Limited. All rights reserved.

20, 1st Floor, Neeladri Complex, 10th Cross, Sampige Rd, 2nd Main, Malleshwaram, Bengaluru, Karnataka 560003 · GSTIN 29AACCO0462F1ZM

+91 91810 15607 · connect@geekobot.in · Monday to Saturday, 10 AM to 2 PM IST

UPI · CARDS · NETBANKING · GST INVOICES

ShopProjectsGeeko AIGuides
Compare 0 parts →
Log in

Shop by category

Shop all components
  • Boards & SBCs1,910 products
    • Alternative Single Board Computers
    • Arduino Ecosystem
    • FPGA & Logic Boards
    • Microcontroller & Wireless Boards
    View all
  • Sensors & Modules4,701 products
    • Biomedical & Heart Rate
    • Current, Voltage & Power
    • Force, Weight & Pressure
    • Gas, Weather & Environmental
    View all
  • IoT & Wireless2,314 products
    • RF Modules
    • RFID & NFC
    • Antennas & RF Accessories
    • Cameras & Smart Vision
    View all
  • Drone & FPV3,558 products
    • Flight Control & Navigation
    • FPV Video & Optics
    • Frames & Structural Parts
    • Motors & Propulsion
    View all
  • 3D Printing2,204 products
    • 3D Printers
    • 3D Scanners & Digitizers
    • Laser Engravers & Cutters
    • Material Management & Upgrades
    View all
  • Filaments & Resins1,472 products
    • Filaments
    • Photopolymer Resins
    View all
  • Motors & Drivers463 products
    • BLDC Motor Drivers
    • DC & Geared Motors
    • DC Motor Drivers
    • Linear Actuators & Solenoids
    View all
  • Power & Batteries557 products
    • Battery Holders & Connectors
    • Breadboard Power
    • Chargers & BMS
    • DC-DC Converters
    View all
  • Semiconductors295 products
    • Diodes & Rectifiers
    • Interface & RF Encoder ICs
    • Logic ICs (74xx)
    • Logic ICs (CD4000)
    View all
  • Passive67 products
    • Capacitors
    • Circuit Protection
    • Crystals & Oscillators
    • Inductors
    View all
  • Displays & LEDs572 products
    • 7-Segment & Dot Matrix
    • Addressable LEDs
    • Character LCDs
    • Graphic LCDs
    View all
  • Switches & Relays184 products
    • Keypads & Touch
    • Push Buttons & Tactile
    • Relay Modules
    • Relays
    View all
  • Wires & Cables233 products
    • Board-to-Wire Connectors
    • Crimp & Splice
    • Headers & Dupont
    • Heat Shrink & Sleeving
    View all
  • Prototyping101 products
    • Breadboards
    • Interface Modules
    • PCBs & Perfboards
    View all
  • Tools & Test717 products
    • Bench Power Supplies
    • Hand Tools
    • Measuring Tools
    • Meters & Testers
    View all
  • Robotics180 products
    • Humanoid & Legged Robots
    • Robot Chassis & Platforms
    • Robotic Arms & Grippers
    • Wheels & Casters
    View all
  • STEM Kits268 products
    • Arduino Learning Kits
    • Coding & IoT Kits
    • Early Coding (Ages 3-8)
    • Invention Kits
    View all
  • Atal Tinkering Lab196 products
    • Package 1: Electronics, Robotics, IoT and Sensors
    • Package 2: Rapid Prototyping Tools
    • Package 3: Mechanical, Electrical and Measurement Tools
    • Package 4: Power Supply, Accessories and Safety Equipment
    View all
  • Mechanical Parts212 products
    • Bearings
    • Brackets & Mounts
    • Couplers
    • Fasteners & Standoffs
    View all
  • Audio109 products
    • Amplifier Modules
    • Buzzers & Sirens
    • Speakers
    View all
  1. Home
  2. ›Guides
  3. ›Sensors
  4. ›FS-IR02 Photoelectric Liquid Level Sensor

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

I'm using
Wiring, code and the Run it panels follow your board.
On this page
Short answerWhat the Photoelectric liquid level sensor isPhotoelectric liquid level sensor pinoutWiring the Photoelectric liquid level sensorExample codeSetup and tuningWhat you needAlternatives and when to choose themCommon mistakesFAQsParts and next steps
Short answer

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.

  • Option 1DFRobot Gravity FS-IR02 Photoelectric Liquid Level Sensor – High Accuracy Probe with Interface Adapter₹909
  • Option 2FS-IR02B Photoelectric Water Level Sensor – 14mm Diameter, Polycarbonate, 5V DC₹339
  • Option 3Optical Liquid Level Sensor – 5V DC, 50cm Cable, Locking Nut Mount₹1,009
01

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.

02

Photoelectric liquid level sensor pinout

The pins on the Photoelectric liquid level sensor and what each one does.

PinFunction
Red / VCC5 V
Black / GNDGround
Yellow / OUTDigital output
PinFunction
Red / VCC
5 V
Black / GND
Ground
Yellow / OUT
Digital output
03

Wiring the Photoelectric liquid level sensor

Connect the Photoelectric liquid level sensor like this.

Photoelectric liquid level sensor pinArduino UnoESP32
VCC5V5V (VIN)
GNDGNDGND
OUTD2GPIO 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
04

Example code

Some versions go LOW in liquid; test in a glass of water and swap the comparison if needed.

Detect liquid and sound an alarm (Uno) · Arduino C++Verify & upload in Electrolark
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);
}
05

Setup and tuning

Wiring

VCC (often 5 V), GND and OUT to a digital pin; check the output logic.

Mounting

fit the sensor at the level you want to detect, through the tank wall with the seal.

Liquids

works with clear and most coloured liquids; very dark or foamy liquids can confuse it.

Cleaning

keep the tip clean, because residue can hold a false level.

Logic

decide whether the pump runs on high or low level in code.

06

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
07

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.
08

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.
09

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

  • DFRobot Gravity FS-IR02 Photoelectric Liquid Level Sensor – High Accuracy Probe with Interface Adapter
    ₹909View
  • FS-IR02B Photoelectric Water Level Sensor – 14mm Diameter, Polycarbonate, 5V DC
    ₹339View
  • Optical Liquid Level Sensor – 5V DC, 50cm Cable, Locking Nut Mount
    ₹1,009View
  • Uno R3 Development Board (No Cable)
    ₹359View
  • ESP32-WROOM-32 38-Pin Development Board
    ₹389View
  • Buzzer Module 3.3–5V
    ₹27View
  • 5V Relay Module with Optocoupler
    ₹74View
  • R385 / R365 Diaphragm Water Pump 12V
    ₹220View
Shop Water, Liquid Level & Flow Sensors

Keep learning

Buying guideIntermediateLiquid Level SensorsThe right liquid level sensor depends on whether you need a single trip point or a continuous reading.3 min read · SensorsComponent guideBeginnerFloat Level Switch (Small Vertical, Side-Mount and Cable Float)A float switch has a float that rises with the liquid and moves a magnet past a reed switch (small floats) or tilts a switch inside the cable float (tank floats).5 min read · SensorsComponent guideBeginnerXKC-Y25 and XKC-Y26 Non-Contact Liquid Level SensorThe XKC-Y25 and XKC-Y26 detect liquid through the wall of a plastic or glass container, up to about 20 mm thick, using capacitance.4 min read · Sensors

Sources

  • DFRobot FS-IR02 photoelectric liquid level sensor wiki

Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.

On this page
Short answerWhat the Photoelectric liquid level sensor isPhotoelectric liquid level sensor pinoutWiring the Photoelectric liquid level sensorExample codeSetup and tuningWhat you needAlternatives and when to choose themCommon mistakesFAQsParts and next steps
Need a hand?Ask Geeko AI which part fits your project, or talk to the Geekobot team.Ask Geeko AIHelp & support

Parts for this guide (Arduino Uno)6 items · ₹2,443

DFRobot Gravity FS-IR02 Photoelectric Liquid Level Sensor – High Accuracy Probe with Interface Adapter · Optical Liquid Level Sensor – 5V DC, 50cm Cable, Locking Nut Mount · Buzzer Module 3.3–5V · 5V Relay Module with Optocoupler · R385 / R365 Diaphragm Water Pump 12V · Uno R3 CH340G ATmega328p Compatible Development Board

Run itChange the inputs and watch the output

The optical tip outputs HIGH when its glass cone is in liquid.

Buzzer OFF
Serial monitor9600 baud
Dry

A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.

Ask the Community

Ask a question