Help converting a formula in code

I am trying to use a thermistor to get TDS readings but am having a little issue converting the following formula into code that can be understood by my Arduino.

[1 Siemens = 1 S = 1 (ohm)-1 = 1 mho]

[1 dS/m = 1 mS/cm = 1 mmho/cm]

TDS (mg/L) = K [EC (dS/m)]

Can someone help me out a little or point me in the right direction?

Well... I don't understand 8)

shutterflypro: [1 Siemens = 1 S = 1 (ohm)-1 = 1 mho]

[1 dS/m = 1 mS/cm = 1 mmho/cm]

TDS (mg/L) = K [EC (dS/m)]

What is "mmho", "dS" and "mho" ? You write : "1 (Ohm)-1", so 1-1=0 no ? Can you be more precise please.

EDIT : I made some research, it's always better :P So, you need to calculate TDS, but how do you get mg*/L* ? mmho is milli mho ? and dS what is it ?

Very many people on this forum know how to write code thus converting equations to code and would love to help you if you explained all those acronyms, which very few on this forum know without extensively googling and reading. We are not machines. We need some meaning to the words.

Even after googling and reading, I still don't understand what your input is. If you have a formula, you have at least one input or independent variable. I see the dependent variable is TDS but what is the indep. ? Thermistor resistance?

That's it : First you need to now the coefficient of your sensor. Have you a reference ? Please give more details.

We are using HM Digital, Inc. SP-5 sensor. They will provide very little data about how this is done. Even their datasheet is vague. They only give that no temperature compensation is needed at 25 degrees C

What I have found out though is that the sensor is basically a Thermistor. It has 4 wires and two are for transmitting a pulse and two for receiving it. The formula I posted earlier is one that I found for calculating TDS. This exact setup is the same as if you were trying to calculate the conductivity of a liquid or object. Once the conductivity is figured out it is a simple formula to translate to TDS.

So what are the ideas.....


1 Siemens = 1 S = 1 (ohm)-1 = 1 mho

is nonsense.

1 Siemens = 1 S = 1 (ohm)-1 = 1 mho

You’re right AWOL :slight_smile: (ohm)-1 is the first name of the Siemens; Thus, S = 1 / R

Well… maybe you can use the digital Input. The two wires transmitting pulse go into a circuit link to an arduino digital input, and which is normally opened (like a relay).
Each time the sensor sends a pulse, the circuit becomes closed, then Arduino knows that there is a pulse. You get my point ?

But what the current and the tension of you’re pulse ? How it works ?

Here’s what I’ve got:
Siemens is the unit for electrical conductance, basically reciprocal of resistance.
So, G [S ] = 1 / R [ohm]
1 (ohm)-1 I suppose means (1 ohm)-1
1 mho apparently follows some, to me obscure, convention of right to left reading of reciprocal numbers. Rubbish. We have an SI unit, so lets all agree to use that one.

[1 dS/m = 1 mS/cm = 1 mmho/cm] translates to:
1 deciSiemens / meter = 1 miliSiemens / centimeter = (1/miliohm) / centimeter
0.1 S / m = 10 ohm / m

TDS (mg/L) = K [EC (dS/m)]
TDS could very well be total dissolved solids, judging by the mg/L part. K and EC elude me, for now.

Yes, TDS is Total Dissolved Solids and this is the number that I ultimately want to get from the equation.

EC is electrical conductivity. If someone knows how to get the Electrical Conductivity from a Thermistor then with a simple equation TDS can be found.

It is getting the EC that is throwing a monkey wrench into the picture.

K is a coefficient, because TDS function of EC is linear. But "m" is the size of the sensor ?

I just googling about the EC of a transistor (I think you can googling too before asking us). And it seems to be rather complicate...

So your problem isn't math, but actual measurement of conductivity? But I don't understand what dissolved solids have to do with the temperature of whatever they are dissolved in. Well, I know there is relation, but it won't help you determine the amount of dissolved stuff, only potential amount.

And I still don't get it how is that related to electrical conductivity. Without knowing what is dissolved and in what ratios with other dissolved stuff I don't see this happening. How is the temperature of the solvent going to tell you anything regarding conductivity?

I know this can be done because we use this very simple device daily. What I am trying to do is to take the exact same sensor used in this device and build it into a digital panel that will allow the combination of data from several other sensors to be read all together.

The company would not give me the formula they use and their datasheet was rather limited. i.e. 25 degree C requires no correction.

