Arduino Ultrasonic Water Flow Instrument With ScioSense UFM01

by electromechpro in Circuits > Arduino

830 Views, 8 Favorites, 0 Comments

Arduino Ultrasonic Water Flow Instrument With ScioSense UFM01

R4 with UFM01.jpg

Arduino Ultrasonic Water Flow Instrument With ScioSense UFM01

Supplies

ufm01.jpg

Flow sensor UFM01 from ScioSense

Arduino compatible board with Serial1

The Problem:

ufm01.jpg
UFM-01 & YF-B3 flow sensors.jpg

Interfacing ScioSense UFM01 Ultrasonic Flow Sensor With Arduino

 

  I was tasked at my work with measuring an unknown amount of water flow from some drains to evaluate the effectiveness of different drainage experiments. As the collection points were “out in the Wild”, it was essential to keep the data logging equipment as robust and cost-effective as possible. 

  As our instrumentation sometimes included Arduino based sensors, it was decided to use an Arduino with a Real Time Clock, an RS-232 shield for transmitting the data to other data gathering equipment, and an SD card reader/writer for backup storage. A Hall effect turbine style water flow sensor was chosen for interfacing with the Arduino, as much information was available on the internet for reference. Our installations all had an inspection well about 18 inches square, with a 4 inch inlet and outlet pipe. Since the expected volume of water was unknown, the water was collected in a 5 gallon bucket, then pumped out with a 12 volt bilge pump with internal float switch to keep the parts count down. The flow sensor was inline with the pump discharge.

The water had an unexpected amount of small debris in it, and would quickly clog the turbines of the flow sensors. Inlet screens on the bucket and pump seemed to have no effect, as the sensors require frequent servicing. The site was 40 minutes away from the lab, so this was less than ideal.


At the time, there was no affordable option to the mechanical, Hall effect flow sensors. Later, while searching online, I found the UFM01 ultrasonic flow sensor from ScioSense.

https://www.sciosense.com/ufm-01-ultrasonic-flow-sensing-module/   Cost was around $45-50 USD at the time of writing. As a bonus, the sensor has its own microcontroller that communicates accumulated flow, flow rate, and (extra bonus) water temperature, along with a unique serial number, via serial UART. Data sheet link here: https://www.sciosense.com/wp-content/uploads/2023/12/UFM-01-Datasheet.pdf

The usual channels, Mouser and Digikey, were both backordered for months, but I placed an order for a couple of evaluation units anyway. It is important to note that there is both an evaluation kit and a “just the sensor” option. The evaluation kit is not necessary for connection to the Arduino, and will save you a few bucks if you don’t need it. 

The Solution:

UFM01-R4-OLED.jpg

The UFM01 connects to the Arduino R4 as shown. Pretty simple, really. +5, Ground, Transmit and Receive (remember, transmit of the sensor goes to receive of the Arduino, and vice versa.)

Project Notes

Screenshot 2024-06-25 .png
FY3TOK8LXUF29NI.jpg


When the sensors came in, there was a Python program for evaluating them, which worked fine, but I needed to port it to Arduino C++. Studying the data sheet for it, the easiest way seemed to be to use the UART output. There is also a one-wire output that seems to be similar to the way a DHT11/22 connects, but without an Arduino library for it, the timing parameters for communicating with it were too much for my limited programming skills. Perhaps someone with greater programming skills will tackle this some day. 

We worked inhouse to get some code translated from Python to Arduino, and had some success using an Arduino UNO R3 and the custom software serial library. The UFM01 communicates at 2400 baud, with 8 bits, Even parity, and 1 stop bit. Regular software serial could not handle the even parity.  Sending commands to the UFM01 proved to be a problem for the custom software serial port, as the sensor sends out a data burst about every second, and the software serial cannot handle simultaneous transmit and receive.

By this time, the Arduino R4s had arrived. One of the big changes to the R4 is that the transmit and receive pins, D0 and D1, are connected to Serial1, not Serial. This was ideal for connecting to the UFM01. (see illustration for simplified circuit. OLED is optional, but cool. Explanation for the bowl of water also follows)

After connecting the sensor, download the code attached below.

The program we worked on in house had some trouble parsing the hex output of the UFM01 sensor. The sensor’s output is a hex string of human readable decimal number pairs, least significant first. Thus, an output of “29 06” translates into 6.29 liters/hour of flow.

A request for tech support help from ScioSense was made, and after some trial and error (note the indicated temperature on the OLED), code was written that properly parses the output of the UFM01 to the Arduino, and displays it on the serial monitor. See Picture.

From the illustration, you can see the ID (serial number), Volume, Flow and Temp. From the data sheet, the number 80 before the C indicates a negative value. This is handled in the code.

Supporting Notes:

ufm01 test rig2.jpg

An important thing to consider when using ultrasonic flow sensors, and covered in the data sheet, it that the sensor only works when it is completely full of water. The final configuration we came up with has the sensor upstream of a sort of P-trap to keep it immersed. For testing, one can dunk the sensor in a container of water. The temperature will read 0.0 deg. C if it is not full of water.

Another thing we found is that the accumulated flow total does not always go to zero when power is cycled. An early version of our code had the sensor powered from a GPIO pin set High at setup, then cycled Low for a second at midnight. Sometimes the sensor would reset to 0, sometimes not. The code from ScioSense has a function that handles resetting the sensor count. This code was adapted to our use and the function was called when the RTC struck midnight.

I have received permission from ScioSense to share the advance version of the Arduino code here. Look for an official user guide some time in the near future. Other than math.h, no special libraries are needed. The board used to develop the code was an Adafruit Feather M0 datalogger board, with a SAMD21 MCU https://www.adafruit.com/product/2796?gad_source=1&gclid=EAIaIQobChMI84eEm8j3hgMVx6FaBR0c8AV1EAAYASAAEgKT__D_BwE .

 As stated above, I have gotten it to work on an UNO R4 WiFi. It also was tested on a Seeed Studios XAIO SAMD21 https://www.seeedstudio.com/Seeeduino-XIAO-Pre-Soldered-p-4747.html?srsltid=AfmBOoqF4MQcH3Jf-hBX_rQYiErMDDWHrMQmkmgHY4ll1irfUQyXT0xewng  

and an ESP32 based M5Stack Tough https://shop.m5stack.com/products/m5stack-tough-esp32-iot-development-board-kit?variant=40644956160172 . As you can see on the illustration, the sensor has logged over 25 thousand liters at the time the picture was taken.

I did not have a mate for the connector on the end of the UFM01, so I cut it off and stripped and tinned the leads. The test setup pictured shows the wires directly plugged in to the Arduino headers. I tested the sensor, and it works on 5v and 3v, so I did not need a level shifter to make it work with the ESP32 board. It only draws 2 mA, so it can be powered directly from a pin. Doing this, it may be possible to connect more than 1 UFM01 to an Arduino serial port and read whichever one is turned on. I have not tried this. The data string from the sensor includes its serial number, so one could differentiate readings.


Another thing to consider, here in the US, is that although the data sheet says it is a standard 1/2 inch pipe thread, it is a British standard pipe thread, or BSPT. The threads are the same pitch, but 5 degrees different. There are 2 ways you can get around this:

  1. Purchase a 1/2 inch PVC BSPT-F to NPT-M adapter, or BSPT to slip fitting.
  2. Use the brass Hall effect flow sensor pictured in step 1 and a heat gun as a BSPT die to modify a standard 1/2 inch female thread PVC coupler. If you soften the PVC fittings with the heat gun, you can carefully thread them onto the brass threads. Once it cools, the fitting will smoothly thread onto the plastic ScioSense sensor.