Hi,
I am an undergraduate working in a lab to build a liquid level sensor using the etape set up sold here:
I am not an EE major, so I am quite the beginner with this kind of thing. The housing cap of my model contains a precalibrated 0-5 V module, so I've wired the black pin directly to the ground of the arduino, the red pin to the 5 V arduino power supply, and the white to the first analog input.
(Black)-----(Arduino Gnd)
(Red)---- (Arduino 5 V power supply)
(White)----(A1)
When I execute the following code, the etape senses resistance changes above a certain value, which it tends to reach when about half full, but any more water released will not result in resistance changes beyond this point.
#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 12000 // Resistance value (in ohms) when no liquid is present.
#define CALIBRATION_RESISTANCE 7666.67 //nce value (in ohms) when liquid is at max line.
#define CALIBRATION_VOLUME 80 // 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);
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;
}
Essentially, the value for resistance seems to "max out" about halfway down its length. I believe this has to do with the fact that my code expects a resistance reading, but this model of etape measures voltage instead. Since my etape comes with a built in voltage divider in the housing cap, I think I have to accommodate for this problem in the code. Does anyone have an arduino code for this type of etape? Or could someone offer some suggestions about how to approach my problem? I appreciate the help, I am very inexperienced.