AN-1147 Salinity Sensor

The GreenPAK™ device can be employed in simple salinity measurement applications using low cost materials and techniques.

This document explores the use of the SLG46531V along with the SLG88102V for the measurement of salinity in drinking water. It is to be noted that the procedures documented can be used for different Electric Conductivity (EC) values; this means that this implementation can be used in a wide range of alternate applications such as hydroponics agriculture, chemical readings and more.

Theory of sensing

Water salinity is, as the name indicates, the quantity of salts present in a certain quantity of water. In order to measure this value, we need to correlate it to an electronic reading; in this case we correlate the salinity to a voltage.

This can be achieved by analyzing the conductivity of water. At a given state, distillated water has a specific EC (Electric Conductivity); the change in its EC can thus be related to the quantity of salts dissolved in it. A voltage divider can be used to analyze the EC of the water to get an idea of its value; the higher the EC, the lower the resistance presented by the probe will be. This, in turn, corresponds to a lower voltage in the voltage divider.

The Electric Conductivity uses a unit called Siemens (S) and for this application we will be using mS/cm.

Usually the EC is measured using AC voltage because DC polarizes the liquid in the probe rendering the readings useless. A quick measure using DC can however be made if we use a pulse and then wait a few seconds for the next reading; this avoids polarizing by not letting the voltage reach the polarizing point.

Also, when the voltage is cut off the voltage divider, the liquid between the plaques of the probe returns to normal.

We will be using the previously mentioned method (Turning on for enough time to make the reading, and then turning the voltage off for a longer time than it was turned on.), in a system that periodically reads the EC and displays the output with a set of LEDs.

Designing the sensing circuit

We can design our own probe or measuring cell, using two traces of a conductor with a known area and distance between the two traces. They need to be parallel to each other and the liquid must also be between the traces.

To get EC we need G (Conductance).

The Conductance is defined as:


and we define A/L as K.

For this application we will suppose a K constant of 3 and we will be looking for specific EC values shown in Table 1.

EC (mS/cm) Description
0.159 mS/cm Fresh Water
0.781 mS/cm Max. Salinity Admissible in Tap water
1.56 mS/cm Salinity in No drinkable water


Table 1. EC values

We need to know the range of voltage we will be obtaining from the voltage divider (V reading) as shown in Figure 1.

Sensor Voltage Divider

Figure 1. Sensor Voltage Divider

We calculate an approximate resistance for the probe after supposing a minimum and a maximum range of EC values using Table 1, and implementing the following formula:



(1) Can be reached once we acknowledge that G = EC*A/L and G= 1/R.



And finally K = A/L so L/A = 1/K


EC is in S/cm so we multiply by 1000 to use mS/cm.

Note this formula is in units of mS/cm.

Moreover, the formula does not cater for the change in T, so the solutions must be at a range between 20-25 C°. To cater for T we can use the following set of formulas:





But this time, we will not be catering for the value of T.

Substituting the EC values of 1.59 mS/cm and 0.159 mS/cm in (1), we can make a simple look-up table with several values for R1, for us to select from. Note that 220 Ohm and 2.1 kOhm are the resistive values that are expected to be reached by the probe.

This way we know that we can have a maximum of 2.41 volts between EC values of 0.159 mS/cm and 1.59 mS/cm.

This entails that we can sense using these 2.41 volts; the EC ranges between 0.159 mS/m and 1.59 mS/cm. In order to keep the rest of this simpler, we will focus on the EC values of 0.159 mS/cm, 0.781 mS/cm and 1.59 mS/cm as these values have great significance for drinking water. We also have to point out that the R1 resistor will have a value of 700 Ohms.

R1 Vout @ 220 ohm Vout @ 2.1kohm Vout range
300 1.99 4.11 2.12
400 1.67 3.95 2.28
500 1.44 3.80 2.36
600 1.26 3.66 2.40
700 1.12 3.53 2.41
800 1.01 3.40 2.39
1000 0.85 3.18 2.33


Table 2. R1 and corresponding Vout values

Limiting the Readings

Since we are only looking for three EC numbers, we can obtain the expected voltage reading for them and use the SLG88102V to sense the values in order to obtain 3 digital outputs. We do this because the SLG46531V doesn't have an ADC. We can see the logic expected by the use of the SLG88102V in Table 3.

Vreading < Vexpected Vreading > Vexpected
EC Vexpected 0.159_EC 0.781_EC 1.59_EC 0.159_EC 0.781_EC 1.59_EC
0.159 3.53 1 0 0 0 0 0
0.781 1.76 1 1 0 1 0 0
1.59 1.12 1 1 1 1 1 0


