LevelmetingWaterputV4
PublicLoading…
Levelmeting Waterput V4
Description
This project is V4 in the levelmeting waterput project. It uses the QDY30A level sensor with RS485 protocol because all the previous sensors broke.
This project uses the ModbusMaster library which can be installed from the Library Manager in the Arduino IDE.
Components
- Sensor is the QDY30A level sensor with RS485 protocol.
- MAX485 module so that the Arduino/ESP32 can communicate with the modbus protocol by using the RX and TX pins.
- AZDelivery ESP32 Dev Kit C V4 for wireless data transmission which I had lying around.
- 220-240V to 24V power adapter as the sensor works on 24V.
- 24V to 5V step-down converter to power the ESP32. The MAX485 module is powered by the 5V pin of the ESP32.
Diagram
Thanks lejmr for this diagram. I used it to test my sensor. It is wrong for the TX and RX pins, they should be swapped. (See below for more.) The rest is the same as in this diagram.
My adaptation: I used pin 2 on the ESP32 to connect the DE and RE pins from the MAX485 module.
See the final KiCad diagram under the waterputv4Schematics folder. Here is a screenshot in case you don't have KiCad.
Testing the sensor
This took a lot of trial and error but I got it working in the end. Some important remarks:
- R0 from the MAX485 module should be connected to RX on the ESP32 and DI to TX. This is wrong in the original diagram I used.
- The provided screw terminals on the MAX485 module are useful to connect the sensor to.
- You cannot use the Serial port for debugging as you need the TX and RX pins to communicate with the sensor. I used the Bluetooth Serial library instead. You need to download the Bluetooth Serial app on your phone to connect to the wireless Serial.
- When uploading the code, disconnect TX, RX, 5V and GND from the MAX485 and ESP32.
- The test code is in the folder
testcode.
Final integration
- I have been using ThingSpeak for all the previous versions and it works quite well to store the data.
- The Bluetooth Serial library took too much space, so I have switched to the TelnetStream library. You need to install PuTTY and enter the IP adress which can be obtained from the Serial monitor. After this, it connects to the modbus sensor and from that moment on, all logging will happen with the telnet stream on PuTTY.
- You need to add a
credentials.hfile in the same folder as the final code. You need to fill this template with your own credentials.
#define mySSID "xxxxx"
#define myPASSWORD "xxxxx"
#define myChannelNumber 111111
#define myWriteAPIKey "xxxxxx"
Telnet Commands
After connecting to your ESP32 using PuTTY (see IP address in Serial Monitor), you can use the following commands in the telnet console:
-
ping
The ESP32 will respond withpong, show the current sensor height, and display the time remaining until the next automatic data upload to ThingSpeak. -
send data
Immediately triggers a sensor reading and uploads the value to ThingSpeak, regardless of the regular upload interval.
Example session:
> ping
pong
Doing a height reading...
Data at adress 4: 158
Converted height: 15.8cm
15.80
Time to next data send: 122 seconds
> send data
Sending data now...
Data at adress 4: 158
Converted height: 15.8cm
Height: 15.8cm
Uploading data to ThingSpeak...
Successful upload to ThingSpeak.
Height: 15.80 uploaded to ThingSpeak server.
If you enter an unknown command, nothing will happen. Commands are case-sensitive.
Tip:
Make sure you have connected to the correct IP address and that your ESP32 is powered and connected to WiFi.
Wishlist
- Add
reconnect wificommand. - OTA updates
No comments yet. Be the first to ask about this board.