Submersible Water Pressure Sensor

Having a bit of a senior moment.
Using the stainless steel pressure sensor and the gravity analog current to voltage converter with the following software that is on the site.
What I would like is, instead of reading up to 5000mm (5m) I would like it go to 10m(10000mm) but to show metres with 2 decimal points instead of mm with 2 decimal points.
This is because I have both a 5m and 10m sensor to try
Thank you for any assistance
Software seems to work:-

/***********************************************************
  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");
  }
}


![111|500x291](upload://kZC1blEicQuZeURDiP8N05QxiEi.png)

Divide the mm value by 1000.0 and print it in the same way.

    Serial.print(depth/1000.0);

Thankyou :+1:

@Graham_B
curious, can you tell which sensor you use?

its this one:
[Gravity: Industrial Stainless Steel Submersible Pressure Level Sensor (0-5m) | The Pi Hut]

Not going to happen with a 0-5m sensor.
Leo..

Edit: saw you also had a 10m sensor.

Why not display the 0 ~ 10 meter depth in cm (meter / 100), = mm times 10?

//Serial print results
    Serial.print("depth:");
    Serial.print(depth * 10);
    Serial.println("cm");


Hi all again.
Regarding the Water Pressure sensor, seems to do what I want it to do, now cobbled a 4 x 20 LCD to show depth instead of using serial monitor.
What I want to do is to use a 1 x 5 keypad to input the sensor range instead of keep changing it in the program its self, and re upload.
The original program above Range is 5000 (5m) but i would like to change this to 10m or 15m etc.
For example on the display something like "Input Range" having 000.00m displayed and using the keypad to scroll up down ie 0-9, move left up down 0-9 etc so for example 22m required, display shows 022.00m, then enter.
Hope this makes some sort of sense, any ideas as i am a bit stuck.
thanks

Some information about your keypad is needed, post it's datasheet, brand name and exact part number and / or the seller's web page.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.