Turbidity Sensor Library for Proteus V1.0: the turbidity sensor with its STATUS panel and the Advance pop-up

Turbidity Sensor Library for Proteus V1.0: Water Quality with Arduino

2.5K Views
40
700
60
25
60
PCBWay

Hello friends, I hope you all are doing great. Today, I am going to share the new Turbidity Sensor Library for Proteus V1.0. A turbidity sensor tells you how cloudy water is: how much fine mud, clay, algae or other particles float in it. It is the sensor behind many water quality projects - a filter that should give clear water, an aquarium, a fish pond, a rain water tank, a washing machine that checks its rinse water, or a river monitor after heavy rain. The usual module for Arduino is a white plastic probe with a U-shaped tip and a small blue adapter board with an A / D switch and a threshold potentiometer.

Behind the part sits our own model, written from the maker's published data. It gives the voltage the real board gives for the water in the beaker - 4.2 V in clear water, lower as the water clouds, following the published curve from volts to NTU - and, with the switch on D, the digital level of the board's comparator. A probe can be a little off the curve, the output follows the supply, very muddy water goes beyond the curve, a dry probe reads as clear water, and air bubbles in the light path make single readings jump. You can change the water while the simulation runs. You get a Simple device with a live STATUS panel and an Advance device with a pop-up window and three test tools. The demo runs on our Arduino UNO V4.0.

NOTICE: a turbidity sensor is easy to fake: a potentiometer on an analog pin. We wanted more. Our turbidity sensor knows the water it stands in and gives exactly the voltage the published curve turns back into that water. Its probe can be off the curve, its output moves with the supply, its digital output switches at the potentiometer's threshold, and bubbles, stirred-up mud and a dry probe behave as they do in a real beaker - so an uncalibrated probe, a sketch without a filter or a switch left on D fail exactly as they do on a real board. It took our team a lot of hard work. Your feedback is the fuel that keeps us going, so please tell us what you think in the comments below or in the turbidity sensor board of our forum. And if our free libraries help you, you can buy us a coffee. So, let's get started with the Turbidity Sensor Library for Proteus V1.0:

Turbidity Sensor Library for Proteus V1.0: the turbidity sensor with its STATUS panel and the Advance pop-up
Figure: The Turbidity Sensor Library for Proteus V1.0: a Simple turbidity sensor in river water with its STATUS panel, and the pop-up of an Advance one on river water.

What is a Turbidity Sensor?

Turbidity is the cloudiness of water. It is measured in NTU, nephelometric turbidity units: drinking water is below 1 NTU, a clear pond a few tens, a river after rain hundreds, muddy flood water thousands. The sensor does not count particles. Its probe has an infrared LED on one side of the gap in its tip and a phototransistor on the other. In clear water most of the light crosses the gap. Particles scatter it, so less light arrives and the signal falls. That is why the output is highest in clear water and lower as the water clouds.

The turbidity sensor in numbers
ParameterThe analog / digital turbidity sensor
Supply5 V, up to 40 mA
Analog output0 to 4.5 V (clear water about 4.2 V)
Digital outputHIGH or LOW against a threshold set with the potentiometer
Responseunder 500 ms
Probean infrared LED and a phototransistor across the gap of a U-shaped tip; the tip is waterproof, its top is not
Connectionsa 3-pin header (+, -, OUT), an A / D switch, a 3-pin socket for the probe

From Volts to NTU

The maker publishes a curve for a 5 V supply: NTU = -1120.4 V^2 + 5742.3 V - 4352.9, valid from about 2.5 to 4.2 V. At 4.2 V it gives about 0 NTU, clear water. At 3.98 V it gives about 250 NTU, river water, and at 2.63 V about 3000 NTU. Below 2.56 V the formula turns down again, so it cannot tell more: a sketch can only say "3000 NTU or more". The curve is steepest near clear water, where 0.1 V is about 370 NTU. Two things follow: one ADC step of the Arduino is worth about 18 NTU there, and a probe that gives only 4.05 V in clear water reads hundreds of NTU unless you calibrate it.

The A / D Switch

The adapter board has a small slide switch. On A, OUT is the analog signal. On D, OUT is a digital level from a comparator: the board compares the signal with the voltage set on its potentiometer. In our model D is HIGH while the water is clearer than the threshold and LOW when it is more turbid. That is handy for a simple "water too dirty" alarm on a digital pin, but for NTU the switch must be on A.

What's New in Turbidity Sensor Library for Proteus V1.0

  • The published curve: the model gives the voltage that NTU = -1120.4 V^2 + 5742.3 V - 4352.9 turns back into the water's turbidity, 4.2 V for clear water.
  • Beyond the curve: above about 3000 NTU the output keeps falling, and the sketch can only say "3000 NTU or more".
  • A zero for each probe: the ZERO property is this probe's voltage in clear water, so you can practise the calibration.
  • The supply: the output follows VCC, like a real optical sensor.
  • The A / D switch and the potentiometer on the board - both clickable during the simulation - with a comparator and a small hysteresis.
  • The water on the panel: - and + (50 NTU a click), six presets - CLEAR, TAP, POND, RIVER, FLOOD and MUD - and four actions - STIR, BUBBLES, DILUTE and PROBE OUT.
  • A beaker beside the board: the water turns from clear blue to brown, the infrared light across the probe's gap fades as the water clouds, bubbles rise during BUBBLES, and PROBE OUT lowers the water below the probe.
  • Three test tools on the Advance device: Output & curve, Calibration & supply, and Digital & wiring.
  • A two-node demo on our Arduino UNO V4.0 with no library at all: a reading every 40 ms, the median of 30 each second, the curve, a word for the water, and the CAL, OFFSET and FILTER commands.
  • A compact package: about 1.26 MB, without the C++ source code of the model.

Two Devices: Simple and Advance

Turbidity sensor board in Proteus with its A / D switch, threshold potentiometer and the probe in a beaker
Figure: The turbidity sensor as the library draws it, with its PWR and D LEDs lit for the picture.