Table 3. Sensing Logic Table

We will be using inverted logic when the voltage sensed is bigger than the voltage expected. In such a scenario, the output of the SLG88102V will be LOW; otherwise it will be HIGH. Table 4 further shows this logic.

1.59_EC 0.781_EC 0.159_EC Water Quality R_LED Y_LED G_LED
0 0 1 Fresh Water 0 0 1
0 1 1 Tap Water 0 1 0
1 1 1 Salt Water 1 0 0


Table 4. LED Output Logic Table

We can depict those three water quality standards as 3 LEDs (Green, Yellow and Red) and can thus measure the limits of drinkable water.

The SLG88102V has four OPAMPs; three of them must be configured as a comparator, just as it is shown in Figure 2. It is not compulsory to use the three thresholds; we can use just two of them to mark two different levels. In such a case, we could also use the Dual PAMP SLG88101V.

SLG88102V schematic

Figure 2. SLG88102V schematic

VExpected can be obtained from Table 3.

When Vreading is bigger than VExpected, this configuration outputs the Value of LOW; it’s VDD when V reading is not big enough, which makes the three outputs become our 3-bits.

We can obtain the VExpected using voltage dividers on another PIN configured as a digital output.

The comparator’s outputs will need to go to the selected PINs in the SLG46531V. This can be viewed in Table 3.

Programming the SLG46531V

First, we define three pins as digital inputs: PINs 3, 4 and 6 (1.59_EC, 0.781_EC and 0.159_EC respectively). These 3 PINs will be reading continuously, but since we are sensing every 6.34 seconds, we need to get the reading and interpret it at the same moment that we are sending the reading pulse. We achieve this by implementing a logic function using the same signal i.e. sent every 6.34 seconds.

As the SLG46531V has a fast response, the duration of the pulse does not give enough time to the voltage to reach the thresholds needed for the readings.

So, we have to add a delay in the output of the counter amounting to around 657 milliseconds.

The functions used are 3-Bit and 2-Bit LUTs that are programmed to only give a HIGH to PIN 13 (R_LED) when Vreading is lower than the voltage expected and when the EC is of 1.59 mS/cm. A HIGH is sent to PIN 14 (Y_LED) when the Vreading is bigger than the voltage expected from the EC of 1.59 mS/cm and smaller than the voltage expected for an EC of 0.781 mS/cm. Finally a HIGH is sent to PIN 16 (G_LED) when Vreading is bigger than the voltage expected from an EC of 0.781 mS/cm.

It would be hard to interpret the readings if the LED turns ON for only a few milliseconds; this means that we have to store the values of each reading. For that we use another configurable LUT (Look UP Table) and we select its Type as a LATCH. LATCH has a table of truth shown in Figure 3.

LUT table

Figure 3. LUT table

If we use the LATCH then we have to agree to a CLK signal; the LATCH will save the value when CLK is LOW and keep the past state when CLK is HIGH.

For the CLK we will once again use the Pulse i.e. generated every 6.34 seconds. This time we will first send it to an inverting gate; so when the pulse is set to LOW, the CLK in the LATCH will be in a HIGH state, and when it changes for a few milliseconds to LOW, it will store the reading. Finally, when it turns back to HIGH, the LATCH will keep the last stored value.

In Figure 4 we can see how the finished program looks. The logic gates present before the output PINs are there to make sure that only one LED will be turned on at a time. For that, we refer to Table 4.

GreenPAK Designer schematic

Figure 4. GreenPAK Designer schematic

The logic gates present before the output PINs are there to make sure that only one LED will be turned on at a time. For that, we refer to Table 4.

The logic was explained previously, and a file containing the project accompanies this note.

This method still leaves us plenty of resources to use inside the SLG46531V.

The final part is to connect the LEDs to ground using a resistor between the LED and ground to limit the current and also prevent any possible damage in the OUTPUT PINs, or in the LED.

It is also worth mentioning that if needed, a start button can be implemented in order to know when the first reading is being made.

This can be achieved using a latch to store the value of the button and using an AND gate to make sure that the readings are only done and stored after the button or switch is activated.

Another way round

As previously mentioned, the SLG46531V does not have a proper ADC; but if we don't need more resources from the SLG46531V and also don't have a SLG88102V available, then we can also use the three of the four analog comparators present inside the SLG46531V.

In this scenario, obtaining a more suitable voltage range requires a few more calculations in order for us to fully use the capabilities of the analog comparator.

Shown in Figure 5, the analog comparator can have its negative input configured to an internal reference.

