I have bought water level sensor QDY30A from Ali QDY30A - the modbus RS485 version. I am trying to read its values using Wemos ESP32 S2 mini with Esphome and Max485, but no luck. Looks like the modbus connection is completely dead. Sensor docs are not so good, only wiring on that Ali page (and those colors are not correct as I have green instead of black). Some datasheet I found here (PDF). Modbus data sequence written in logs seems to be ok.
What I have also tried with no result:
connect DE and RE pins on MAX485 and put them to GND (signalizing always āreadā)
switch RX and TX on ESP32
switch blue and yellow from sensor (A to B) as some docs shows them switched
flow_control_pin (Optional, Pin): The pin used to switch flow control. This is useful for RS485 transceivers that do not have automatic flow control switching, like the common MAX485.
I have tried to connect them together. I did not connect them to ESP board as I am not planning to write to sensor, I am only reading. So I connected them to GND as recommended here:
If youāre only ever going to be either transmitting or receiving then you could tie both DE and RE high (permanent transmit) or both low (permanent receive).
You were right with a flow control pin. I definitely need to write something to sensor - commands for reading. So I need a flow control pin for MAX485.
I have also switched the A and B (blue and yellow) wires from sensor to MAX485. Now it is working. Sensor is sending unit ācmā, but is measuring in āmmā. Measurements are very quick and very accurate (water level in the bucket 122mm, value returned: 122). Current draw by sensor is stable 5.7mA.
My final esphome yaml for those, who will look for working setup in a future:
substitutions:
devicename: water-tank
friendly_name: Water tank sensor
device_description: Water tank sensor (Carat 4m3)
esphome:
name: ${devicename}
friendly_name: ${friendly_name}
comment: ${device_description}
esp32:
board: lolin_s2_mini #Pinout: https://www.wemos.cc/en/latest/s2/s2_mini.html
variant: esp32s2
framework:
type: arduino
wifi:
networks:
- ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: ${friendly_name} Hotspot
password: !secret wifi_ap_password
ota:
password: !secret ota_password
# Enable logging
logger:
level: DEBUG
baud_rate: 0
captive_portal:
# restart
button:
- platform: restart
name: Restart
sensor:
# Reports how long the device has been powered (in minutes)
- platform: uptime
name: Uptime
filters:
- lambda: return x / 60.0;
unit_of_measurement: minutes
# water level sensor
# https://esphome.io/components/sensor/modbus_controller.html
- platform: modbus_controller
modbus_controller_id: qd
name: "Water level"
id: modbus_water_level
register_type: holding
address: 0x0004
unit_of_measurement: "mm"
value_type: S_WORD
# Reports the WiFi signal strength
- platform: wifi_signal
name: Wifi Signal
update_interval: 60s
text_sensor:
- platform: version
name: ESPHome Version
- platform: wifi_info
ip_address: # exposes the IP Address when connected
internal: true
id: wifi_ip_addr
name: "IP Address"
uart:
id: mod_bus
tx_pin: GPIO39
rx_pin: GPIO37
baud_rate: 9600
data_bits: 8
stop_bits: 1
parity: NONE
#debug:
modbus:
id: modbus1
uart_id: mod_bus
flow_control_pin: GPIO35
modbus_controller:
- id: qd
address: 0x01
modbus_id: modbus1
setup_priority: -10
update_interval: 5s
status_led:
pin:
number: GPIO15
Hello Martin, did you try to change the modbus address of this sensor via esphome ? I want to use two sensors hence the need to change the default modbus address but all my tries failed! Any clue? Thanks
For your information: my experiments show that the holding register at 0x0005 (zero point) actually is writable. The value will be added to the result in register 0x0004.
BTW: Other registers are also writable and stored, but donāt change anything (unit of measurement, scaling factor)
Hi murcielago,
with your crucial tip to swap TX and RX wires, it also worked for me. Many thanks for that!
I read in another post of yours that you still want to change the millimeters to liters. Did you succeed?
Regards, Frank
Hi, Iām trying to get this sensor working but no luck
I have the sensor documentation here and from what I can see Iām doing everything right but Iām not getting any readings.
Also interested in doing this, but I have the QDY30A from Aliexpress but have the 0-10V version which just has red (+), green (-) and a yellow wire. Iām unsure how to wire this up to the ESP32, any ideas? I realise I can only get 5V max on the pins, so what else can be used to get the right resolution here?
Connect tx to tx on your hw519 to the esp and rx to rx, Not crossed! Than it worked on my project
In your wiring you us 16 and 17 thats korrect!
Your code is 17 and 18!