Turbidity Sensor Arduino: NTU Measurement, Calibration and Code
How to use a turbidity sensor with Arduino: IR light measurement, analog and digital output, voltage-to-NTU curve, calibration, ESP32 divider and Pico code.
A turbidity sensor is an optical sensor that measures how much of the infrared light passing through water reaches the other side, turning water clarity into a voltage the Arduino can read. The clearer the water, the higher the output voltage; the more suspended particles such as mud, detergent, algae or milk, the lower it gets. The common hobby modules work on the same principle as the sensors washing machines use to monitor rinse water, and come with a small interface board.
In this guide you'll see how the sensor works, the difference between analog and digital output, the curve that converts voltage into NTU and the limits of that curve. An NTU table by water type, step-by-step calibration, Arduino Uno code, ESP32 code with a voltage divider and a MicroPython example for the Raspberry Pi Pico are ready. Finally, two application examples, washing machine rinse water and an aquarium, show where the sensor works best.
What is turbidity, and what does NTU mean?
Turbidity is a measure of how opaque the suspended particles in water make it by scattering light. Its unit is the NTU (Nephelometric Turbidity Unit). Lab instruments are calibrated with a standard solution called formazin and measure the light scattered at a 90-degree angle. Hobby sensors measure the light that passes straight through instead, so their NTU values are approximate estimates. The human eye usually starts to notice cloudiness at around 4-5 NTU; for drinking water the target is below 1 NTU.
| Water type | Typical turbidity | Can a hobby sensor tell it apart? |
|---|---|---|
| Distilled or purified water | 0-0.5 NTU | Used as the clear-water reference |
| Tap and drinking water | Usually below 1 NTU | No, no visible difference from distilled water |
| Swimming pool | Below 0.5 NTU recommended | No |
| Clean aquarium | Usually below 5 NTU | Only clear clouding is seen |
| Lake and stream water (normal) | 5-50 NTU | Roughly, at the upper end |
| Well or stream water after rain | Tens to hundreds of NTU | Yes, especially above 100 NTU |
| First wash water of a washing machine | Hundreds to thousands of NTU | Yes, its best range |
| Muddy water, undiluted milk | Thousands of NTU and more | The sensor saturates at its lowest value |
How does a turbidity sensor work?
At the bottom of the sensor there is a small gap between two transparent legs facing each other. One leg holds an infrared LED and the other a phototransistor. Water fills the gap; the LED's light passes through the water to the phototransistor. Particles scatter and absorb the light, less light reaches the phototransistor and the module's output voltage drops. With a 5 V supply you read about 4.1-4.3 V in clear water, and in very cloudy water the voltage falls below 2.5 V. Because infrared light is used, the colour of the water affects the result less than it would with visible light, but sunlight and room lighting can leak into the open gap and change the reading.
| Feature | Typical module value |
|---|---|
| Measuring principle | Light transmission with an infrared LED and phototransistor |
| Supply | 5 V DC |
| Current | Up to about 40 mA |
| Analog output | 0-4.5 V, highest in clear water |
| Digital output | HIGH or LOW, threshold set with the trimmer on the board |
| Response time | Under 500 ms |
| Probe operating temperature | About 5-90 °C |
| Approximate measuring range | 0-3000 NTU (according to the rough curve) |
Analog and digital output: the A/D switch
The interface board has a small A/D switch, and the signal pin gives two different things depending on its position. In the A position the output is an analog voltage proportional to clarity; use this position for NTU calculation, trend tracking and calibration. In the D position a comparator on the board compares the voltage with the threshold you set on the trimmer and outputs only HIGH or LOW. Digital mode is enough to drive an LED or relay module without a microcontroller, or for a simple clean-or-dirty decision. Which state gives HIGH can vary from board to board, so test in clear and cloudy water first and take notes.
Turbidity sensor wiring
| Sensor board | Arduino Uno | ESP32 | Raspberry Pi Pico |
|---|---|---|---|
| VCC | 5V | VIN (5 V) | VBUS (5 V) |
| GND | GND | GND | GND |
| Signal (A position) | A0 | GPIO 34, via a 10 kΩ / 20 kΩ divider | GP26, via a 10 kΩ / 20 kΩ divider |
The ESP32 and Pico run on 3.3 V, while the sensor outputs up to 4.5 V. So put a 10 kΩ resistor between the signal and the ADC pin, and a 20 kΩ resistor between the ADC pin and GND. This voltage divider brings 4.5 V down to 3.0 V; in code you multiply the measured voltage by 1.5 to get the module's real output. You can check the values with the voltage divider tool. On the ESP32, connect the sensor only to ADC1 pins (GPIO 32-39); ADC2 pins can't be read while Wi-Fi is on.
From voltage to NTU: the conversion curve and its limits
The approximate curve widely used for these modules, measured at 25 °C with a 5 V supply, is this second-order equation: NTU = -1120.4 × V² + 5742.3 × V - 4352.9. The curve is only valid between 2.5 V and 4.2 V: 4.2 V gives about 0 NTU and 2.5 V about 3000 NTU. Values outside this range must be clamped to the limits, otherwise the formula produces meaningless results.
| Module output | Approx. NTU from the curve | Meaning |
|---|---|---|
| 4.20 V | 0 | Clear water |
| 4.15 V | 180 | Slightly cloudy |
| 4.10 V | 360 | Clearly cloudy to the eye |
| 4.00 V | 690 | Very cloudy |
| 3.80 V | 1290 | Dirty wash water |
| 3.50 V | 2020 | Muddy water |
| 3.00 V | 2790 | Very dense |
| 2.50 V | 3000 | Measuring limit |
The table shows the curve's biggest weakness: in the clear-water region the slope is about 3700 NTU per volt. The Arduino Uno's 10-bit ADC reads in 4.9 mV steps at 5 V, so a single ADC step is worth about 18 NTU. With this sensor you can't see the difference between 1 NTU and 10 NTU. It answers the question clean, cloudy or very dirty, and it's good at tracking change in the same water. A 16-bit ADC such as the ADS1115 helps with finer resolution, but the sensor's optical noise and temperature drift still set a limit. ADC concepts are explained in detail in what is an ADC.
Calibration: tuning your own sensor
- Measure the Arduino's 5V pin with a multimeter and enter it as VREF in the code. On USB-powered boards this value is usually between 4.7 and 5.1 V and directly affects the result.
- Wipe the probe with a soft cloth and make sure the gap between the legs is clean. Use an opaque, dark container and keep direct light off it while measuring.
- Fill the container with distilled or purified water, immerse the probe upright and shake it gently to remove air bubbles from the legs. Wait a minute and record the voltage shown in the Serial Monitor as V_CLEAR.
- For more accurate results, measure two more points with formazin standards (e.g. 100 and 1000 NTU) from lab suppliers and build your own curve.
- If you only need to compare, set up a percentage clarity scale with two reference waters, one clear and one dirty; the code in the washing machine example does this.
- Repeat the calibration once a month and after every probe cleaning; even a thin film of dirt on the legs lowers the voltage.
Arduino Uno code: voltage and approximate NTU
Set the sensor's A/D switch to A and connect the signal pin to A0. The code averages 50 readings, converts them to voltage, scales the result against the clear-water measurement and calculates NTU from the curve. Because the output is printed as volt,ntu, you can also watch it as a graph in the Serial Plotter.
1// Bulanıklık sensörü: gerilim ve yaklaşık NTU / Turbidity sensor: voltage and approximate NTU
2const int TURB_PIN = A0; // modül sinyal ucu, anahtar A konumunda / module signal pin, switch on A
3const float VREF = 5.0; // 5V pinini multimetreyle ölçüp yaz / measure the 5V pin and enter it
4const float V_CLEAR = 4.20; // kendi berrak suyunda ölçtüğün gerilim / voltage you measured in clear water
5
6float readVolts() { // 50 okumanın ortalaması / average of 50 readings
7 long sum = 0;
8 for (int i = 0; i < 50; i++) {
9 sum += analogRead(TURB_PIN);
10 delay(2);
11 }
12 return sum / 50.0 * VREF / 1023.0;
13}
14
15float toNtu(float v) {
16 v = v * 4.20 / V_CLEAR; // berrak su = 4,20 V olacak şekilde ölçekle / scale so clear water = 4.20 V
17 v = constrain(v, 2.5, 4.2); // eğri yalnız bu aralıkta geçerli / curve only valid here
18 float ntu = -1120.4 * v * v + 5742.3 * v - 4352.9;
19 return ntu < 0 ? 0 : ntu;
20}
21
22void setup() {
23 Serial.begin(9600);
24 Serial.println(F("volt,ntu"));
25}
26
27void loop() {
28 float v = readVolts();
29 Serial.print(v, 3);
30 Serial.print(',');
31 Serial.println(toNtu(v), 0);
32 delay(1000);
33}| Code part | What it does |
|---|---|
| VREF | The ADC's reference voltage; the 5V value you measured corrects the result directly |
| V_CLEAR | The voltage you measured in clear water; maps your sensor onto the 4.20 V reference curve |
| v * 4.20 / V_CLEAR | Matches your own sensor's clear-water point to the curve's 0 NTU point |
| constrain(v, 2.5, 4.2) | Keeps the value inside the range where the curve is valid |
| Average of 50 readings | Reduces jitter from bubbles and electrical noise |
ESP32 code: reading through a voltage divider
The ESP32's ADC is 12-bit but not linear towards its ends. That's why the code uses analogReadMilliVolts() instead of analogRead(): it returns a millivolt value corrected with the calibration data written into the chip at the factory. The median of 31 samples completely removes occasional spikes. Since the divider ratio is 1.5, the measured voltage is multiplied by this number to get the module's output. Filtering methods are compared in the sensor data filtering guide.
1// ESP32: 10k/20k gerilim bölücüyle bulanıklık okuma / turbidity through a 10k/20k divider
2const int TURB_PIN = 34; // ADC1 pini (Wi-Fi açıkken de çalışır) / ADC1 pin (works with Wi-Fi on)
3const float DIVIDER = 1.5; // (10k + 20k) / 20k
4const float V_CLEAR = 4.20; // berrak suda modül çıkışı / module output in clear water
5
6float moduleVolts() { // 31 örneğin ortancası / median of 31 samples
7 int mv[31];
8 for (int i = 0; i < 31; i++) {
9 mv[i] = analogReadMilliVolts(TURB_PIN); // fabrika kalibrasyonlu mV / factory-calibrated mV
10 delay(2);
11 }
12 for (int i = 1; i < 31; i++) { // ekleme sıralaması / insertion sort
13 int x = mv[i], j = i - 1;
14 while (j >= 0 && mv[j] > x) { mv[j + 1] = mv[j]; j--; }
15 mv[j + 1] = x;
16 }
17 return mv[15] / 1000.0 * DIVIDER; // pindeki gerilimden modül çıkışına / pin voltage to module output
18}
19
20void setup() {
21 Serial.begin(115200);
22 analogSetPinAttenuation(TURB_PIN, ADC_11db); // 0-3,1 V aralığı / 0-3.1 V range
23}
24
25void loop() {
26 float v = moduleVolts();
27 float s = constrain(v * 4.20 / V_CLEAR, 2.5, 4.2);
28 float ntu = max(0.0f, -1120.4f * s * s + 5742.3f * s - 4352.9f);
29 Serial.printf("%.3f V %.0f NTU\n", v, ntu);
30 delay(1000);
31}Raspberry Pi Pico code (MicroPython)
On the Pico, connect the signal to GP26 through the same 10 kΩ / 20 kΩ divider and power the sensor from VBUS. read_u16() returns a value from 0 to 65535; it's converted to a voltage relative to 3.3 V and multiplied by the divider ratio. The Pico's ADC reference is its 3.3 V supply rail, so power the board from a good USB source for more stable results.
1# Pico: bulanıklık, GP26 ve 10k/20k bölücü / turbidity on GP26 with a 10k/20k divider
2from machine import ADC
3import time
4
5adc = ADC(26) # GP26 = ADC0
6DIVIDER = 1.5 # (10k + 20k) / 20k
7V_CLEAR = 4.20 # berrak suda modül çıkışı / module output in clear water
8
9def module_volts(n=31): # ortanca / median
10 r = sorted(adc.read_u16() for _ in range(n))
11 return r[n // 2] * 3.3 / 65535 * DIVIDER
12
13while True:
14 v = module_volts()
15 s = min(max(v * 4.20 / V_CLEAR, 2.5), 4.2)
16 ntu = max(0, -1120.4 * s * s + 5742.3 * s - 4352.9)
17 print("{:.3f} V {:.0f} NTU".format(v, ntu))
18 time.sleep(1)Example: washing machine rinse water monitor
Some washing machines and dishwashers measure the clarity of rinse water with a similar optical sensor: if the water is still soapy and cloudy they add another rinse, and if it's clear they shorten the programme and save water and energy. You can try the same idea with a bucket or a hand-washing basin. Instead of NTU, this code calculates a clarity percentage between two reference points: V_CLEAR is measured in tap water and V_DIRTY in the first, soapy wash water. When clarity goes above 90 %, the green LED lights and the buzzer gives a short beep.
1// Durulama suyu izleyici: göreli berraklık % / Rinse water monitor: relative clarity %
2const int TURB_PIN = A0;
3const int GREEN_LED = 8; // su yeterince berrak / water clear enough
4const int RED_LED = 9; // hâlâ kirli / still dirty
5const int BUZZER_PIN = 5; // aktif buzzer / active buzzer
6const float VREF = 5.0;
7const float V_CLEAR = 4.20; // musluk suyunda ölçülen / measured in tap water
8const float V_DIRTY = 3.10; // ilk, köpüklü yıkama suyunda ölçülen / measured in the first, soapy wash water
9const int CLEAR_ENOUGH = 90; // %90 ve üstü "temiz" / 90 % and above counts as "clean"
10
11float readVolts() {
12 long sum = 0;
13 for (int i = 0; i < 50; i++) {
14 sum += analogRead(TURB_PIN);
15 delay(2);
16 }
17 return sum / 50.0 * VREF / 1023.0;
18}
19
20void setup() {
21 pinMode(GREEN_LED, OUTPUT);
22 pinMode(RED_LED, OUTPUT);
23 pinMode(BUZZER_PIN, OUTPUT);
24 Serial.begin(9600);
25}
26
27void loop() {
28 float v = readVolts();
29 int clarity = constrain((int)((v - V_DIRTY) / (V_CLEAR - V_DIRTY) * 100), 0, 100);
30 bool clean = clarity >= CLEAR_ENOUGH;
31 digitalWrite(GREEN_LED, clean);
32 digitalWrite(RED_LED, !clean);
33 digitalWrite(BUZZER_PIN, clean); // temizse kısa bip / short beep when clean
34 delay(clean ? 200 : 0);
35 digitalWrite(BUZZER_PIN, LOW);
36 Serial.print(F("Berraklik / clarity: "));
37 Serial.print(clarity);
38 Serial.println(F(" %"));
39 delay(2000);
40}The percentage scale makes full use of the high-turbidity range where this sensor is strong and isn't affected by the uncertainty of the NTU curve. Connect the green LED to D8 and the red LED to D9 with 220 Ω resistors, and the active buzzer to D5. Foam and air bubbles spoil the measurement, so keep the sensor a few centimetres below the water surface and a little away from the flow.
Example: aquarium and water tank alerts
- Aquarium filter reminder: The sensor stores the average measured overnight in clean water as a baseline. If the voltage drops more than 0.05 V below the baseline (about 150-200 NTU more), a warning lights to show the filter is clogging or the fish are being overfed. For aquarium automation see the aquarium control system guide.
- Rainwater tank: After a downpour, the first water flowing into the tank carries dust from the roof. When turbidity rises, a solenoid valve diverts this first flush away, and once clarity returns it sends the water to the tank.
- Water quality station: The turbidity sensor is more meaningful together with pH, TDS and temperature; the setup combining all four sensors on one board is in the water quality monitoring guide. For dissolved minerals use the TDS sensor guide and for acidity the pH sensor guide.
Common mistakes and fixes
| Symptom | Cause | Fix |
|---|---|---|
| The value jumps in clear water | Air bubbles on the legs | Shake the probe to remove bubbles, let the water settle for a few minutes |
| Different readings by day and night | Outside light enters the sensor's open gap | Use an opaque container or a dark sleeve around the sensor |
| All values a little high or low | The 5 V from USB is really 4.8 V | Measure the 5V pin, enter it as VREF and measure V_CLEAR again |
| Readings go wrong on the ESP32 when Wi-Fi turns on | Signal is on an ADC2 pin | Use one of the ADC1 pins between GPIO 32 and 39 |
| The clear-water voltage drops over weeks | Dirt and biofilm build up on the legs | Wipe the probe with a soft cloth and measure V_CLEAR again |
| The digital output never changes | Switch on D but the threshold at one end | Turn the trimmer so it switches between clear and cloudy water |
In the BlueGrays app you can try reading analog sensors, measuring voltages and showing data on a display step by step, with circuit diagrams and commented code, in projects such as reading light intensity with an LDR, a digital voltmeter with an LCD and the ESP32 temperature logger, and then easily adapt what you've learned to the turbidity sensor.
Frequently asked questions
What is a turbidity sensor used for?
A turbidity sensor measures the amount of suspended particles in water, in other words how clear the water is. It's used to monitor rinse water in washing machines and dishwashers, to spot contamination early in aquariums and water tanks, and to log changes in stream and well water after rain. It does not show whether water is safe to drink.
What is NTU?
NTU (Nephelometric Turbidity Unit) is the unit for water turbidity and is based on how much light is scattered by particles in the water. For drinking water the target is below 1 NTU, and the human eye notices cloudiness from about 4-5 NTU. Muddy water and dirty wash water range from hundreds to thousands of NTU.
How do you connect a turbidity sensor to Arduino?
The sensor board's VCC goes to 5V, GND to GND and the signal pin to A0, with the board's switch set to A. The value read with analogRead() is converted to a voltage, and a conversion curve gives the approximate NTU. On the ESP32 and Pico the signal must be connected through a 10 kΩ and 20 kΩ voltage divider.
Can a turbidity sensor measure drinking water?
Hobby turbidity sensors are not sensitive enough to tell apart the 0-5 NTU differences at drinking water level; on an Arduino Uno a single ADC step is worth about 18 NTU. Bacteria and dissolved chemicals may also leave turbidity unchanged. Drinking water safety requires a lab analysis.
How do you calibrate a turbidity sensor?
First you measure the Arduino's 5V pin and enter it in the code as the reference voltage. Then you immerse the probe in clean, bubble-free distilled water and record the voltage as the clear-water value. For a more accurate curve, extra points can be measured with formazin standard solutions.
Can you use a turbidity sensor with an ESP32?
Yes, but because the sensor's output goes up to 4.5 V, the signal must be brought below 3.3 V with a voltage divider. A 10 kΩ and 20 kΩ divider lowers 4.5 V to 3.0 V, and the value read in code is multiplied by 1.5. The sensor should be connected to an ADC1 pin and read with analogReadMilliVolts().
Projects to build after reading this
See all projects
Measuring Light Intensity with an LDR
Want to see how bright your room is as a number? The LDR, a small part that reacts to light, measures the light around it, and the Arduino writes the value to your computer screen every half second.

Reading Light Intensity with the ESP32 LDR Module
Real-time monitoring of the LDR module's raw ADC value and relative light percentage calculated from dark and light reference values in the Serial Monitor. This percentage is not a lux measurement. Teaches the module’s calibration logic. It is ideal to complete this before Project 10, as it is used to determine the threshold value.

Digital Voltmeter with LCD Display
Find out how much voltage a battery or power adapter gives with a meter you built yourself.

Smart Irrigation Station
A gardener that waters your plants on its own, so they don't dry out while you're on vacation.

ESP32 Temperature Data Logger (DHT22 + DS1307 RTC + microSD + OLED)
Build a timed temperature and humidity logger with the ESP32! A DHT22 sensor reads temperature and humidity once a minute, and each reading is saved to a microSD card in CSV format with a real-time stamp from the DS1307 RTC module. The OLED display shows the latest temperature, humidity, timestamp and total number of records live, in large text.

ESP32 DHT22 Temperature and Humidity (with LCD Display)
This project measures ambient temperature and humidity using a DHT22 sensor and displays the data in real time on a 16x2 I2C LCD. Data is read from the sensor using the one-wire protocol via the Adafruit DHT library. This project serves as the foundation for IoT weather stations, smart home automation, or environmental monitoring systems in greenhouses. Communication with the DHT22 is established via the ESP32's GPIO 4 pin.

ESP32 HTTPClient + Weather API (with SSD1306 OLED Display)
In this project the ESP32 makes a REST API call over the internet to a weather API (wttr.in) using HTTPClient.h. Unlike the I2C LCD version, it uses an SSD1306 OLED (128×64) display, with large text and vector icons for a richer look. Seven weather icons (sunny, rainy, snowy and more) are drawn on the fly, with no bitmap files.
More articles
BlueGrays app
Build this circuit step by step on your phone
Wiring diagram, code and parts list on one screen. 500+ Arduino, ESP32, ESP8266, Pico, mBot and micro:bit projects ready to build.
Scan with your phone
Point your camera at the code and your phone's app store opens.
or open the store