The part shows the blue adapter board with its 3-pin header on the left - +, - and OUT - the A / D slide switch, the blue threshold potentiometer, the comparator chip and the white 3-pin socket on the right. A black cable runs to the white probe, and the probe stands in a beaker of water with the red LED window and the dark phototransistor window facing each other across the gap of its tip. Two LEDs sit on the board: PWR while the board has power and D while the comparator says the water is clearer than the threshold. The beaker, the LEDs, the badge and the button are TEP additions.

Turbidity sensor in Proteus as a Simple device with its STATUS panel and as an Advance device
Figure: The turbidity sensor as a Simple device with its STATUS panel, and as an Advance device with OPEN PANEL on its board.
The two devices (search "TURBIDITY" in Pick Devices; both in TEPTURBIDITY.LIB)
SimpleAdvance
DeviceTURBIDITYTEPTURBIDITYADVTEP
On the schematicThe board, the beaker and the STATUS panelThe board and the beaker
The water and the actionsOn the STATUS panelIn the pop-up
The switch and the potentiometerOn the board (clickable)On the board and in the pop-up
StatusBanner, a ruler, 10 readouts, the last 4 eventsA pop-up: Sensor, Event log, Tests

Download Turbidity Sensor Library for Proteus

Click the button below to download Turbidity-Sensor-Library-for-Proteus-v1.0.zip (about 1.26 MB, without the C++ source code of the model):

Turbidity Sensor Library for Proteus V1.0
  • README.txt: the devices, installation, the demo, wiring, the test tools and real hardware.
  • Proteus Library Files: TEPTURBIDITY.LIB and ArduinoV4TEP.LIB from our Arduino Library for Proteus V4.0.
  • Proteus Model Files: TEPTURBIDITY.DLL and TEPARDUINO.DLL.
  • Proteus Simulation: Turbidity-Sensor-ArduinoUnoV4.pdsprj, Turbidity_Water_Demo.hex and copies of the two DLLs.
  • Arduino Code: Turbidity_Water_Demo.ino - it needs no library.

No Proteus yet? Read How to Download and Install Proteus 7 and 8. New to libraries? Follow How to Install a New Library in Proteus.

How to Install Turbidity Sensor Library for Proteus

  1. Close Proteus and extract the whole zip file, for example to your Desktop.
  2. Copy the two files from Proteus Library Files into the LIBRARY folder of Proteus (usually C:\Program Files (x86)\Labcenter Electronics\Proteus 8 Professional\LIBRARY).
  3. Copy TEPTURBIDITY.DLL and TEPARDUINO.DLL from Proteus Model Files into the MODELS folder.
  4. Delete TEPTURBIDITY.IDX from the LIBRARY folder if it is there.
  5. Start Proteus, press P and search for TURBIDITY.

Tip: keep the Proteus Simulation folder together, because the project needs its .hex file and the DLLs beside it. The library is tested in Proteus 8.5; Proteus 7 is not supported.

The Turbidity Sensor Part in Proteus

Turbidity sensor in Proteus with its STATUS panel in tap water
Figure: Node 1 up close: U1, the Simple turbidity sensor, in tap water - 1 NTU and 4.199 V on OUT, read as 1 NTU.

The Simple device adds the STATUS panel under the board. Its banner shows the reading and the output: green when all is well; amber with a probe off the curve, a supply away from 5 V, bubbles or the probe in air; red beyond the curve or without power; blue with the switch on D; grey while the output settles. Below it are - and + for the turbidity (50 NTU a click) and for the threshold (100 NTU a click), and a ruler from 0 to 4000 NTU with the curve's range, the threshold, the water and the reading. Then come six presets, four actions, ten readouts - the state, the output, the water, the switch, the threshold, what the curve reads, the reading with this probe's zero, the analogRead value, the probe's zero and the digital level - and the last four events.

The six presets of the water
PresetTurbidityThe water
CLEAR0 NTUclear, filtered water
TAP1 NTUtap water
POND60 NTUpond water
RIVER250 NTUriver water
FLOOD1500 NTUflood water after rain
MUD4000 NTUmuddy water, beyond the curve

The actions change the water the way real life does. STIR stirs up the sediment: about +800 NTU at once, settling again over a minute. BUBBLES lets air bubbles cross the light path for 12 seconds, short dips of the output. DILUTE pours as much clear water again: half the turbidity. PROBE OUT lifts the probe out of the water, and a second click puts it back. On the board itself you can click the A / D switch, and the left or right half of the potentiometer turns the threshold down or up by 100 NTU. The red X closes the STATUS panel, and the PANEL button on the board opens it again:

Turbidity sensor in Proteus with its STATUS panel closed by the red X
Figure: The STATUS panel closed with its red X: only the board and the beaker stay, with PANEL: OFF on the board.

The Advance device keeps the schematic clean: only the board and the beaker. The live data opens in a pop-up window at Run, and the OPEN PANEL button on the board brings the window back:

Turbidity sensor in Proteus as an Advance device
Figure: Node 2 up close: U2, the turbidity sensor as an Advance device, with OPEN PANEL on its board, in clear water.

The properties set the start: NTU (1 by default), ZERO - this probe's voltage in clear water (4.20 V, the curve) - THRESHOLD in NTU (1000) and MODE, the switch (A). The Simple device also has PANEL (open or closed). Every run starts again from the properties.

The Demo Circuit

Turbidity sensor Proteus simulation: two Arduino UNO V4.0 boards and two turbidity sensors on A0
Figure: The demo project running: node 1 with a Simple turbidity sensor in tap water, node 2 with an Advance one in clear water.

The demo project has two nodes, each an Arduino UNO V4.0 from our Arduino UNO Library for Proteus V4.0 with a turbidity sensor on A0. Node 1 is tap water, 1 NTU, with a probe that follows the curve. Node 2 is clear water, but its probe is a little different: it gives 4.05 V in clear water instead of 4.20 V - the kind of probe you calibrate. Both switches are on A, and both UNOs run the same Turbidity_Water_Demo.hex.

Turbidity sensor demo project in Proteus edit mode: the two nodes before the simulation runs
Figure: The same project before Run: the STATUS panel waiting for the simulation.