Analog Comparator configuration

Figure 5. Analog Comparator configuration

We can select diverse internal reference voltages for the comparator. However, the max reference voltage is around 1200 mV, which is not enough to cater for our current needs, and would also use up GPIO PINs.

Moreover, every analog comparator can only sense through a predefined PIN, which makes designing a little more limited.

However, the ACMP has an amazing function: the input gain.

It raises the effective max comparison voltage of 1200 milivolts to a whopping 4800 milivolts depending on the selected gain. Conversely, using the gain function increases power consumption, rendering necessary the use of WAKE/SLEEP cycles. In this application, slight ups and downs in the readings are not a big deal; but configuring said cycles would be extra work if the SLG88102V is used.

Here, if a Temperature compensator were to be implemented in the same SLG46531V, the PINs used for the ACMP could get used for this purpose instead.

If we were to summarize the advantages, we would get the following.

Using SLG88102V Only using SLG46531V
Lower Input current needed (pA) Current Needed for the inputs in order of uA
More resources avaible in the SLG46531V One chip solution


Table 5. Advantages of SLG46531V and SLG88102V usage


In this section, we will see the manufacture and the results of the device.

The reference voltages were obtained via a voltage divider whilst using the calculated resistances.

The device was built using a protoboard and an MCU to provide a stable 5V supply for the SLG88102V; the voltage dividers get used for the expected voltage values.

From left to right in Figure 6: Salt water, Tap water, Bottled Water.

Also in Figure 6, the output LED in the PAK5 development kit corresponds to the PIN 13.

The other PINs in the bottom part of the kit represent the constant HIGH readings coming from the SLG88102V. The output LED corresponds to R_LED in the designing so this means that the water is not drinkable. Figure 7 shows a close up of the LEDs

In Figure 8, the probe is in the bottled water container and the output LED corresponds to the G_LED, which was designed to be the LED indicating that the water was drinkable.

Figure 9 is a close up of the LEDs.

Finally in Figure 9, the probe is in the tap water container; the output LED is the one corresponding to Y_LED, which was designed to be the output for the salinity of city tap water.

Figure 10 shows another close up of the LEDs that are “on” at the moment.

Salt Water

Figure 6. Salt Water

Salt Water Indicator

Figure 7. Salt Water Indicator

Bottled Water

Figure 8. Bottled Water

Salt Water Indicator

Figure 9. Bottled Water Indicatorr

Tap Water

Figure 10. Tap Water

Tap Water Indicator

Figure 11. Tap Water Indicatorr

Probe selection

The probe selected was a 1-15 NEMA Type A Plug, which has a K of approximate 3 (2.9 to be precise).

The mentioned K, like the 1-15 NEMA, is a standard which should be true for the one used in this project and future ones.

K can also be obtained using the formula K = A/L. This can be used to design a new probe for other applications.

Conclusion and Notes regarding the scope of the application

Procedures documented in this application note can also be used for other EC values, expanding possible end applications and use cases.

As mentioned before, T (Temperature) affects the conductance of liquids, but it doesn’t change it in a linear way; to adjust it, we can calculate another range of EC values.

Even if the present procedure does not include any temperature compensation, the formulas have been mentioned, if needed. It's only a matter of following the same procedure with a different set of values.

For example, if we were to measure the salinity of a reef tank, we would need to be reading an EC of 56 mS/cm as it is the ideal value. In this scenario, we can make a simple range: 56 being “ideal”, 55 being “low salinity” and 57 “high salinity”.

Then, we would have to calculate the maximum and minimum values of resistance that the probe could reach. After that, we would have to select a value for resistor R1, and follow that by calculating the voltages we would expect to see of the three levels of salinity.

Design the voltage dividers for the reference voltage and implement the 88102. Finally, we change the purpose of the same application.

It is worth noting that if we were to build the probe; stainless steel would be the ideal material to use as it would last longer in cases of repeated submersion in high salinity fluids.

Be sure to always rinse the probe with distillated water before and after exchanging solutions. This prevents the previous solution from contaminating the new one for more accurate readings.

About the Author

Name: Onésimo Ivan Fernandez

Background: Mechatronic engineer graduated from UDLAP. He is currently pursuing a Master's degree in the field of Electronics and Computer Science. Focused on electronics and programming, Ivan developed and improved several projects during his senior year in college. He also participated and became the 2016 finalist in the INF Challenge in Mexico.




See full list of Application Notes

© 2017 Silego Technology. 1515 Wyatt Drive, Santa Clara, CA 95054.
Facebook LinkedIn Twitter YouTube Google