Maison » DIY Optical Liquid Level Sensor: Build & Parts Guide

DIY Optical Liquid Level Sensor: Build & Parts Guide

Juin 8, 2026

A diy optical liquid level sensor can be built in two practical ways: assemble your own optical head from an IR LED, Phototransistor, et la pointe prismatice, or start with a ready optical level module and focus on wiring, Montage, et étalonnage. The first path teaches you how photoelectric liquid detection really works. The second path is faster, nettoyeur, and usually more reliable for a working tank project.

This guide explains both routes, including parts, cost factors, mounting choices, calibration steps, common failure modes, and when it makes more sense to buy a finished sensor from HojellyTek instead of continuing a DIY build.

How an Optical Liquid Level Sensor Detects Wet and Dry States

An optical level sensor uses photoelectric sensing. Inside the sensor head, an infrared LED sends light into a clear prism or optical tip. A phototransistor, photodiode, or receiver detects the returned light.

Quand la pointe du prisme est dans l’air, the IR light reflects internally and returns strongly to the receiver. Lorsque le liquide recouvre le prisme, the light behavior changes because the liquid has a different refractive index than air. The receiver sees a lower or different signal, and the circuit converts that change into a wet/dry output.

For a deeper product-level explanation, voir HojellyTek’s Capteur de niveau optique Guide.

For DIY use, this means you are not measuring the full tank height. You are building a point-level detector: empty at this point, full at this point, overflow reached, pump protection level reached, or reservoir refill needed.

Choose Your DIY Build Path First

Path A: Use a Ready Optical Sensor Module

This is the easiest option for Arduino, ESP32, Raspberry Pi Pico, hobby automation, Aquariums, réservoirs d’eau, and small reservoirs. The optical head, emitter, Récepteur, Logement, and basic circuit are already built. You only handle the low-voltage supply, signal reading, Montage, et étalonnage.

A ready module is best when you want a working result quickly and do not need to design the optical geometry yourself.

Path B: Build the Optical Head from Parts

This is the educational route. You use an IR LED, phototransistor ou photodiode, resistors, a comparator or microcontroller input, and a prism or clear optical tip. It is useful for learning, custom shapes, or lab prototypes.

This route is harder because optical alignment, Blindage de la lumière ambiante, Étanchéité, prism clarity, and repeatable calibration all matter. A small change in angle or surface finish can change the reading.

Parts and Cost Planning Table

Exact prices vary by supplier, qualité, Matériau de logement, et quantité, so use this table as a planning guide rather than a price quotation.

Part or MaterialPurpose in the BuildDIY Cost ImpactWhat to Check Before Buying
IR LEDSends infrared light into the optical tipBasWavelength, viewing angle, package size, stable output
Phototransistor or photodiodeReceives reflected IR lightBasSensibilité, Vitesse de réponse, package alignment
Prism or clear optical tipCreates the wet/dry optical changeDouleur moyenneOptical clarity, forme, Compatibilité liquide, polish quality
RésistancesSet LED current and receiver signal levelBasCorrect values for your board voltage
Comparator or transistor stageConverts analog signal into stable digital outputLow to mediumThreshold adjustment, noise immunity
Arduino, ESP32, or MCU boardReads the signal and controls logicDouleur moyenneTension d’entrée, ADC/digital pin behavior
Ready optical level moduleReplaces separate LED, Récepteur, and prism designDouleur moyenneTension d’alimentation, Type de sortie, Étanchéité des câbles
Housing or enclosureProtects electronics from splashesDouleur moyenneWaterproofing, Sortie du câble, Résistance mécanique
Cable gland or sealed cableKeeps moisture away from wiringDouleur moyenneSeal quality, Soulagement de la déformation, tank environment
Filetage ou support de montageHolds the tip at the correct levelDouleur moyenneTaille du filetage, Épaisseur du mur, Orientation
Finished industrial sensorProduction-ready alternativeHigher upfront, lower rework riskProduction, matériel, Montage, Câble, OEM fit

The hidden cost in DIY is usually not the LED or receiver. It is waterproofing, Montage répétable, optical alignment, and time spent fixing false readings.

Assembly Route 1: Using a Ready Optical Module

