eTape liquid level sensor

Hello,

I am using eTape continous fluid level sensor PN 12110215TC-12 in order to determine the
level of the liquid we are using.

Here is the datasheet----->https://cdn-shop.adafruit.com/datasheets/eTape+Datasheet+12110215TC-12_040213.pdf

Now, I need to determine the depth of the liquid before i calibrate to calculate the volume.

I found this below code and i notice that this code can be used to determine the volume once the
calibration is done.
But my requirement is to determine the depth of the liquid first.
I am very new to arduino projects and I will be very thankful if someone help me with this.

Thanks

LIQUID_LEVEL.ino (217 Bytes)

I am really sorry. the above attached code is incorrect.

This is the correct code.

// Liquid Level Sensor Sketch

// Show the raw resistance values measured from an eTape liquid level sensor.
// See details on the sensor at:
//   https://www.adafruit.com/products/1786

// Created by Tony DiCola
// Released under an MIT license: http://opensource.org/licenses/MIT

// Configuration values:
#define SERIES_RESISTOR     750    // Value of the series resistor in ohms.    
#define SENSOR_PIN          0      // Analog pin which is connected to the sensor. 

// The following are calibration values you can fill in to compute the volume of measured liquid.
// To find these values first start with no liquid present and record the resistance as the
// ZERO_VOLUME_RESISTANCE value.  Next fill the container with a known volume of liquid and record
// the sensor resistance (in ohms) as the CALIBRATION_RESISTANCE value, and the volume (which you've
// measured ahead of time) as CALIBRATION_VOLUME.
#define ZERO_VOLUME_RESISTANCE    0.00    // Resistance value (in ohms) when no liquid is present.
#define CALIBRATION_RESISTANCE    0.00    // Resistance value (in ohms) when liquid is at max line.
#define CALIBRATION_VOLUME        0.00    // Volume (in any units) when liquid is at max line.

void setup(void) {
Serial.begin(9600);
}

void loop(void) {
// Measure sensor resistance.
float resistance = readResistance(SENSOR_PIN, SERIES_RESISTOR);
Serial.print("Resistance: "); 
Serial.print(resistance, 2);
Serial.println(" ohms");
// Map resistance to volume.
float volume = resistanceToVolume(resistance, ZERO_VOLUME_RESISTANCE, CALIBRATION_RESISTANCE, CALIBRATION_VOLUME);
Serial.print("Calculated volume: ");
Serial.println(volume, 5);
// Delay for a second.
delay(1000);
}

float readResistance(int pin, int seriesResistance) {
// Get ADC value.
float resistance = analogRead(pin);
// Convert ADC reading to resistance.
resistance = (1023.0 / resistance) - 1.0;
resistance = seriesResistance / resistance;
return resistance;
}

float resistanceToVolume(float resistance, float zeroResistance, float calResistance, float calVolume) {
if (resistance > zeroResistance || (zeroResistance - calResistance) == 0.0) {
  // Stop if the value is above the zero threshold, or no max resistance is set (would be divide by zero).
  return 0.0;
}
// Compute scale factor by mapping resistance to 0...1.0+ range relative to maxResistance value.
float scale = (zeroResistance - resistance) / (zeroResistance - calResistance);
// Scale maxVolume based on computed scale factor.
return calVolume * scale;
}

The data sheet has pretty good specs on resistance with immersion depth, and the code gives a calibration procedure for converting the level change to an actual volume given your vessel.

// The following are calibration values you can fill in to compute the volume of measured liquid.
// To find these values first start with no liquid present and record the resistance as the
// ZERO_VOLUME_RESISTANCE value.  Next fill the container with a known volume of liquid and record
// the sensor resistance (in ohms) as the CALIBRATION_RESISTANCE value, and the volume (which you've
// measured ahead of time) as CALIBRATION_VOLUME.

Can you explain more about the container you are trying measure, and what is your specific issue with calibration?

Hello again.

The container which i am using is not a constant cross section one.
since for now i am only concerned with finding the depth of the liquid, i don't think the shape of the container
matters here.

I just need the proper code in order to find the depth of the liquid according to the resistive output
of the sensor.

Thanks.

I just need the proper code in order to find the depth of the liquid according to the resistive output
of the sensor.

The data sheet give the information on resistance with depth, so your task is to determine an unknown variable resistance.

A simple way to do this is to use a “voltage divider.”

See Wikipedia – especially the section on “resistive divider”

The sensor is wired in series with a known resistance to form a voltage divider and a known voltage is applied across the divider. The Arduino’s analog-to-digital converter is connected to the center tap of the divider so that it can measure the tap voltage and, by using the measured voltage and the known resistance and voltage, compute the sensor resistance.

Do a Google search on “arduino determine unknown resistance with voltage divider” and you will get plenty of references.

You want to use a reference resistor in the middle of your measurement range so I would use 1.2K. Use a precision resistor (1% or better) and measure the reference resisitor with an ohmeter to detemine its exact value.

Hello,

First of all thank you so much for making me to understand the basic about this sensor.

yes, I noted the values of variable resistor (sensor) using multimeter with the help of known
reference resistor value( I used 750 ohms), supply voltage(5V) and the measured sensor voltage.

but, I need to read the depth of the liquid using the arduino code in the serial monitor.
how to convert this resistance value to find out the depth.

and also one more doubt!
The sensor have 4 pins. pins 2 and 3 are used to read the sensor output. pins 1 and 4 are given for
temperature compensation. so, what is the connection for pin 1 and 4. They have not mentioned anything about these 2 pins in the datasheet.

Thanks.

