DIY Optical Liquid Level Sensor: Build & Parts Guide
A diy optical liquid level sensor can be built in two practical ways: assemble your own optical head from an IR LED, フォトトランジスタ, and prism tip, or start with a ready optical level module and focus on wiring, 取り付け, およびキャリブレーション. The first path teaches you how photoelectric liquid detection really works. The second path is faster, クリーナー, 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.
プリズムの先端が空気中にあるとき, the IR light reflects internally and returns strongly to the receiver. 液体がプリズムを覆うとき, 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, HojellyTekの項目を参照してください 光学レベルセンサー ガイド.
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, 水族館, 水タンク, and small reservoirs. The optical head, emitter, 受信機, 住宅, and basic circuit are already built. You only handle the low-voltage supply, signal reading, 取り付け, およびキャリブレーション.
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 or photodiode, resistors, a comparator or microcontroller input, and a prism or clear optical tip. It is useful for learning, カスタム形状, or lab prototypes.
This route is harder because optical alignment, 環境光遮蔽, 防水, 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, 品質, ハウジング素材, and quantity, so use this table as a planning guide rather than a price quotation.
| Part or Material | Purpose in the Build | DIY Cost Impact | What to Check Before Buying |
|---|---|---|---|
| 赤外線LEDです | Sends infrared light into the optical tip | 低い | Wavelength, viewing angle, package size, stable output |
| Phototransistor or photodiode | Receives reflected IR light | 低い | 感度, 応答速度, package alignment |
| Prism or clear optical tip | Creates the wet/dry optical change | 中程度 | Optical clarity, 形状, 液体適合性, polish quality |
| 抵抗器 | Set LED current and receiver signal level | 低い | Correct values for your board voltage |
| Comparator or transistor stage | Converts analog signal into stable digital output | Low to medium | Threshold adjustment, noise immunity |
| Arduino, ESP32, or MCU board | Reads the signal and controls logic | 中程度 | 入力電圧, ADC/digital pin behavior |
| Ready optical level module | Replaces separate LED, 受信機, and prism design | 中程度 | 供給電圧, 出力タイプ, cable sealing |
| Housing or enclosure | Protects electronics from splashes | 中程度 | Waterproofing, ケーブル出口, 機械的強度 |
| Cable gland or sealed cable | Keeps moisture away from wiring | 中程度 | Seal quality, ひずみ緩和, tank environment |
| Mounting thread or bracket | Holds the tip at the correct level | 中程度 | 糸のサイズ, 壁の厚さ, 向き |
| Finished industrial sensor | Production-ready alternative | Higher upfront, lower rework risk | 出力, 材料, 取り付け, ケーブル, OEM fit |
The hidden cost in DIY is usually not the LED or receiver. It is waterproofing, 再現可能な取り付け, 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.
- Identify the low-voltage pins. Most simple modules provide power, グラウンド, and signal. Some modules may provide digital output, アナログ出力, あるいはその両方. Do not assume wire colors; check the supplier diagram.
- 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.
- Test in air first. Read the dry-state output before putting the sensor into liquid.
- Submerge only the optical tip. Record the wet-state output. If the signal is analog, note the difference between dry and wet values.
- 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, 参照 Arduinoガイド. For general signal connection reference, use the 配線図.
Assembly Route 2: Building from IR LED, フォトトランジスタ, 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. 液体がプリズムに触れるとき, 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. 水のために, a clear plastic optical tip may work for learning. 石油のために, 燃料, 化学薬品, 洗剤, or hot liquids, material choice becomes much more serious.
Wetted Materials: プラスチック製, PTFE製, ステンレススチール, そしてガラス
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.
電源ユニットかエンジニアリングプラスチック 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 ステンレススチール is common for industrial housings because it gives mechanical strength, 耐食性, and a professional threaded body.
ガラス光学チップ are often used where optical clarity, 耐温性, or chemical stability is important. Glass can also help with repeatable sensing at the prism surface.
For DIY learning, simple plastic may be acceptable. OEM機器用, 機器, fuel/oil projects, or exported products, confirm material compatibility before ordering any sensor.
Output Types You May See: デジタル, NPN, PNP, および4〜20mAです
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.
NPN出力 is common where the sensor sinks current to the control input.
PNP出力 is common where the sensor sources current to the control input.
4–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.
注文前に, 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.
生産機器用, common decisions include straight vs right-angle body, threaded vs flange mounting, plastic vs stainless housing, およびケーブルの長さ.
キャリブレーション: Turn Wet and Dry Readings into a Reliable Signal
Calibration is simple but should not be skipped.
まずは, 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
- 水しぶきが響く
- バブル
- 泡
- 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.
ダーティプリズム: 油絵フィルム, mineral scale, 藻類, 塵, 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: 波, 泡, 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 ステンレス, グラス, or other wetted-material options
- OEM/ODMのカスタマイズ
- production quantity consistency
- export-ready supplier communication
- fewer field failures
HojellyTekは、深センの光電光学センシングに特化した製造・輸出業者です, 社内R&D, and OEM/ODM liquid level sensor projects for customers in the US, 私たちは, インド, その他の市場. If your DIY prototype is moving toward a real product, 私たちの 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, これらの詳細を準備してください:
- 液体タイプ: 水, 油, 燃料, 洗剤, 冷却液, or chemical
- tank material and wall thickness
- mounting position and required thread style
- wet/dry logic requirement
- 出力タイプ: NPN, PNP, アナログ, またはその他のインターフェース
- supply voltage required by your control board
- cable length and connector preference
- 湿潤素材の好み: プラスチック, PTFE製, 316 ステンレス, グラス
- whether the project needs OEM body size, プライベートラベル, 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.
よくある質問
Can I build a diy optical liquid level sensor with an IR LED and phototransistor?
はい. You can build a basic optical point-level detector with an IR LED, フォトトランジスタ, プリズムチップ, resistors, and a low-voltage control board. The difficult parts are optical alignment, 防水, 環境光遮蔽, and stable calibration.
Is a ready optical level module better than building from separate parts?
For most practical projects, はい. 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, 密閉不良, 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, コンパクトサイズ, special wetted material, OEM/ODMのカスタマイズ, or production-ready consistency. 液体タイプを送ってください, 取り付け方法, 出力要件, and quantity plan by WhatsApp or email to request a quote.