Help needed for 5V analog water pressure transducer switch, ESPhome and HA

Hi, I am hoping someone would be able to assist me getting a water pressure transducer to operate a relay for water pump with given pressure readings. Im Struggling to grasp the concept of ADC, Lambda, ect.

Im using a Nodemcu V3 lolin,
DFRobot sen0257 water pressure transducer

  • Sensing range: 0 - 1.6 MPa
  • Input Voltage: 5VDC
  • Output Voltage: 0.5 - 4.5 VDC
    (Linearly corresponding to 0 - 1.6 MPa)
  • Accuary: 0.5% - 1% FS
    And a 2 channel 5V relay. (only using one channel for now)

So as it stands and fighting with this for a while, I have the pressure transducer signal pin connected via a 2k trim pot voltage divider dropping 4.5V to 3.3V for the A0 pin on the node dev board
The sensor is getting a signal on the ADC between 0-1V and the sensor state is showing between 0-4.5V it seems in the log.
This how ever is probably not accurate and have gotten to the point. where im actually now not to bothered with calibrating correctly or converting the Voltage into mBar and PSI readings.

I need to get this working one way or another quite urgently. I have tried a few options in the ESPhome using on_range_value and the switch.toggle ect, but just dont seem to be coming right with getting the switch to automate.

switch:
  - platform: gpio
    pin: D1
    name: "Water Pump"
    id: waterpump


sensor:
  - platform: adc
    pin: A0
    name: "Water Pressure"
    id: 'WaterPressure'
    unit_of_measurement: "V"
    filters:
      - multiply: 3.3
    on_value_range:
        - below: 1.0
          then:
            - switch.turn_on: waterpump
        - above: 2.0
          then:
            - switch.turn_off: waterpump
    update_interval: 5s

Schematic - https://i.ibb.co/FDwFWYt/transducer-Relay-bb.png

For now i would be grateful if i could just get the switch to operate by sensor voltage level and calibrate the automation to the voltage provided with a external pressure gauge. If anyone is able to point me in the right direction, or offer assistance it would be a huge help. Thank you

you already have a threas open about this. Please don’t double up.

I Didnt want to be hijacking gregs thread where this was starting to go a different way to his project,I Got a bit further but still having issue getting the switch to automate

switch:
  - platform: gpio
    pin: GPIO14
    name: "Water Pump"
    id: "waterpump"

sensor:
  - platform: adc
    pin: A0
    name: "Water Pressure"
    id: 'waterpressure'
    unit_of_measurement: "V"
    filters:
      - multiply: 3.3
    on_value:
      then:
        - lambda: |-
            if (x < 1.0f) {
              id(waterpump).turn_on();
              }
            else if (x > 2.0f) {
              id(waterpump).turn_off();
              }
    update_interval: 3s

OK fair enough, actually it has been moved on from what was in the other thread.

First things first. Are you getting sensible looking pressure values?

Your schematic is showing you are using D1 to switch the relay. Your esphome code refers to GPIO14 which is labelled D5.

Also, does the switch work from homeassistant?

Sorry yes, i did change pins around since doing the schematic, the code is working now, I had to invert the switch, it was kicking on, but actually keeping the relay off. this is working,

switch:
  - platform: gpio
    pin: GPIO12
    name: "Water Pump"
    id: "waterpump"
    inverted: yes

sensor:
  - platform: adc
    pin: A0
    name: "Water Pressure"
    id: 'waterpressure'
    unit_of_measurement: "V"
    filters:
      - multiply: 3.3
    on_value:
      then:
        - lambda: |-
            if (x < 2.0f) {
              id(waterpump).turn_on();
            }
            else if (x > 3.0f) {
              id(waterpump).turn_off();
            }
    update_interval: 3s

For now it does what i need, will look into calibrating it precisely and converting to bar or psi at a later stage. I just needed it to operate for now at set pressures.According to the pressure gauge it is a bit off, i get 0-0.94V on the adc at about 0-120psi. where ideally it probably should be 0-232psi in the 0-1v range. But as im only going to about 100psi max mostly 60-80 psi. its should still be ok for now. Thanks

1 Like

Well ir obviously depends where you hwve your trimpot set. I have no idea of the voltage divider ratio you have set so impossible to say.

Yes, I Did originally test with 4.5V and trimmed it down to 3.3V i will have to double check it again as it was with a CV Buck converter i was testing with

Thanks for your post, are you able to converting voltage to psi / bar value? I’m interested on this. Can you help me? Thank you