I found a formula, which I posted above that would convert. While this is similar to a thermistor sensor it does look a little different. When reading Total Dissolved Solids it is basically sending a pulse through the medium. The delay of these pulses will tell you the amount of solids. It is also a function of how conductive the medium is.

In this particular case I want to find out how much salt is in water. If I submerge the sensor in pure water I would receive a reading of 0 TDS. Saltwater has an average concentration of 35k TDS (Different areas of the world can have higher or lower)

So what the Arduino needs to do is to send a pulse and then read the pulse (I am assuming on the PWM TX RX pins)

It will then take this and process the delay according to a math formula (The one above)

Temperature does effect these readings. (I do believe it is a property of thermal dynamics)

So temperature and salinity need to have an arbitrary baseline set for the calculation. I know the temperature baseline is 25 degrees C, I am waiting on the company that manufactures the sensor to tell me what the baseline for the salinity is.

In the meantime though, I am trying to figure out the code behind the following:

Sending/receiving the pulse from the Arduino. Calculating the TDS/EC

I am open for suggestions and hints.

I do appreciate everyones time and abilities (Would happily by those that help a drink)

I have been googling and will continue to do so, but have been hitting a lot of walls, that is why I brought it to this community, which is know for being helpful.

If you need to know something else just ask.

Link the datasheet for the sensor.

The datasheet is very vague. I have copied and posted the entire thing below....No online link to it...

Internal Circuitry: None. The sensors may be implemented with any system. Implementation and interfacing is a function of the hardware and program of each individual product or system. Recommended Range: 0-10,000 ppm

Output: Unamplified (mV)

Pins: For each sensor, half of the pins are output and half are input. Stimulus: Any type of conductivity signal other than DC (including pulsed DC).

Thermister Response Time: The response time for the thermister varies depending upon the temperature and also where the sensor is located in the water. It could be anywhere from 5 seconds to 5 minutes. Please note that the thermister is in the upper part of the sensor, so distance to the water is a factor.

Temperature Compensation Curve: This is a function of the program that controls the sensor, not the sensor itself. At 25oC, there is no need for compensation.

Seriously, that's it? Does the thing have part name on it? Anything at all that can be used to identify it?

Well, doesn't matter. If I understand correctly how the thing works it sends a pulse and times the time it takes to receive it on the other end. Speed of light through the water is known and can be calculated, but is roughly 225 000 000 m/s. Unfortunately that is still very fast and means that in one microsecond it will travel 225 m. Even if Arduino could reliably measure time in nanosecond range it would still mean the signal would travel 22,5 cm between two readings, and that any change is the speed of EM signal due to dissolved salt would be negligible when measured at this level. So, if this sensor operates on this principle and unless you are willing to make a huge sensor I'm afraid that that Arduino is just too slow for this application.

More details on the device you use could mean all this falls in the water (pun not intended) and that we can salvage (there it is again) your project. Pictures of the insides at least. Or preferably the model and make of the device.

Because temperature has a large effect on conductivity of ionized salts in solution. As the temperature increases EC will go down or increase in conductivity. It's an inverse function the larger the number in mho's of conductivity the greater the conductiviy. The TDS is "Totally Dissolved Salts" or the conductive part of water. Pure de-ionized water is a non conductor of electricity, adding various salts causes it to conduct electricity Accurately measuring EC is the real task and a non trivial one. The device I reworked measured the dielectric constant of the media it was inserted into, soil or water. It was a non contact (electrically insulated) probe made from stainless steel with a coil inside the slotted end of the probe and the coil measured the dielectric constant of the media it was in contact with physically. This was necessary because of the differences in the nature of various soils and their composition.


Ok Bob,

Now we are moving forward. Sounds as if you know what I am dealing with.

Do you have any code snipets or formulas I can use.

My sensor is already made and proven to work in the environment I am planning on using it in.

What do you got?

Thanks by the way.

Do you know how you'll pick up the output tension of the thermistor ? You should have to determinate the coefficient between EC and the output tension. But "k" is still missing... I think only datasheet can give it. Sorry but I can't help you forward =(

I still don't understand the thermistor part. What you were describing seems to be a way to measure capacitance, charging the capacitor and reading the voltage until it goes beyond a certain value. Is that what you want to do? Your probe tip has two parallel rods or plates, right?

I suppose thermistor is there to provide correction for the temperature oscillation.