For most builders, a ready module is the best starting point.

  1. Identify the low-voltage pins. Most simple modules provide power, terre, and signal. Some modules may provide digital output, Sortie analogique, ou les deux. Do not assume wire colors; check the supplier diagram.
  2. Connect only to a compatible low-voltage control board. Use Arduino, ESP32, a data logger, or a low-voltage PLC input where suitable. Do not connect the sensor directly to mains power or AC pump wiring.
  3. Test in air first. Read the dry-state output before putting the sensor into liquid.
  4. Submerge only the optical tip. Record the wet-state output. If the signal is analog, note the difference between dry and wet values.
  5. Set your threshold. Use a clear midpoint between dry and wet readings, then add a small time delay in code to avoid false switching from waves or splashes.

For low-voltage microcontroller examples, voir le Guide Arduino. For general signal connection reference, use the Schéma de câblage.

Assembly Route 2: Building from IR LED, Phototransistor, and Prism

If you want to make the sensing head yourself, the optical layout is the most important part.

The IR LED should shine into the prism or clear tip at a repeatable angle. The receiver should be positioned where reflected light returns strongly in the dry state. Quand le liquide touche le prisme, the reflected light drops or shifts. Your circuit then detects that change.

A basic prototype can be arranged like this:

  • IR LED aimed into the clear prism body
  • Phototransistor placed to receive reflected IR
  • Resistor to limit LED current
  • Pull-up or pull-down resistor for receiver signal
  • Microcontroller analog input or comparator input
  • Shielding around the optical pair to block room light
  • Sealed mechanical head so liquid reaches only the prism tip

The hardest part is making the prism. A rough plastic tip, scratched surface, cloudy epoxy, or misaligned LED can make the sensor unstable. Pour l’eau, a clear plastic optical tip may work for learning. Pour le pétrole, combustible, Produits chimiques, Détergents, or hot liquids, material choice becomes much more serious.

Wetted Materials: Plastique, PTFE, Inox, et Verre

The “wetted material” is the part that touches the liquid. For a DIY project, people often focus only on the circuit, but the material in contact with the liquid decides whether the sensor survives.

Alimentation ou plastique d’ingénierie can be useful for compact water-level designs where chemical exposure is mild. It is easier to machine or mold than metal.

PTFE is chosen when stronger chemical resistance or anti-stick behavior is needed. It can be useful where residue or aggressive liquid is a concern.

316 Acier inoxydable is common for industrial housings because it gives mechanical strength, résistance à la corrosion, and a professional threaded body.

Embouts optiques en verre are often used where optical clarity, Résistance thermique, or chemical stability is important. Glass can also help with repeatable sensing at the prism surface.

For DIY learning, simple plastic may be acceptable. For OEM equipment, appareils, fuel/oil projects, or exported products, confirm material compatibility before ordering any sensor.

Output Types You May See: Numérique, NPN, PNP, et 4–20 mA

Small hobby modules usually provide a simple digital signal or analog voltage. Industrial sensors may use NPN, PNP, relay-style interface, or 4–20 mA output depending on the control system.

Sortie NPN is common where the sensor sinks current to the control input.

Sortie PNP is common where the sensor sources current to the control input.

4Sortie de –20 mA is usually used for industrial analog transmission, especially where long cable runs or noise immunity are important. For a simple point-level DIY sensor, digital output is usually enough.

Avant de commander, check the input type of your controller. A sensor with the wrong output may still be a good sensor, but it will not connect cleanly to your board without interface electronics.

Mounting the Sensor Correctly

Mounting decides whether your optical sensor gives clean readings.

Side mounting is common for point-level detection. The prism tip passes through the tank wall and sits exactly at the level you want to detect. Threaded mounting is stronger than glue or tape, especially when the tank vibrates or the cable is pulled.

For small DIY containers, a bracket can hold the sensor from above, but the tip must stay fixed at the chosen height. If the sensor moves, your trigger level moves too.

Check these mounting points:

  • Keep the prism tip clean and exposed to the liquid.
  • Avoid placing the tip too close to reflective walls or shiny metal parts.
  • Do not let cables hang in a way that pulls on the sensor.
  • Seal the tank opening properly.
  • Keep the electronics side away from condensation and splashes.
  • Choose thread and mounting style before drilling the tank.

Pour les équipements de production, common decisions include straight vs right-angle body, threaded vs flange mounting, plastic vs stainless housing, et longueur de câble.

Étalonnage: Turn Wet and Dry Readings into a Reliable Signal

Calibration is simple but should not be skipped.

D'abord, power the sensor in air and record the dry reading. Then wet the prism completely and record the wet reading. If using analog input, choose a switching threshold between those two values. If using digital output, confirm whether the module reads HIGH when wet or HIGH when dry.

