Throw-in Liquid Level - Returns several levels

Please,

I have set up the liquid level sensor with an Arduino, a current to voltage converter and a 24V DC power supply.

But this scheme returns several different levels:

depth:197.92mm
depth:338.54mm
depth:1075.52mm
depth:338.54mm
depth:796.88mm
depth:184.90mm
depth:171.88mm
depth:171.88mm
depth:364.58mm
depth:1036.46mm
depth:286.46mm....

like this topyc: https://forum.arduino.cc/t/gravity-throw-in-type-liquid-level-transmitter-pressure-sensor/616098

tks for any help

Did you follow the suggestions given by helpers in the other thread? If so, please post your revised code, and schematic.

CODE:

#define ANALOG_PIN A1
#define RANGE 5000 // Depth measuring range 5000mm (for water)
#define CURRENT_INIT 4.00 // Current @ 0mm (uint: mA)
#define DENSITY_WATER 1 // Pure water density normalized to 1
#define DENSITY_GASOLINE 0.74 // Gasoline density
#define PRINT_INTERVAL 1000

int16_t dataVoltage;
float dataCurrent, depth; //unit:mA
unsigned long timepoint_measure;

void setup()
{
Serial.begin(9600);
pinMode(ANALOG_PIN, INPUT);
timepoint_measure = millis();
}

void loop()
{
if (millis() - timepoint_measure > PRINT_INTERVAL) {
timepoint_measure = millis();

dataVoltage = analogRead(ANALOG_PIN);
dataCurrent = dataVoltage / 120.0; //Sense Resistor:120ohm
depth = (dataCurrent - CURRENT_INIT) * (RANGE/ DENSITY_WATER / 16.0); //Calculate depth from current readings

if (depth < 0) depth = 0.0;

//Serial print results
Serial.print(“depth:”);
Serial.print(depth);
Serial.println(“mm”);
}
}

Thanks. Did you make any revisions to produce the above code? Or is it verbatim from the other thread? Where did it come from?

...and, the wiring diagram? In the other thread, there were also suggestions to improve or fix the hardware design... did you follow them, or investigate at all?

Considering the code, it would be best to set aside the sketch for now, and use a simple test sketch that only reports raw ADC values. Then you can be sure whether it's a hardware or software problem.

hi,
I reviewed the code, without doing any calculations, reading only the returned value and it fluctuates. returns several different values.

The problem is hardware!

any tips?

Tks

Post a picture of the setup.
The other poster seems to have connected the sensor to A0 instead of A1 in the code.
A mistake easily made.

Yep, DFRobot made a real mess of this.
Only 393 A/D values spread over 5000mm, and the wrong analogReference.
They should have used an ADS1115 between sensor and Arduino.
This would have been a better option, and it doesn't need a 24volt supply.
Leo..

Hi,
Can you please post specs/data link to your sensor please?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Was on the page OP linked to.
This one, and it comes with a voltage follower, with 2.4volt output at 20mA.
Which is a poor match for a 5volt Arduino, and double bad if default Aref is used.
Leo..

Hi,
So its a pressure sensor.
@ejhammer7777 have you measured the current in the 4-20mA loop?
Is the air pipe open to the atmosphere?
What reading do you get with the sensor out of the water?
What reading do you get when at a measured depth?

Tom... :smiley: :+1: :coffee: :australia:

@ TomGeorge
I think you're in industrial electronics. Don't you think it's strange that the current to voltage converter is used in the + line. Is that ever done?
I think it's not a problem if one of the supplies is floating, but if the Arduino and sensor supply have a shared ground then sensor voltage is outside common mode voltage of the opamp on that board.
Leo..

Hi,

The analog raw data is not scaled in volts, it is 0 to 1023, to represent 0 to 5V at the analog input pin.
To convert to volts;

float datavolts = analogRead(ANALOG_PIN)  x 5 / 1023;

Why aren't you using the sample code here;


/***********************************************************
      DFRobot Gravity: Analog Current to Voltage Converter(For 4~20mA Application)
      SKU:SEN0262

      GNU Lesser General Public License.
      See <http://www.gnu.org/licenses/> for details.
      All above must be included in any redistribution
     ****************************************************/

    #define ANALOG_PIN A2
    #define RANGE 5000 // Depth measuring range 5000mm (for water)
    #define VREF 5000 // ADC's reference voltage on your Arduino,typical value:5000mV
    #define CURRENT_INIT 4.00 // Current @ 0mm (uint: mA)
    #define DENSITY_WATER 1  // Pure water density normalized to 1
    #define DENSITY_GASOLINE 0.74  // Gasoline density
    #define PRINT_INTERVAL 1000

    int16_t dataVoltage;
    float dataCurrent, depth; //unit:mA
    unsigned long timepoint_measure;

    void setup()
    {
      Serial.begin(9600);
      pinMode(ANALOG_PIN, INPUT);
      timepoint_measure = millis();
    }

    void loop()
    {
      if (millis() - timepoint_measure > PRINT_INTERVAL) {
        timepoint_measure = millis();

        dataVoltage = analogRead(ANALOG_PIN)/ 1024.0 * VREF;
        dataCurrent = dataVoltage / 120.0; //Sense Resistor:120ohm
        depth = (dataCurrent - CURRENT_INIT) * (RANGE/ DENSITY_WATER / 16.0); //Calculate depth from current readings

        if (depth < 0) 
        {
          depth = 0.0;
        }

        //Serial print results
        Serial.print("depth:");
        Serial.print(depth);
        Serial.println("mm");
      }
    }

Tom... :smiley: :+1: :coffee: :australia:

Don't you mean

float datavolts = analogRead(ANALOG_PIN) * 5 / 1023.0;

?
(leaving the 1023 vs 1024 debate for another day...)

I'm just quoting the sketch provided.
Yes, lets leave the 1023/1024 debate for another forum section.

Tom... :smiley: :+1: :coffee: :australia:

Actually, I think its software. Try this (note the higher print speed) ...

#define ANALOG_PIN A1
#define RANGE 5000 // Depth measuring range 5000mm (for water)
#define CURRENT_INIT 4.00 // Current @ 0mm (uint: mA)
#define DENSITY_WATER 1 // Pure water density normalized to 1
#define DENSITY_GASOLINE 0.74 // Gasoline density
#define PRINT_INTERVAL 10

unsigned int analogData;
float voltage, current, depth; //unit:mA
unsigned long timepoint_measure;

void setup()
{
  Serial.begin(115200);
  delay(2000);
  pinMode(ANALOG_PIN, INPUT);
  timepoint_measure = millis();
}

void loop()
{
  if (millis() - timepoint_measure > PRINT_INTERVAL) {
    timepoint_measure = millis();

    //analogData = analogRead(ANALOG_PIN);

    // the next 2 lines are for testing only
    // comment out and enable line 25 for normal use
    analogData += 1;
    if (analogData > 1023) analogData = 0;

    voltage = analogData * 0.0048875; // 4.8875 mV per adc count
    current = voltage / 0.12; //Sense Resistor:120ohm (0.12KΩ)

    depth = (current - CURRENT_INIT) * (RANGE / DENSITY_WATER / 16.0); //Calculate depth from current readings
    if (depth < 0) depth = 0.0;

    //Serial print results
    Serial.print("analogData: ");
    Serial.print(analogData);
    Serial.print("  voltage: ");
    Serial.print(voltage);
    Serial.print("  current: ");
    Serial.print(current);
    Serial.print("  depth: ");
    Serial.print(depth);
    Serial.println(" mm");
  }
}