# Non Linear Sensor, how do I make a conversion?

## Recommended Posts

I am using a VH400 sensor from Vegetronix connected to a LabJack, they have a great sensor for measuring volumetric water content in soil, however, output is non linear.

My question is, what is the best/simplest way to use the 4 segment table below to graph and log?

Most curves can be approximated with linear segments of the form:

y= mx-b,

where m is the slope of the line

The VH400's Voltage to VWC curve can be approximated with 4 segents of the form:

VWC= mV-b

m= (VWC2 - VWC1)/(V2-V1)

After m is determined, the y-axis intercept coefficient b can be found by inserting one of the end points into the equation:

b= mv-VWC

Voltage Range Equation

0 to 1.1V VWC= 10V-1

1.1V to 1.3V VWC= 25V- 17.5

1.3V to 1.82V VWC= 48.08V- 47.5

1.82V to 2.2V VWC= 26.32V- 7.89

##### Share on other sites

So these are the equations:

0 to 1.1V VWC= 10V-1

1.1V to 1.3V VWC= 25V- 17.5

1.3V to 1.82V VWC= 48.08V- 47.5

1.82V to 2.2V VWC= 26.32V- 7.89

If the voltage reading is between 0 and 1.1, use 10 * Voltage - 1? etc.?

If so, you can use a Conversion in several ways. One, you could create a sequence function, but this would only work if the data acquisition rate was slow, say 1 second or longer. If you are doing faster stuff, or just want to be super efficient, you'll want to represent the above in a single expression. To do that you'll probably need to use the inline if:

iif(Value <= 1.1, 10 * Value - 1, iif(Value <= 1.3, 25 * Value - 17.5, iif(Value <= 1.82, 48.08 * Value - 47.5, 26.32 * Value - 7.89)))

##### Share on other sites

Thanks for the formula, I think the conversion would work the best. I believe the sensor is now working. The non linear application of this sensor measures volumetric water content (or linear measurement with water level 10cm deep on a 0-3 volt scale, but not at the same time). I believe volumetric water content is that is on a scale of 0 to 1.

I *believe* the formula result can be multiplied by 100 to get a percentage reading in a graph... pretty nice for a near real time soil water content measurement.

In my opinion, really neat and inexpensive soil or 10cm water level sensor.

Again, Thanks.

-Greg

##### Share on other sites

The conversion is not working correctly, I had a mistake in the display formula that masked the results...

I can make the conversion work with one "if" function for the first conversion range, however, it appears that I cannot use more than one "iif" or "if" in one conversion line... Seems like it should work but it doesn't.

Should I be able to run more than one "if" function in one line?

I may need to write a sequence if I cannot use more than one "if" function the conversion.

-Greg

##### Share on other sites

There's no reason you can't have multiple iif()'s. They are just functions. My guess is you have a typo. Can you post the exact script you used that didn't work?

##### Share on other sites

Here is what I have:

iif(Value<=1.1, 10*Value-1, iif(Value<=1.3, 25*Value-17.5, iif(Value<=1.82, 48.08*Value-47.5, 26.32*Value-7.89)))

I tried posting this over the weekend on the forum, but it did not appear to take..

I hope it is as simple as a typo, I looked and looked.

I can get the first part working fine: iif Value<=1.1, 10*Value-1

Just seems like the () are not working correctly. Should there be a space between the iif and ()?

Thanks,

Greg

##### Share on other sites

The forum is fully moderated, so posts don't appear until we enable them. If we didn't moderate, this forum would be littered with spam.

It appears maybe Conversions don't like Value in that many places. I checked the formula by replacing all the "Value" with "x" and then trying it on a variable and it works fine. I think what you'll need to do is use a second channel and put the result of the calc in the first channel's event. Something like:

y.addValue(iif(x<=1.1, 10*x-1, iif(x<=1.3, 25*x-17.5, iif(x<=1.82, 48.08*x-47.5, 26.32*x-7.89))))

where x is the actual reading channel and y is the new Test channel (with timing =0)

##### Share on other sites

What is the syntax for defining the variable "x" in a conversion formula for the channel Value?

e.g. if the channel name SoilMoisture is the A to D I/O type on channel #0, What should the conversion formula for this channel should be:

Value=x

or

Value=Var.x

or

Var.x=Value

I can't get any of them to work right.

##### Share on other sites

In a conversion? You don't. I was saying put the code in the channel event, and was using x and y as placeholders for you to substitute your own channel names:

1) rename your current channel from SoilMoisture to SoilMoistureRaw. Remove the conversion

2) create a new channel called SoilMoisture, device type "Test", "A/D", Timing = 0.

3) in the Event for soilMoistureRaw (click on the channel in the workspace, then the event tab), put:

SoilMoisture.addValue(iif(SoilMoistureRaw<=1.1, 10*SoilMoistureRaw-1, iif(SoilMoistureRaw<=1.3, 25*SoilMoistureRaw-17.5, iif(SoilMoistureRaw<=1.82, 48.08*SoilMoistureRaw-47.5, 26.32*SoilMoistureRaw-7.89))))

#### Archived

This topic is now archived and is closed to further replies.