but, I need to read the depth of the liquid using the arduino code in the serial monitor.
how to convert this resistance value to find out the depth.

First, You need to work through the math to get an equation for depth from resistance. The general form for a line is y = mx +b. In your case, y is the ohms resistance, and x is the inches of fluid depth. Equation of a Straight Line

For the best accuracy, you should use specific measured resisitance values for your 1" and 12" depths, but here’s the calculation using the given nominal values of the two points (1,2250) and (12,400). The slope (m) is -1850/11 = -168 ohms/inch. (I realize that this is somewhat different than the nominal -150 ohms/inch given in the data sheet).

Now that you know the slope, you just need to determine the value of b (y intercept) to use in the equation. Hint: Just project the line back to x = 0 with the slope of -168 ohm/inch. You will also want the linear equation in the form which solves for depth x = (y - b)/m where y is your measured resistance.

Second, you need to write the code to read the voltage with analogRead(), convert it to resisitance with the voltage divider equation, and plug the values into the equation for depth.

Make an effort to write some code and post it. Please remember to use the code tags [code][/code] found at the </> in the tool bar to get your code in a window like this

your code here

and also one more doubt!
The sensor have 4 pins. pins 2 and 3 are used to read the sensor output. pins 1 and 4 are given for
temperature compensation. so, what is the connection for pin 1 and 4. They have not mentioned anything about these 2 pins in the datasheet.

I am also confused by this, and I would suggest you contact the manufacuturer’s technical support at techsupport@milonetech.com

I can only assume that the Rref which is nominally 2250 ohms changes with temperature in the same fashion as the variable resistor. If you go by the circuit diagrams posted in the data sheet, I would use the method shown as “Voltage Dividers and Microncontroller”.

You will determine how much Rref has changed from its nominal value at the measurement temperature, and adjust the variable depth resistance by the same percentage amount. For example if the reference resistor reads 5% higher than its nominal value, then adjust the depth measurement resistance value by the same 5%.
You will need to measure the reference resistor accurately at some known temperature to get a starting point.

Hello again,

I am trying to get the exact depth since 4 days. The values(sensor output) are not consistent
and almost zero repeatablity. So, I averaged the sensor output(voltage) and you can see it in the code.

After this, I converted the voltage output to resistance and resistance to depth using the same method you suggested( In the code you can see the slope and constant which I got from the graph).
still, I failed to get consistent values.

The method which I am following to get the depth is perfect. Only thing is I need to get the consistent value and very good repeatablity.

Is there any other way to get the consistent values.?? or any changes in the code??

const int numReadings = 10;
 
int readings[numReadings];      // the readings from the analog input
int readIndex = 0;              // the index of the current reading
int total = 0;                  // the running total
float average = 0; // the average
float depth;
float slope = 58.8492;
float b = 2761.917;
 
#define SENSORPIN A0 
 #define SERIESRESISTOR 753 
 
void setup(void) {
  // initialize serial communication with computer:
  Serial.begin(9600);
  // initialize all the readings to 0:
  for (int thisReading = 0; thisReading < numReadings; thisReading++) {
    readings[thisReading] = 0;
  }
}
 
void loop(void) {
   
  // subtract the last reading:
  total = total - readings[readIndex];
  // read from the sensor:
  readings[readIndex] = analogRead(SENSORPIN);
  // add the reading to the total:
  total = total + readings[readIndex];
  // advance to the next position in the array:
  readIndex = readIndex + 1;
 
  // if we're at the end of the array...
  if (readIndex >= numReadings) {
    // ...wrap around to the beginning:
    readIndex = 0;
  }
 
  // calculate the average:
  average = total / numReadings;
  
  // send it to the computer as ASCII digits
 Serial.print("voltage count is ");
 Serial.println(average);
  delay(200);
  
  // convert the value to resistance
  average = (1023 / average)  - 1;
  average = SERIESRESISTOR / average;
  
  Serial.print("Sensor resistance "); 
  Serial.println(average);
  delay(200);

  depth=(b-average)/slope;
 
  
  Serial.print( "depth is  ");
  Serial.println(depth);
  delay(200);
 

 
 
}

Thank you so much for your patience to help us.

The values(sensor output) are not consistent
and almost zero repeatablity. So, I averaged the sensor output(voltage) and you can see it in the code.

The averaging is a good idea.

To troubleshoot, I think it would be a good idea to separate the measurement from the analysis.

With constant level, can you provide the raw analog read values from the divider without any averaging? How much variation do you see?

If the readings are really jumping around you need to fix that. Pay particular attention to your connections and grounding. Can you attach a photo of the sensor setup in the fluid and the connections of the voltage divider and arduino?

If youre basic measurement is OK, and you are getting stable analogRead values from the sensor, then there may be issues with integer truncations messing up the float math. All constants used in calculations should end in a decimal point zero to force the math to use floats.

Make the value of SERIESRESISTOR 753.0, and where you divide 1023/average change to 1023.0/average

I have some other concerns, but they relate to the depth value you get, not the stability of the value.

Given what data the manufacturer provides, the slope value of 58.8 seems low. (I think you are using a positive value for slope because you multiply by -1 when formulating your final calculation.) The intercept value also seems high. Can you show the measurements you took to determine your values?

Hello,

I had to complete that task by November end. So, I somehow managed to get the approximate values.
for every 0.003 voltage variation, the corresponding resistance variation was upto 12 Ohms( minimal change). That variation may be due to sensor set up.

So instead of taking the resistance value to map with depth of water level, I directly considered the voltage counts( digital value of sensor) and plot the graph to find the constant and slope.
Even though the readings were not accurate, They were acceptable.

Thank you.