Go Down

Topic: Using a constant fluid level etape resistor to determine volume of water consume (Read 57 times) previous topic - next topic


I am working on a project for school(first time using arduino) where we have to make measure how much water someone has drank out of a water bottle. Unfortunately the only related sensor I have access to (supplied by school) is a liquid level sensor strip (http://www.adafruit.com/product/464). I am using the following code to get volume readings but am having difficulty figuring out how code for a volume difference, which would give me the amount someone has consumed. I am wondering if someone has any ideas how to code for the amount of fluid consumed using this etape sensor.

Thank you, I really appreciate the time and expertise that people put into forums!

Code: [Select]

// Configuration values:
#define SERIES_RESISTOR     560    // 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    1677    // Resistance value (in ohms) when no liquid is present.
#define CALIBRATION_RESISTANCE    1230    // Resistance value (in ohms) when liquid is at max line.
#define CALIBRATION_VOLUME        500    // Volume (in any units) when liquid is at max line.
void setup(void) {
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.
  volume = 1+ volume;
  Serial.print("Calculated volume: ");
  Serial.println(volume, 5);
  // Delay for a second.

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;


Are you getting values from the sensor that seem reasonable? That is, do the values go up as the amount of water goes up? Do they go down as the amount of water goes down?

That sensor is meant to be used on a tank of constant cross-section. Is your bottle of constant cross-section?


If your container has a constant cross section the change in water height will be directly proportional to the volume change. If the measure does not go exactly to a perfectly flat bottom you will need to calibrate your system. Put in a known small amount of water and read the depth measurement. Then add a known larger amount and measure the new depth. The difference in the depths will represent the amount added.

If the container does not have a constant cross section you will need to make a calibration table that relates each different depth to the volume of water.


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131