ArduinoGeneral

Help with Gravity Water Pressure Sensor SKU SEN0257 and ESP32 using ESPHOME

userHead Account cancelled 2021-03-07 18:41:51 1756 Views3 Replies
Currently I have a problem calculating the pressure using the sensor. I currently have it attached to a pump with a pressure gauge to compare the results with the SEN0257. However, the formula that was given in the tutorial will always end up being a negative value.

https://wiki.dfrobot.com/Gravity__Water ... 7#target_5

Here is what I have done. I check the lowest voltage of the sensor without a pump attached to get the offset value. Which was 0.41195~ . Then using the rest of the formula with the average voltage 0.464 pre-pump.

0.464 *5.00 = 2.32
2.32 / 1024 = ‭0.002265625‬
‭0.002265625‬ - 0.41195 (offset) = ‭-0.409684375‬
‭-0.409684375‬ * 400 = ‭-163.87375‬

The final results is ‭-163.87375‬ kPa without any pressure. Even when the voltage is at max 4.5, when you plug in the formula the result is ‭-155.9909375‬. In the end it will always get a negative result. Even worse, ESPHome adc only reads up to 3.9V with its https://esphome.io/components/sensor/ad ... ttenuation . So, I can't even go up to the max voltage value unless I multiply by 4.09 from a 0db attenuation.

Am I calculating it wrong? I'm not sure what I am doing wrong exactly.
2025-07-29 22:53:43

If this helps, here an example wrt how I setup the SEN0257 to use with ESPHOME.

# === Pressure Sensor ===

# === ADC Sensor: Reads the raw voltage from the pressure transducer ===

# === RAW ADC SENSORS (voltage representation) ===

  - platform: adc

    pin: GPIO00

    name: "Sensor Volts (Raw)"

    id: pressure_volts_1

    icon: "mdi:lightning-bolt"

    accuracy_decimals: 3

    attenuation: 11db

    update_interval: 1s

    filters:

      - sliding_window_moving_average:

          window_size: 30

          send_every: 10

      - delta: 0.01

      - filter_out: nan

    web_server:

      sorting_group_id: config_settings

  - platform: template

    name: "Pressure (kPa)"

    id: pressure_kpa_1

    unit_of_measurement: "kPa"

    icon: "mdi:gauge"

    accuracy_decimals: 1

    update_interval: 1s

    lambda: |-

      // 1.6 MPa (1600 kPa) sensor powered at 3.3V with 0.33-2.97V output:

      // Pressure (kPa) ≈ (Voltage - 0.33) * 606.0606

      float kpa = (id(pressure_volts_1).state - id(offset_volts)) * 606.0606;

      if (kpa < 0.0) return 0.0;

      return kpa;

    filters:

      - exponential_moving_average:

          alpha: 0.1

    web_server:

      sorting_group_id: pressure_values

  - platform: template

    name: "Pressure (psi)"

    id: pressure_psi

    device_class: pressure

    update_interval: 1s

    unit_of_measurement: 'psi'

    icon: "mdi:gauge"

    accuracy_decimals: 0

    lambda: |-

      // 1 kPa = 0.145038 PSI

      // Output voltage range at 3.3V: 0.33V to 2.97V

      // Pressure range: 0 to 232 PSI

      // Pressure (psi) ≈ ((Voltage - 0.33) / (2.97 - 0.33)) * 232 OR Pressure (psi) ≈ (Voltage-0.33) * 93.2203

      float kpa = id(pressure_kpa_1).state;

      float psi = kpa * 0.145038;

      if (psi < 0.0) return 0.0;

      return psi;

    filters:

      - exponential_moving_average:

          alpha: 0.1

    web_server:

      sorting_group_id: pressure_values

userHeadPic JohnCamm
2021-05-28 02:54:52 Cool one. userHeadPic xayig96692
2021-04-07 00:15:52 Thanks for the update. userHeadPic pifibi5999