Wiring

The wiring of the two nodes (in Proteus and on a real board)
Turbidity board pinArduino UNOIn the demo
+ (VCC)5Va VCC terminal
- (GND)GNDa GND terminal
OUTA0 (any analog input)A0 through the labels TURB_1 and TURB_2

In Proteus OUT reaches its UNO through a net label - TURB_1 for node 1 and TURB_2 for node 2 - and VCC and GND are power terminals. The serial monitor needs no wires at all, because it is built into the UNO V4.0. With the switch on D, OUT also works on a digital pin.

The Arduino Code

The demo sketch needs no library. New to Arduino? Start with Arduino Tutorial for Beginners and Introduction to Arduino UNO. The pin, the reference voltage and the number of readings:

const byte TURB_PIN = A0;                     // the board's OUT
const float VREF = 5.0;                       // the UNO's ADC reference
const byte SAMPLES = 30;

Every 40 ms loop() takes a reading and puts it into a ring of 30, and once a second it reports:

  if (now - lastSample >= 40) {
    lastSample = now;
    readings[next] = analogRead(TURB_PIN);
    next = (next + 1) % SAMPLES;
    if (filled < SAMPLES) filled++;
  }
  if (now - lastReport >= 1000 && filled > 0) {
    lastReport = now;
    report();
  }
  while (Serial.available()) {

The Median of 30 Readings

A bubble in the light path, a spike on the supply or a speck of mud passing the gap can pull one reading far down. The sketch sorts a copy of the last 30 readings and takes the one in the middle. Unlike an average, one wild reading cannot move the median:

int medianOf(int *a, byte n) {                // the middle of a sorted copy: one wrong reading cannot move it
  int s[SAMPLES];
  for (byte i = 0; i < n; i++) s[i] = a[i];
  for (byte i = 1; i < n; i++) {
    int v = s[i];
    byte j = i;
    while (j > 0 && s[j - 1] > v) { s[j] = s[j - 1]; j--; }
    s[j] = v;
  }
  return s[n / 2];
}

The Curve

ntuOf() applies the published curve inside its range: above 4.2 V it says 0 NTU, at 2.56 V and below 3000 NTU, the formula in between:

float ntuOf(float v) {                        // the maker's curve, inside its range
  if (v >= 4.2) return 0;
  if (v <= 2.56) return 3000;
  float ntu = -1120.4 * v * v + 5742.3 * v - 4352.9;
  if (ntu < 0) ntu = 0;
  return ntu;
}

report() takes the median (or, with FILTER 0, the newest reading) and turns it into volts with the 5 V reference. Two checks first: an analogRead above 960 or below 20 cannot be an analog turbidity signal, so the switch must be on D:

  if (raw > 960) { Serial.println(F("D HIGH: the switch is on D - clearer than the threshold")); return; }
  if (raw < 20) { Serial.println(F("D LOW: the switch is on D - more turbid than the threshold")); return; }

Otherwise it adds the probe's offset, applies the curve and prints the NTU with a word - clear below 5, cloudy below 100, turbid below 1000, muddy above - and two warnings: above 4.25 V the probe is probably in air, and at 2.56 V and below the water is beyond the curve:

  float v = volts + offsetV;
  float ntu = ntuOf(v);

The Commands

CAL calibrates the probe in clear water: the curve wants 4.20 V there, so the offset becomes 4.20 V minus the last reading. It refuses when the reading cannot be clear water:

  if (!strcmp(c, "CAL")) {
    if (lastVolts > 3.5 && lastVolts < 4.6) {
      offsetV = 4.2 - lastVolts;
      Serial.print(F("offset = "));
      if (offsetV >= 0) Serial.print('+');
      Serial.print(offsetV, 3);
      Serial.print(F(" V (clear water read "));
      Serial.print(lastVolts, 3);
      Serial.println(F(" V; the curve wants 4.20 V)"));
    } else Serial.println(F("CAL: put the probe in clear water first (the switch on A)"));

OFFSET x sets the offset by hand, FILTER 0 reports single readings instead of the median and FILTER 1 brings the median back. The HEX file is in the package, so you do not need the Arduino IDE to run the demo. To change the sketch, open it in the Arduino IDE and export the compiled binary, as in How to get the HEX file from Arduino. It needs 8,198 bytes of flash and 348 bytes of RAM.

The Serial Monitor: Tap Water

Turbidity readings in the built-in serial monitor of the Arduino UNO V4.0
Figure: ARD1's monitor: the header, then tap water - ADC 860, 4.199 V, 4 NTU, clear.

Both UNOs have the serial monitor built in, and it opens at Run. The screenshots use its Simple interface. The sketch prints its header and the commands, and a report arrives every second:

TEP turbidity sensor - demo V1.0
OUT on A0 (switch on A): a reading every 40 ms, the median of 30 each second
Commands: CAL (in clear water), OFFSET x, FILTER 0 / 1, HELP
#1  t=1 s  ADC 845  4.126 V  NTU 266  turbid
#2  t=2 s  ADC 860  4.199 V  NTU 4  clear
#3  t=3 s  ADC 860  4.199 V  NTU 4  clear
#4  t=4 s  ADC 860  4.199 V  NTU 4  clear
#5  t=5 s  ADC 860  4.199 V  NTU 4  clear

From the second report node 1 reads 4 NTU, clear: ADC 860 is 4.199 V, and one ADC step lower would already be about 20 NTU, so the 4 is simply the resolution of the UNO's 10-bit converter near clear water. The first report is higher because its median still holds readings from the moment the board was switched on, while its output rose.

Clear water read as turbid by an uncalibrated turbidity probe, in the serial monitor
Figure: ARD2's monitor: the same sketch reads clear water as 533 NTU, turbid - the probe gives 4.05 V instead of 4.20 V.
#1  t=1 s  ADC 816  3.984 V  NTU 740  turbid
#2  t=2 s  ADC 829  4.048 V  NTU 533  turbid
#3  t=3 s  ADC 829  4.048 V  NTU 533  turbid
#4  t=4 s  ADC 829  4.048 V  NTU 533  turbid
#5  t=5 s  ADC 829  4.048 V  NTU 533  turbid
#6  t=6 s  ADC 829  4.048 V  NTU 533  turbid

Node 2 stands in clear water, yet the sketch reads 533 NTU, turbid. Nothing is wrong with the water: the probe gives 4.048 V in clear water, 0.15 V less than the curve expects, and near clear water 0.15 V is more than 500 NTU. Let's see what the pop-up says.

The Advance Pop-Up Window

At Run, U2 opens its own window, Turbidity Sensor, with the look of our TEP Serial Monitor Advance for Proteus. It has three tabs, Sensor, Event log and Tests, plus Settings and Help behind the gear and question mark icons. The status bar at the bottom always shows the water, the output and what the curve reads.

Turbidity sensor Advance pop-up with clear water and a probe off the curve
Figure: U2 at the start: clear water, 4.042 V on OUT - the curve reads 526 NTU, with this probe's zero 1 NTU.

The toolbar carries the presets. The water at the probe has -500 / -50 / +50 / +500 NTU, the A / D switch, the threshold with -100 / +100, the actions and the ruler. What the board gives shows the banner and four tiles: OUT, what the curve as published reads, the reading with this probe's zero, and the digital level of the comparator. The curve draws the published curve in grey and this probe's curve in blue, with the threshold as an amber line and the point where the signal is right now, and the last 150 s plots the water (green) and what the curve reads (blue dots). The amber banner already says it: this probe gives 4.05 V in clear water, the curve reads 526 NTU for 0 NTU - CAL in clear water.

Calibration & Supply

Turbidity sensor Calibration and supply test tool: a probe that gives 4.05 V in clear water
Figure: Calibration and supply on U2: the probe gives 4.05 V in clear water (-0.15 V); clear water reads 526 NTU; CAL would add +0.150 V.

The Calibration & supply tool explains the error: the probe gives 4.05 V in clear water at 5 V, the curve expects 4.20 V, so clear water reads 526 NTU, and near clear water 0.1 V is about 370 NTU. The supply is a clean 5.00 V here. The fix is CAL with the probe in clear water: an offset of 4.20 V minus the reading, here +0.150 V.

CAL in Clear Water

So we typed CAL in ARD2's monitor - the probe stands in clear water:

Turbidity sensor calibrated with CAL in clear water
Figure: ARD2's monitor: CAL in clear water - offset = +0.147 V, and from then on 0 NTU, clear.
#6  t=6 s  ADC 829  4.048 V  NTU 533  turbid
#7  t=7 s  ADC 830  4.053 V  NTU 517  turbid
#8  t=8 s  ADC 830  4.053 V  NTU 517  turbid
CAL
offset = +0.147 V (clear water read 4.053 V; the curve wants 4.20 V)
#9  t=9 s  ADC 830  4.053 V  NTU 0  clear
#10  t=10 s  ADC 830  4.053 V  NTU 0  clear
#11  t=11 s  ADC 830  4.053 V  NTU 0  clear
#12  t=12 s  ADC 830  4.053 V  NTU 0  clear

CAL takes the last reading, 4.053 V, and works out the offset: +0.147 V. From the next second on the sketch adds it to every reading, and clear water reads 0 NTU, clear. The offset is 3 mV smaller than the tool's 0.150 V because the last median sat one ADC step higher - near clear water a single step matters.

Pond and River Water

Now the water. We clicked POND in U2's pop-up, waited, and then RIVER:

Turbidity sensor pop-up in river water
Figure: U2 in river water: 250 NTU, 3.981 V - the curve as published reads 752 NTU, with this probe's zero 250 NTU.
Turbidity readings of pond and river water after the calibration
Figure: ARD2's monitor: pond water reads 54 to 90 NTU, cloudy; river water 264 NTU, turbid.
#13  t=13 s  ADC 830  4.053 V  NTU 0  clear
#14  t=14 s  ADC 826  4.033 V  NTU 72  cloudy
#15  t=15 s  ADC 826  4.033 V  NTU 72  cloudy
#16  t=16 s  ADC 826  4.033 V  NTU 72  cloudy
#17  t=17 s  ADC 827  4.038 V  NTU 54  cloudy
#18  t=18 s  ADC 825  4.028 V  NTU 90  cloudy
#19  t=19 s  ADC 815  3.979 V  NTU 264  turbid
#20  t=20 s  ADC 815  3.979 V  NTU 264  turbid
#21  t=21 s  ADC 815  3.979 V  NTU 264  turbid
#22  t=22 s  ADC 815  3.979 V  NTU 264  turbid

The calibrated sketch reads pond water, 60 NTU, as 54 to 90 NTU: the reading jumps between neighbouring ADC values, and each step is still worth about 18 NTU here. River water, 250 NTU, reads 264 NTU. Without the calibration the same probe would say 752 NTU - the pop-up shows both numbers side by side.

Output & Curve

Turbidity sensor Output and curve test tool on river water
Figure: Output and curve on U2 in river water: 3.975 V, the curve 768 NTU, with the probe's zero 4.125 V and 250 NTU, one ADC step 15 NTU.

The Output & curve tool does the sketch's maths with the numbers of this moment: 3.975 V is about 814 in analogRead; the published curve makes 768 NTU of it; with this probe's zero the signal becomes 4.125 V and 250 NTU - the river. One ADC step is worth about 15 NTU here, and the tool also says whether the signal is still on the curve. Open it first when a reading is far off.

BUBBLES: Why the Median Matters

Air bubbles are the classic problem of optical water sensors: a bubble in the gap scatters the light like a cloud of mud. We typed FILTER 0 - single readings - and clicked BUBBLES:

Turbidity readings with air bubbles and no median filter
Figure: ARD2's monitor with FILTER 0: single readings of river water with bubbles - 246 to 298 NTU.
#23  t=23 s  ADC 815  3.979 V  NTU 264  turbid
FILTER 0
filter: off - one reading
#24  t=24 s  ADC 814  3.975 V  NTU 281  turbid
#25  t=25 s  ADC 815  3.979 V  NTU 264  turbid
#26  t=26 s  ADC 813  3.970 V  NTU 298  turbid
#27  t=27 s  ADC 815  3.979 V  NTU 264  turbid
#28  t=28 s  ADC 813  3.970 V  NTU 298  turbid
#29  t=29 s  ADC 814  3.975 V  NTU 281  turbid
#30  t=30 s  ADC 816  3.984 V  NTU 246  turbid
Turbidity sensor pop-up with air bubbles in the light path
Figure: U2 with BUBBLES: short dips of the output - single readings jump, a median hides them.

Every bubble that crosses the gap pulls the signal down for a fraction of a second. With FILTER 0 the sketch prints only the newest reading, so whether it shows a bubble depends on the moment: here the single readings move between 246 and 298 NTU for 250 NTU of river water, and a reading taken just while a bubble crosses the gap can be off by more than a thousand. Then FILTER 1, the median of 30, with the bubbles still rising:

Turbidity readings with air bubbles and the median of 30
Figure: ARD2's monitor with FILTER 1: the median of 30 readings - 264 NTU every second, the bubbles hidden.
#31  t=31 s  ADC 815  3.979 V  NTU 264  turbid
FILTER 1
filter: the median of 30 readings
#32  t=32 s  ADC 815  3.979 V  NTU 264  turbid
#33  t=33 s  ADC 815  3.979 V  NTU 264  turbid
#34  t=34 s  ADC 815  3.979 V  NTU 264  turbid
#35  t=35 s  ADC 815  3.979 V  NTU 264  turbid
#36  t=36 s  ADC 815  3.979 V  NTU 264  turbid

The median reads 264 NTU every single second. A bubble lasts 60 to 200 ms - a few of the 30 readings - and those land at the low end of the sorted list, never in the middle. That is why the demo uses a median instead of an average.

STIR: the Sediment Rises and Settles

Turbidity sensor pop-up after the sediment was stirred up
Figure: U2 after STIR: the sediment rises - 937 NTU at this moment, settling again.
Turbidity readings as the stirred-up sediment settles
Figure: ARD2's monitor: the stirred-up water reads 935 NTU, then falls a few NTU every second - 643 NTU at t=54 s.
#43  t=43 s  ADC 773  3.774 V  NTU 935  turbid
#44  t=44 s  ADC 775  3.784 V  NTU 905  turbid
#45  t=45 s  ADC 778  3.799 V  NTU 860  turbid
#46  t=46 s  ADC 779  3.804 V  NTU 845  turbid
#47  t=47 s  ADC 781  3.813 V  NTU 815  turbid
#48  t=48 s  ADC 783  3.823 V  NTU 784  turbid
#49  t=49 s  ADC 784  3.828 V  NTU 768  turbid
#50  t=50 s  ADC 786  3.838 V  NTU 737  turbid
#51  t=51 s  ADC 788  3.848 V  NTU 706  turbid
#52  t=52 s  ADC 789  3.853 V  NTU 691  turbid
#53  t=53 s  ADC 791  3.862 V  NTU 659  turbid
#54  t=54 s  ADC 792  3.867 V  NTU 643  turbid
Turbidity readings half a minute after the sediment was stirred up
Figure: ARD2's monitor ten seconds later: 498 NTU, falling to 399 NTU - the sediment settles.
#63  t=63 s  ADC 801  3.911 V  NTU 498  turbid
#64  t=64 s  ADC 801  3.911 V  NTU 498  turbid
#65  t=65 s  ADC 802  3.916 V  NTU 482  turbid
#66  t=66 s  ADC 803  3.921 V  NTU 465  turbid
#67  t=67 s  ADC 803  3.921 V  NTU 465  turbid
#68  t=68 s  ADC 804  3.926 V  NTU 449  turbid
#69  t=69 s  ADC 804  3.926 V  NTU 449  turbid
#70  t=70 s  ADC 805  3.931 V  NTU 432  turbid
#71  t=71 s  ADC 805  3.931 V  NTU 432  turbid
#72  t=72 s  ADC 806  3.936 V  NTU 415  turbid
#73  t=73 s  ADC 806  3.936 V  NTU 415  turbid
#74  t=74 s  ADC 807  3.940 V  NTU 399  turbid

STIR stirs up the sediment at the bottom of the beaker: the river water jumps to about 1000 NTU and then settles slowly, as real mud does. The readings fall from 935 NTU to 643 NTU in the first ten seconds and to 399 NTU half a minute after the stir, on their way back to the river's 250. A sketch that alarms at the first high reading would fire here; one that waits for a steady value would not.

FLOOD and MUD: Beyond the Curve

Turbidity sensor pop-up in muddy water beyond the published curve
Figure: U2 in mud: 4000 NTU is beyond the curve - 2.28 V is below 2.56 V, a sketch can only say 3000 NTU or more.
Turbidity readings of flood water and of mud beyond the curve
Figure: ARD2's monitor: FLOOD reads 1500 NTU, muddy; MUD reads 3000 NTU with "beyond the curve".
#74  t=74 s  ADC 807  3.940 V  NTU 399  turbid
#75  t=75 s  ADC 807  3.940 V  NTU 399  turbid
#76  t=76 s  ADC 732  3.574 V  NTU 1500  muddy
#77  t=77 s  ADC 731  3.569 V  NTU 1513  muddy
#78  t=78 s  ADC 732  3.574 V  NTU 1500  muddy
#79  t=79 s  ADC 731  3.569 V  NTU 1513  muddy
#80  t=80 s  ADC 485  2.368 V  NTU 3000  muddy  - beyond the curve
#81  t=81 s  ADC 467  2.280 V  NTU 3000  muddy  - beyond the curve
#82  t=82 s  ADC 467  2.280 V  NTU 3000  muddy  - beyond the curve
#83  t=83 s  ADC 467  2.280 V  NTU 3000  muddy  - beyond the curve

FLOOD, 1500 NTU, reads 1500 - 1513 NTU, muddy - well inside the curve. Then MUD, 4000 NTU: the signal falls to 2.280 V, below the curve's end at 2.56 V, and the sketch prints "NTU 3000 muddy - beyond the curve". The 3000 means "3000 or more": the published formula turns down below 2.56 V, so it cannot tell mud from thicker mud. The pop-up turns red.

PROBE OUT

Back to CLEAR, and then PROBE OUT - somebody lifts the probe out of the water:

Turbidity sensor pop-up with the probe in air: it reads as clear water
Figure: U2 with PROBE OUT: the light passes freely - 4.14 V; the curve reads 182 NTU, with this probe's zero 0 NTU.
Turbidity sensor with the probe in air: probe in air? in the serial monitor
Figure: ARD2's monitor: mud, clear water, then the probe in air - 0 NTU with "probe in air?".
#83  t=83 s  ADC 467  2.280 V  NTU 3000  muddy  - beyond the curve
#84  t=84 s  ADC 689  3.364 V  NTU 1996  muddy
#85  t=85 s  ADC 829  4.048 V  NTU 19  cloudy
#86  t=86 s  ADC 829  4.048 V  NTU 19  cloudy
#87  t=87 s  ADC 845  4.126 V  NTU 0  clear  - probe in air?
#88  t=88 s  ADC 850  4.150 V  NTU 0  clear  - probe in air?
#89  t=89 s  ADC 850  4.150 V  NTU 0  clear  - probe in air?

In air the light crosses the gap without any water to scatter it, so the signal rises above the clear-water value: 4.15 V for this probe, 4.30 V with its offset. The sketch reads 0 NTU and adds "probe in air?" because the corrected signal is above 4.25 V. A dry probe looks like perfectly clear water, so the question mark matters.

The Switch on D

Now the digital output. Back to RIVER, and then D in the pop-up - the same as sliding the board's switch:

Turbidity sensor pop-up with the switch on D: OUT HIGH in river water
Figure: U2 with the switch on D: OUT HIGH - the water is clearer than the threshold, 1000 NTU = 3.75 V.

Now OUT is no longer the turbidity but the comparator: HIGH while the analog signal is above the potentiometer's voltage - clearer water - and LOW below it. The banner turns blue, the threshold of 1000 NTU sits at 3.75 V for this probe, and the river's 250 NTU is far clearer, so OUT is HIGH. Then FLOOD, and six clicks on +100 for the threshold:

Turbidity sensor digital output: D HIGH, D LOW and a new threshold in the serial monitor
Figure: ARD2's monitor: the switch on D - D HIGH for the river, D LOW for flood water, D HIGH again with the threshold at 1600 NTU.
#90  t=90 s  ADC 849  4.146 V  NTU 0  clear  - probe in air?
#91  t=91 s  ADC 816  3.984 V  NTU 246  turbid
#92  t=92 s  ADC 816  3.984 V  NTU 246  turbid
#93  t=93 s  ADC 1004  4.902 V  D HIGH: the switch is on D - clearer than the threshold
#94  t=94 s  ADC 1004  4.902 V  D HIGH: the switch is on D - clearer than the threshold
#95  t=95 s  ADC 1004  4.902 V  D HIGH: the switch is on D - clearer than the threshold
#96  t=96 s  ADC 0  0.000 V  D LOW: the switch is on D - more turbid than the threshold
#97  t=97 s  ADC 0  0.000 V  D LOW: the switch is on D - more turbid than the threshold
#98  t=98 s  ADC 0  0.000 V  D LOW: the switch is on D - more turbid than the threshold
#99  t=99 s  ADC 1004  4.902 V  D HIGH: the switch is on D - clearer than the threshold
#100  t=100 s  ADC 1004  4.902 V  D HIGH: the switch is on D - clearer than the threshold
#101  t=101 s  ADC 1004  4.902 V  D HIGH: the switch is on D - clearer than the threshold

The sketch sees analogRead jump to 1004 - no analog turbidity signal gets that high - and prints "D HIGH". Flood water, 1500 NTU, is more turbid than the 1000 NTU threshold: OUT goes to 0 V and the sketch prints "D LOW". Six clicks later the threshold is 1600 NTU, the same flood water is now clearer than the threshold, and OUT is HIGH again. That is how you set the potentiometer on a real board: put the probe in water just at your limit and turn it until D changes.

Digital & Wiring

Turbidity sensor Digital and wiring test tool: the switch, the threshold and the digital level
Figure: Digital and wiring on U2: the switch on D, the threshold 1600 NTU = 3.53 V, D HIGH with the signal at 3.581 V.

The Digital & wiring tool checks the power - 5.00 V, up to 40 mA for the infrared LED - and turns amber when the switch is on D, because then analogRead gives only 0 or about 1000. It shows the threshold in NTU and volts, the digital level with the signal behind it, the probe and the cable. Open it when a sketch reads only 0 or 1023. Then we clicked A again.

The Event Log

Turbidity sensor Advance pop-up Event log in Proteus: the readings, the water and a warning, newest first
Figure: The Event log of U2: the readings every 5 seconds, every change of the water and of the board, a note and a warning, newest first.

The Event log lists everything that happened, newest first: power, a reading every 5 seconds with the curve with and without this probe's zero, every change of the water, the switch and the potentiometer, notes and warnings - here the whole story of node 2 backwards, from the switch back on A and the six steps of the potentiometer down to the river water. Filter it, pause it, or clear it.

The Water and the Switch on the STATUS Panel

Back to node 1. We clicked U1's STATUS panel and its board with the mouse while the simulation ran. First RIVER:

Turbidity sensor STATUS panel in Proteus in river water
Figure: U1 with RIVER: 250 NTU and 4.136 V on OUT, read as 250 NTU; the water in the beaker turns grey-green.
Turbidity sensor reading river water in the serial monitor of node 1
Figure: ARD1's monitor: tap water reads 4 NTU, river water 249 NTU.
#105  t=105 s  ADC 860  4.199 V  NTU 4  clear
#106  t=106 s  ADC 860  4.199 V  NTU 4  clear
#107  t=107 s  ADC 860  4.199 V  NTU 4  clear
#108  t=108 s  ADC 859  4.194 V  NTU 22  cloudy
#109  t=109 s  ADC 846  4.131 V  NTU 249  turbid
#110  t=110 s  ADC 846  4.131 V  NTU 249  turbid
#111  t=111 s  ADC 846  4.131 V  NTU 249  turbid
#112  t=112 s  ADC 846  4.131 V  NTU 249  turbid

Node 1's probe follows the curve, so it needs no calibration: tap water reads 4 NTU and river water 249 NTU one report after the click. In the beaker the water turns from clear blue to a cloudy grey-green.

The Board's Switch

Then STIR, and half a minute later a click on the A / D switch of the board itself:

Turbidity sensor board in Proteus with its slide switch on D and the D LED lit
Figure: U1 with its slide switch on D after STIR: the D LED is lit - 401 NTU is clearer than the 1000 NTU threshold.
Turbidity sensor on D in flood water: the D LED off
Figure: U1 on D in flood water: OUT LOW, the D LED off - 1500 NTU is more turbid than the threshold.
Turbidity sensor D HIGH and D LOW in the serial monitor of node 1
Figure: ARD1's monitor: the stirred water settling at 451 NTU, then D HIGH after the switch, D LOW in flood water.
#140  t=140 s  ADC 834  4.072 V  NTU 451  turbid
#141  t=141 s  ADC 834  4.072 V  NTU 451  turbid
#142  t=142 s  ADC 834  4.072 V  NTU 451  turbid
#143  t=143 s  ADC 1004  4.902 V  D HIGH: the switch is on D - clearer than the threshold
#144  t=144 s  ADC 1004  4.902 V  D HIGH: the switch is on D - clearer than the threshold
#145  t=145 s  ADC 1004  4.902 V  D HIGH: the switch is on D - clearer than the threshold
#146  t=146 s  ADC 1004  4.902 V  D HIGH: the switch is on D - clearer than the threshold
#147  t=147 s  ADC 1004  4.902 V  D HIGH: the switch is on D - clearer than the threshold
#148  t=148 s  ADC 0  0.000 V  D LOW: the switch is on D - more turbid than the threshold
#149  t=149 s  ADC 0  0.000 V  D LOW: the switch is on D - more turbid than the threshold
#150  t=150 s  ADC 0  0.000 V  D LOW: the switch is on D - more turbid than the threshold
#151  t=151 s  ADC 0  0.000 V  D LOW: the switch is on D - more turbid than the threshold

The stirred-up water had settled to about 451 NTU when we clicked the switch: the knob moves to D, the D LED lights and the sketch prints "D HIGH". With FLOOD the water is more turbid than the threshold, the LED goes out and the sketch prints "D LOW". A second click on the switch brought the analog signal back: 1502 NTU, muddy.

PROBE OUT on the Panel

Turbidity sensor STATUS panel in Proteus with the probe in air
Figure: U1 with PROBE OUT: the water drops below the probe, the panel says IN AIR - 4.294 V, read as 0 NTU.
Turbidity sensor with the probe in air in the serial monitor of node 1
Figure: ARD1's monitor: flood water, tap water again, then the probe in air - 0 NTU with "probe in air?".
#152  t=152 s  ADC 760  3.711 V  NTU 1527  muddy
#153  t=153 s  ADC 762  3.721 V  NTU 1502  muddy
#154  t=154 s  ADC 762  3.721 V  NTU 1502  muddy
#155  t=155 s  ADC 762  3.721 V  NTU 1502  muddy
#156  t=156 s  ADC 762  3.721 V  NTU 1502  muddy
#157  t=157 s  ADC 857  4.185 V  NTU 57  cloudy
#158  t=158 s  ADC 861  4.204 V  NTU 0  clear
#159  t=159 s  ADC 860  4.199 V  NTU 4  clear
#160  t=160 s  ADC 880  4.297 V  NTU 0  clear  - probe in air?
#161  t=161 s  ADC 881  4.302 V  NTU 0  clear  - probe in air?
#162  t=162 s  ADC 881  4.302 V  NTU 0  clear  - probe in air?
#163  t=163 s  ADC 881  4.302 V  NTU 0  clear  - probe in air?

After TAP the reading falls back to 0 - 4 NTU, and with PROBE OUT the signal rises to 4.302 V: "probe in air?". The water in the beaker drops below the probe, and the STATUS panel says IN AIR in red. Finally the probe went back into the water, and the red X and the PANEL button closed and reopened the STATUS panel.

The Simulation Log

Turbidity sensor Proteus simulation log: the start-up and the readings
Figure: The simulation log of the final run: both turbidity sensors at power-on, a reading every 5 seconds and the water of node 2.

The sensors also write to the simulation log of Proteus, with the exact simulation time. These lines show the start and the water of node 2:

U2: TEP Turbidity Sensor V1.0 - optical turbidity sensor, 0 - 4.5 V on OUT (clear water 4.2 V at 5 V) or D against 1000 NTU; the water 0 NTU, the probe's zero 4.05 V, the switch on A - TEPTURBIDITY.DLL v1.0
U1: TEP Turbidity Sensor V1.0 - optical turbidity sensor, 0 - 4.5 V on OUT (clear water 4.2 V at 5 V) or D against 1000 NTU; the water 1 NTU, the probe's zero 4.20 V, the switch on A - TEPTURBIDITY.DLL v1.0
U2: POWER ON - VCC 5.00 V: the infrared LED lights, the output rises to 4.050 V (0 NTU; the analog output) at 0.0000 s
U2: the output 0.508 V (analogRead about 103) - the curve gives 3000 NTU, 3000 NTU with this probe's zero 4.05 V at 0.0000 s
U1: POWER ON - VCC 5.00 V: the infrared LED lights, the output rises to 4.200 V (1 NTU; the analog output) at 0.0000 s
U1: the output 0.524 V (analogRead about 107) - the curve gives 3000 NTU, 3000 NTU with this probe's zero 4.20 V at 0.0000 s
ARD2: supply pins at 0.001 s - 5V 5.000 V, 3.3V 3.300 V, IOREF 5.000 V (to GND)
ARD1: supply pins at 0.001 s - 5V 5.000 V, 3.3V 3.300 V, IOREF 5.000 V (to GND)
U2: the output 4.046 V (analogRead about 828) - the curve gives 526 NTU, 1 NTU with this probe's zero 4.05 V at 5.0000 s
U1: the output 4.199 V (analogRead about 860) - the curve gives 1 NTU, 1 NTU with this probe's zero 4.20 V at 5.0000 s
U2: the output 4.053 V (analogRead about 830) - the curve gives 526 NTU, 1 NTU with this probe's zero 4.05 V at 10.0000 s
U1: the output 4.200 V (analogRead about 860) - the curve gives 1 NTU, 1 NTU with this probe's zero 4.20 V at 10.0000 s
U2: the water: POND, 60 NTU (pond water; in U2's pop-up) at 12.8514 s
U2: the output 4.032 V (analogRead about 825) - the curve gives 580 NTU, 60 NTU with this probe's zero 4.05 V at 15.0000 s
U1: the output 4.202 V (analogRead about 860) - the curve gives 1 NTU, 1 NTU with this probe's zero 4.20 V at 15.0000 s
U2: the water: RIVER, 250 NTU (river water; in U2's pop-up) at 17.5926 s
U2: the output 3.978 V (analogRead about 814) - the curve gives 752 NTU, 250 NTU with this probe's zero 4.05 V at 20.0000 s

Each sensor reports its water, its probe's zero and the switch at the start - clear water with 4.05 V for U2, tap water with 4.20 V for U1 - and the voltage its output rises to. The readings at 0.0000 s are taken the moment the power comes on, while the output still rises from 0 V, so they mean nothing; from 5 s on every reading gives the curve as published and with the probe's zero: for U2 in clear water 526 NTU against 1 NTU. Then come the changes of node 2's water.

How the Model Works

The turbidity sensor is an analog model. VCC and GND power the board, and OUT is a voltage source behind 1 kohm. For the water in the beaker the model works out the voltage the published curve turns back into the water's turbidity, shifts it by the probe's zero and scales it with the supply. The output follows that voltage with a time constant of 0.15 s, gets 5 mV of noise and, during BUBBLES, short dips. It changes in steps of 20 ms, and the model tells Proteus where each step falls. With the switch on D the comparator compares the signal with the potentiometer's voltage, with a 50 mV hysteresis, and OUT gives about 0.98 x VCC or 0 V. STIR adds sediment that settles with a time constant of 20 s, and DILUTE mixes in with 1.5 s.

If you work with water quality, have a look at our TDS Meter Library for Proteus too: TDS tells you what is dissolved in the water, turbidity what floats in it, and the two sensors are often used side by side.

Troubleshooting

  • Clear water reads hundreds of NTU: the probe gives less than 4.20 V in clear water, or the supply is below 5 V - type CAL with the probe in clear water.
  • Always 0 NTU: the probe is in air - a dry probe reads as clear water - or the water really is clear.
  • "3000 NTU muddy - beyond the curve": the water is more turbid than the curve can tell.
  • Only 0 or about 1004 on analogRead: the board's switch is on D.
  • Single readings jump by hundreds of NTU: bubbles in the light path - keep the median filter on (FILTER 1).
  • No part or no monitor: TEPTURBIDITY.DLL or TEPARDUINO.DLL is missing from MODELS and the project folder; a closed monitor opens again with a click on the UNO's USB port.

Things to Know Before Using a Real Turbidity Sensor

  • Power: 5 V and up to 40 mA. The output follows the supply - calibrate on the supply you use, because USB often gives 4.8 V.
  • 3.3 V boards: the output reaches 4.5 V, so put a divider, for example 10 k and 20 k, on OUT.
  • Calibration: calibrate each probe in clear, filtered or bottled water; the curve is steep there.
  • Water: only the probe's tip is waterproof, not its top and not the board. Keep the windows of the tip clean - a film or a fingerprint scatters the light like turbid water.
  • Light and bubbles: strong sunlight on the gap and bubbles on the windows disturb the reading; mount the probe in the shade, where no bubbles collect.

Limitations of the Simulation

  • Not modelled: the water's colour (dissolved dye absorbs light too), the water's temperature, stray light, a dirty probe, the size of the particles, the probe's ageing and the exact behaviour on a 3.3 V supply.
  • The model's own choices: the ZERO property, the output beyond the curve (0.2 V per 1000 NTU down to 1.0 V), 4.30 V in air, the output in proportion to VCC, the lag of 0.15 s, the noise of 5 mV with a new value every 20 ms, the digital polarity and its hysteresis, STIR, BUBBLES, DILUTE's mixing and the values of the presets.
  • The beaker, the badge, the LEDs, the panel button and the panels are TEP additions.
  • The model is our own, written from the maker's published data. This library is not made or endorsed by the sensor's maker or by Labcenter.
  • Licences: the demo sketch uses no library; the HEX file contains the Arduino AVR core 1.8.6 with LGPL-licensed code - the source link is in the README.
  • Tested in Proteus 8.5 in October 2026 (the demo as shipped on two Arduino UNO V4.0 boards with their built-in monitors: CAL in clear water, POND, RIVER, BUBBLES with FILTER 0 and 1, STIR, FLOOD, MUD, PROBE OUT, the switch on D with a new threshold and the three tools on the Advance sensor; RIVER, STIR, the board's switch, FLOOD, TAP, PROBE OUT, the red X and PANEL with the mouse on the Simple one; 175.1 s of simulation took 1,304 s, about 0.13 x real time with the pop-up and both monitors open on a busy PC). Proteus 7 is not supported.

So, that was all about the Turbidity Sensor Library for Proteus V1.0. I hope the curve from volts to NTU, the calibration in clear water, the A / D switch and the limits of the probe are clear now, and that your water quality project works from the first run. If you use the Turbidity Sensor Library for Proteus in a project, please share it in the comments or in our forum, and if you have any questions, ask in the comments and I will help you out. Till the next tutorial, take care and have fun!


Comments

0

Join the conversation