Then test real conditions:

  • slow filling
  • fast filling
  • éclaboussures
  • bulles
  • écume
  • droplets clinging to the tip
  • dirty water or residue
  • ambient light exposure
  • vibration near the tank

Add debounce in code or logic. A short delay before confirming wet or dry prevents false alarms when liquid briefly touches the prism.

Common DIY Mistakes and How to Avoid Them

Ambient light interference: IR receivers can be affected by sunlight, strong lamps, or reflective surroundings. Shield the LED and receiver, and test near the final installation environment.

Prisme sale: Film à huile, mineral scale, Algues, poussière, or sticky liquid can change the optical path. Clean the tip and choose a material that matches the liquid.

Wrong output assumption: Some sensors switch ON when wet; others switch ON when dry. Always test both states before connecting control logic.

Poor waterproofing: A working bench prototype may fail inside a humid tank area. Seal cable exits, protect the circuit board, and avoid exposed solder joints near liquid.

Bad prism geometry: DIY prisms need clean surfaces and repeatable angles. Rough-cut acrylic or cloudy adhesive can reduce reflection.

No mechanical strain relief: Cable movement can loosen the sensor or crack a seal.

No debounce: Vagues, écume, and droplets can create short false transitions. Confirm the state for a short period before acting on it.

When Buying a Finished Sensor Is Cheaper Than DIY

DIY is cheaper when you are learning, testing one idea, or building a quick prototype from parts you already have. But a finished optical level sensor is often cheaper when you count the full project cost.

Buy a finished sensor when you need:

  • repeatable wet/dry detection
  • sealed cable and housing
  • stable NPN, PNP, or industrial output
  • compact body for limited space
  • PTFE, 316 Inox, verre, or other wetted-material options
  • Personnalisation OEM/ODM
  • production quantity consistency
  • export-ready supplier communication
  • fewer field failures

HojellyTek est un fabricant et exportateur de Shenzhen spécialisé dans la détection optique photoélectrique, R interne&D, and OEM/ODM liquid level sensor projects for customers in the US, EU, Inde, et autres marchés. If your DIY prototype is moving toward a real product, notre finished micro optical sensor may reduce rework, sealing risk, and assembly time.

What to Confirm Before Ordering a Finished Optical Level Sensor

Before sending an RFQ, Préparez ces détails:

  • Type liquide: eau, huile, combustible, Détergent, Liquide de refroidissement, or chemical
  • tank material and wall thickness
  • mounting position and required thread style
  • wet/dry logic requirement
  • Type de sortie: NPN, PNP, analogique, ou une autre interface
  • supply voltage required by your control board
  • cable length and connector preference
  • Préférence pour les matériaux humides: plastique, PTFE, 316 Inox, verre
  • whether the project needs OEM body size, Marque privée, or custom cable
  • whether the sensor is for prototype, pilot run, or mass production

For smart tank monitoring or connected appliance projects, you can also discuss integration needs such as controller boards, wireless modules, or Tuya/Smart Life-related system design where relevant.

FAQ

Can I build a diy optical liquid level sensor with an IR LED and phototransistor?

Oui. You can build a basic optical point-level detector with an IR LED, Phototransistor, Pointe prismatice, resistors, and a low-voltage control board. The difficult parts are optical alignment, Étanchéité, Blindage de la lumière ambiante, and stable calibration.

Is a ready optical level module better than building from separate parts?

For most practical projects, oui. A ready module saves time because the optical head and basic circuit are already assembled. Building from separate parts is better for learning, custom experiments, or understanding how the sensing principle works.

Can this sensor measure the full tank level?

A basic optical level sensor detects liquid at one point. It tells you whether the prism tip is wet or dry. For continuous tank level measurement, you need a different sensing approach or multiple sensing points.

Why does my optical sensor trigger incorrectly?

Common causes include sunlight, dirty prism surfaces, droplets stuck on the tip, reflective tank walls, loose wiring, Mauvais scellement, and no debounce in the control logic. Test dry and wet readings under real mounting conditions.

Can I use this sensor to control a pump?

You can use the low-voltage sensor signal as an input to a suitable controller. Do not wire the sensor directly to mains power or an AC pump. Any pump power circuit should be designed with proper isolation and safety protection by a qualified person.

When should I contact HojellyTek instead of continuing DIY?

Contact HojellyTek when your prototype needs a sealed body, stable output, taille compacte, special wetted material, Personnalisation OEM/ODM, or production-ready consistency. Envoyez votre type liquide, Méthode de montage, Exigence de production, and quantity plan by WhatsApp or email to request a quote.