{"id":1937,"date":"2020-05-14T08:25:23","date_gmt":"2020-05-14T15:25:23","guid":{"rendered":"https:\/\/partofthething.com\/thoughts\/?p=1937"},"modified":"2021-01-02T15:22:05","modified_gmt":"2021-01-02T23:22:05","slug":"reading-a-tuf-2000m-ultrasonic-flow-meter-with-an-arduino-or-esp8266","status":"publish","type":"post","link":"https:\/\/partofthething.com\/thoughts\/reading-a-tuf-2000m-ultrasonic-flow-meter-with-an-arduino-or-esp8266\/","title":{"rendered":"Reading a TUF-2000M Ultrasonic Flow Meter with an Arduino or ESP8266"},"content":{"rendered":"\n<p>I had <a href=\"https:\/\/partofthething.com\/thoughts\/dont-use-push-to-connect-sharkbite-style-fittings-on-high-temperature-hydronic-heating-systems\/\">a flood in the garage the other day<\/a> and realized how great of an investment my flood sensor had been, saving me literally weeks of time and thousands of dollars in repairs. As I considered buying more flood sensors to cover more parts of the house, the thought to put a flow meter on the main water inlet to the house popped into my mind. It&#8217;s not quite as clear of a signal as a flood sensor, but if I detect flow when everyone is asleep or when on vacation, I can be sure that something is going wrong and have Home Assistant give me an alert. <\/p>\n\n\n\n<p>I didn&#8217;t want to cut into my water main and put a in-line flow meter in, so when I saw a <a href=\"https:\/\/www.amazon.com\/gp\/product\/B07NPYFM3M\/\">reasonably priced clamp-on ultrasonic flow meter<\/a> called the TUF-2000M, I had to bite.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3379_01.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"682\" src=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3379_01-1024x682.jpg\" alt=\"\" class=\"wp-image-1973\" srcset=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3379_01-1024x682.jpg 1024w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3379_01-300x200.jpg 300w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3379_01-768x512.jpg 768w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3379_01-1536x1024.jpg 1536w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3379_01.jpg 2000w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption>The TUF-2000M Ultrasonic Clamp-on Flow meter<\/figcaption><\/figure>\n\n\n\n<!--more-->\n\n\n\n<p>I also purchased a water main valve actuator to turn off the water automatically but it was not strong enough to actuate my valve so I sadly had to return it.<\/p>\n\n\n\n<p>The kit comes with a lot of wire and a power cord. You have to strip them yourself and hook them up. BTW, the power transformer is totally crap and broke almost immediately in a kind of scary way.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-gallery aligncenter columns-2 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3386-200x300.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"200\" height=\"300\" src=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3386-200x300.jpg\" alt=\"\" data-id=\"1974\" class=\"wp-image-1974\" srcset=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3386-200x300.jpg 200w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3386-683x1024.jpg 683w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3386-768x1152.jpg 768w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3386-1024x1536.jpg 1024w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3386.jpg 1365w\" sizes=\"auto, (max-width: 200px) 100vw, 200px\" \/><\/a><figcaption class=\"blocks-gallery-item__caption\">The transducers and wire<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3393.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"200\" src=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3393-300x200.jpg\" alt=\"\" data-id=\"1975\" data-full-url=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3393.jpg\" data-link=\"https:\/\/partofthething.com\/thoughts\/reading-a-tuf-2000m-ultrasonic-flow-meter-with-an-arduino-or-esp8266\/img_3393\/\" class=\"wp-image-1975\" srcset=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3393-300x200.jpg 300w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3393-1024x682.jpg 1024w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3393-768x512.jpg 768w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3393-1536x1024.jpg 1536w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_3393.jpg 2000w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption class=\"blocks-gallery-item__caption\">The garbage 12V transformer (luckily I had another 12V one around)<\/figcaption><\/figure><\/li><\/ul><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Getting the RS-485 data into a computer<\/h3>\n\n\n\n<p>At first I tried decoding the RS-485 directly with my <a href=\"https:\/\/www.adafruit.com\/product\/2264\">FT232H chip <\/a>from Adafruit. I could not get it working. Eventually I bought <a href=\"https:\/\/www.amazon.com\/gp\/product\/B07B1WMZM8\">a RS-485 to TTL converter<\/a> to put between the FT232H and the sensor. This worked quickly much easier. For settings, I have my MODBUS interface mode (menu 63) set to RTU only, my serial interface (menu 62) set to 9600,None, 0, 1, and my data logger option turned off.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_20200513_071557.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_20200513_071557-1024x576.jpg\" alt=\"\" class=\"wp-image-1979\" srcset=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_20200513_071557-1024x576.jpg 1024w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_20200513_071557-300x169.jpg 300w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_20200513_071557-768x432.jpg 768w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_20200513_071557-1536x864.jpg 1536w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_20200513_071557.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption>The RS-485-TTL converter hooked to a FT232H, which is plugged into the USB port of a computer<\/figcaption><\/figure>\n\n\n\n<p>Having cracked the physical layer and brought RS-485 down to 3.3V, I was able to decode the data packets. This sensor uses the t<a href=\"https:\/\/en.wikipedia.org\/wiki\/Modbus\">raditional industrial protocol, MODBUS<\/a>. With Python, you can operate this with <a href=\"https:\/\/minimalmodbus.readthedocs.io\/en\/stable\/usage.html\">minimalmodbus<\/a>. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import minimalmodbus\ninstrument = minimalmodbus.Instrument('\/dev\/ttyUSB0', 1, debug = True)\ninstrument.serial.baudrate = 9600\ninstrument.read_float(0)<\/code><\/pre>\n\n\n\n<p>Registers appear (at first) to be 1-based in this system. For example, reading register 99-100 from the manual for a float for Reynolds number gives:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; inst.read_float(99)\n1020.0<\/pre>\n\n\n\n<p>Sounds about right. Upon trying to write things, I ran into trouble. Writing ints to register 60 is supposed to take you to a window. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; inst.write_register(60,4,0,6)\n...(no response on device)<\/pre>\n\n\n\n<p>But strangely, writing to register 59 causes the device menu to change as expected!<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; inst.write_register(59,4,0,6)\n... (device goes to time\/date\/flow menu!)<\/pre>\n\n\n\n<p>Clearly something is wrong though because if I try to go to M25 in this way, it goes to M20. Aha! After fiddling it turns out that you have to use hex values! So to get to window M25, you use<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; inst.write_register(59,0x25,0,6)<\/pre>\n\n\n\n<p>Register 158 is supposed to be the current window. The proper value may be obtained from register 157 in this case, again suggesting a 0-based numbering of the registers<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; inst.read_register(157)\n37  # note this is equal to 0x25 for M25<\/pre>\n\n\n\n<p>To make sure I can read floats right, I went to M06 which shows T1 and T2 temperatures, both around 46.8 \u00b0C (dummy values because the probes aren&#8217;t in). I should be able to read these from registers 33-34 and 35-36, according to the 1-based manual. We try reading from 1-based 33 and 35 first:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; inst.read_float(33)\n46.8441925048828\n&gt;&gt;&gt; inst.read_float(35)\n46.8896484375<\/pre>\n\n\n\n<p>[Scratches head]. It works! Is it possible that writing registers is 0-based and reading them is 1-based!?<\/p>\n\n\n\n<p>I&#8217;m just going to have to get some flow going and read the value because this seems like hit or miss.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Interacting with the TUF-2000M from a ESP8266<\/h3>\n\n\n\n<p>Given TTL serial output from the converter, you can read the 3.3V TTL values into a ESP8266 or Arduino or Raspberry Pi for transmitting to something that can graph and respond. On an Arduino-like device, the <a href=\"https:\/\/www.arduino.cc\/en\/Reference\/SoftwareSerial\">Software Serial<\/a> library is the key. It allows you to use any available pair of digital GPIO pins (hint: don&#8217;t use the ones used by the hardware serial interface) for reading serial data. On a Raspberry Pi, you can <a href=\"https:\/\/elinux.org\/RPi_Serial_Connection\">configure GPIO to do serial like this<\/a>.<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/tekk\/modbusmaster-esp8266\">This library<\/a> seemed like the best one for a ESP8266 at first so I tried it first. We will do a verification test before hooking up flow by ensuring we can read on of the 46 \u00b0C temperatures from register 33. If we can, then we sure as heck will be able to read a flow rate from register 1. <\/p>\n\n\n\n<p>From the debug mode above, the response to a get_float call was:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">01 03 04 42 3B 60 74 B7 A1<\/pre>\n\n\n\n<p>That&#8217;s address, register, num bytes (4), 4 bytes of data, and a checksum. <\/p>\n\n\n\n<p>To make sure I can interpret the data payload, I did some Python:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; vals = [0x42,0x3B,0x60,0x74]\n&gt;&gt;&gt; struct.unpack('&gt;f',bytes(vals))\n(46.84419250488281,)<\/pre>\n\n\n\n<p>Sweet. Note that the single precision float from the flow meter is <a href=\"https:\/\/en.wikipedia.org\/wiki\/Endianness\">Big Endian<\/a>. Ok off to the simpler microcontroller library!<\/p>\n\n\n\n<p>After fiddling around a bit with endianness, I was able to get this result reading register 33 from the ESP8266\/NodeMCU: <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Reading registers\nSuccess! Processing\u2026\n16959 45231 &lt;- done\nFlow is 47.92\nReading registers\nSuccess! Processing\u2026\n16959 45231 &lt;- done\nFlow is 47.92<\/pre>\n\n\n\n<p>Yesss! So we, my friends, are in business! Switching the register of interest back to 1 for the flow rate, here is the test program in its entirety:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* Nick Touran's MODBUS-reading ESP8266 code for the TUF-2000M Ultrasonic flow meter *\/\n#include &lt;SoftwareSerial.h&gt;\n#include &lt;ModbusMaster.h&gt;\n\n#define RX_PIN D2 \/\/ connect to converter's RX wire\n#define TX_PIN D3 \/\/ connect to converter's TX wire\n#define MODBUS_DEVICE_ID 1\n#define FLOW_REGISTER 1\n#define FLOW_DATA_SIZE 2\n\nSoftwareSerial swSerial(RX_PIN, TX_PIN);\nModbusMaster sensor;\n\nvoid setup()\n{\n  Serial.begin(9600);\n  Serial.println(\"Welcome\");\n  swSerial.begin(9600);\n  sensor.begin(MODBUS_DEVICE_ID, swSerial);\n}\n\nvoid loop() \n{\n  readFlow();\n  delay(3000);\n}\n\nvoid readFlow() {\n  uint8_t j, result;\n  uint16_t buf&#91;FLOW_DATA_SIZE];\n  uint16_t temp;\n  float flow;\n\n  Serial.println(\"Reading registers\");\n  result = sensor.readHoldingRegisters(FLOW_REGISTER, FLOW_DATA_SIZE);\n  \n  if (result == sensor.ku8MBSuccess)\n  {\n    Serial.println(\"Success! Processing...\");\n    for (j = 0; j &lt; FLOW_DATA_SIZE; j++)\n    {\n      buf&#91;j] = sensor.getResponseBuffer(j);\n      Serial.print(buf&#91;j]);\n      Serial.print(\" \");\n    }\n    Serial.println(\"&lt;- done\");\n    \/\/ swap bytes because the data comes in Big Endian!\n    temp = buf&#91;1];\n    buf&#91;1]=buf&#91;0];\n    buf&#91;0]=temp;\n    \/\/ hand-assemble a single-precision float from the bytestream\n    memcpy(&amp;flow, &amp;buf, sizeof(float));\n    Serial.print(\"Flow is \");\n    Serial.println(flow, 6);\n  }\n  else {\n    Serial.print(\"Failure. Code: \");\n    Serial.println(result);\n  }\n}<\/code><\/pre>\n\n\n\n<p>For the final version, I will add in WiFi, AndroidOTA (for over-the-air updates), and MQTT for sending the data back to my Home Assistant server for monitoring. OMG this is totally going to work! \ud83d\ude42 \ud83d\ude42 \ud83d\ude42<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configuring the TUF-2000M for my water pipe and mounting<\/h2>\n\n\n\n<p>Once I figured out the menus, I entered my pipe OD, as measured by a micrometer. It&#8217;s 35.5 mm. Then I guestimated the pipe thickness from standard pipes as 3.175 mm. Water was the default fluid. I set the pipe material to Copper. I set the transducer type to &#8220;19. Clamp-on TS-2&#8221; since I got the small clamps. Then I went over to M21 and read out 10.8219 mm for my transducer spacing. OK. Time to mount.<\/p>\n\n\n\n<p>Oh shoot you&#8217;re supposed to use some kind of coupling grease between ultrasonic transducers and the pipe. Hmm maybe I&#8217;ll just try this bearing grease I have sitting around. <\/p>\n\n\n\n<figure class=\"wp-block-gallery columns-3 is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130028-768x1024.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"1024\" src=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130028-768x1024.jpg\" alt=\"\" data-id=\"1966\" data-link=\"https:\/\/partofthething.com\/thoughts\/?attachment_id=1966\" class=\"wp-image-1966\" srcset=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130028-768x1024.jpg 768w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130028-225x300.jpg 225w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130028-1152x1536.jpg 1152w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130028.jpg 1536w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><figcaption class=\"blocks-gallery-item__caption\">The starting point<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130030-1-1024x768.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130030-1-1024x768.jpg\" alt=\"\" data-id=\"1963\" data-link=\"https:\/\/partofthething.com\/thoughts\/?attachment_id=1963\" class=\"wp-image-1963\" srcset=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130030-1-1024x768.jpg 1024w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130030-1-300x225.jpg 300w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130030-1-768x576.jpg 768w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130030-1-1536x1152.jpg 1536w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130030-1.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"blocks-gallery-item__caption\">Measuring out the distance<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130029-1-1024x768.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130029-1-1024x768.jpg\" alt=\"\" data-id=\"1967\" data-link=\"https:\/\/partofthething.com\/thoughts\/?attachment_id=1967\" class=\"wp-image-1967\" srcset=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130029-1-1024x768.jpg 1024w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130029-1-300x225.jpg 300w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130029-1-768x576.jpg 768w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130029-1-1536x1152.jpg 1536w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130029-1.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"blocks-gallery-item__caption\">First mount, with grease<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><a href=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130031-1.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130031-1-1024x768.jpg\" alt=\"\" data-id=\"1968\" data-full-url=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130031-1.jpg\" data-link=\"https:\/\/partofthething.com\/thoughts\/?attachment_id=1968\" class=\"wp-image-1968\" srcset=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130031-1-1024x768.jpg 1024w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130031-1-300x225.jpg 300w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130031-1-768x576.jpg 768w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130031-1-1536x1152.jpg 1536w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/P5130031-1.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"blocks-gallery-item__caption\">Both mounted<\/figcaption><\/figure><\/li><\/ul><figcaption class=\"blocks-gallery-caption\">Mounting the ultrasonic transducers on my water pipe<\/figcaption><\/figure>\n\n\n\n<p>Checking the signal strength on the sensor, I was able to get 85% signal with Q also around 85%, which seems pretty good to me. So the bearing grease is working? Nice. I also rotated them to be 45\u00b0 rather than straight up and down as indicated in the manual.<\/p>\n\n\n\n<p>Here are the numbers in Home Assistant! It definitely works. I messed around with the zero-cutoff value to try to reduce the low-flow noise. This thing is not going to meaningfully detect a trickle out of a faucet. But it certainly can tell you when the faucet is running full blast. I am not sure what&#8217;s up with the oscillatory behavior after the shower at 7:30am. I&#8217;m pretty sure flow isn&#8217;t going backwards to the city. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"254\" src=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/Screenshot-from-2020-05-14-18-44-26-1024x254.png\" alt=\"\" class=\"wp-image-1986\" srcset=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/Screenshot-from-2020-05-14-18-44-26-1024x254.png 1024w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/Screenshot-from-2020-05-14-18-44-26-300x74.png 300w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/Screenshot-from-2020-05-14-18-44-26-768x190.png 768w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/Screenshot-from-2020-05-14-18-44-26-1536x381.png 1536w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/Screenshot-from-2020-05-14-18-44-26.png 1674w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Water flow meter readings overnight, with a shower at the end. Hmm the negative flow is a bit wonky. Oh and the units are wrong. That should say m\u00b3\/hr, not gal\/hr.<\/figcaption><\/figure>\n\n\n\n<p>BTW don&#8217;t use <code>abs<\/code> on a float in Arduino. See <a href=\"https:\/\/github.com\/arduino\/reference-en\/issues\/362\">this issue. <\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"586\" height=\"215\" src=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/image-16.png\" alt=\"\" class=\"wp-image-1969\" srcset=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/image-16.png 586w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/image-16-300x110.png 300w\" sizes=\"auto, (max-width: 586px) 100vw, 586px\" \/><figcaption>This is how long it took me to realize <code>abs<\/code> doesn&#8217;t work on floats in Arduino, leading to a ESP8266 crash. Use <code>fabs<\/code>.<\/figcaption><\/figure>\n\n\n\n<p>For more reference, here&#8217;s another picture of the connections ( in lieu of a proper wiring diagram). <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_20200513_071547.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_20200513_071547-1024x576.jpg\" alt=\"\" class=\"wp-image-1990\" srcset=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_20200513_071547-1024x576.jpg 1024w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_20200513_071547-300x169.jpg 300w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_20200513_071547-768x432.jpg 768w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_20200513_071547-1536x864.jpg 1536w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_20200513_071547.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>And one more<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"902\" height=\"1024\" src=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_4994-902x1024.jpg\" alt=\"\" class=\"wp-image-2070\" srcset=\"https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_4994-902x1024.jpg 902w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_4994-264x300.jpg 264w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_4994-768x872.jpg 768w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_4994-1353x1536.jpg 1353w, https:\/\/partofthething.com\/thoughts\/wp-content\/uploads\/IMG_4994.jpg 1804w\" sizes=\"auto, (max-width: 902px) 100vw, 902px\" \/><figcaption>System mounted in prototype configuration<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>I had a flood in the garage the other day and realized how great of an investment my flood sensor had been, saving me literally weeks of time and thousands of dollars in repairs. As I considered buying more flood sensors to cover more parts of the house, the thought to put a flow meter &hellip; <a href=\"https:\/\/partofthething.com\/thoughts\/reading-a-tuf-2000m-ultrasonic-flow-meter-with-an-arduino-or-esp8266\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Reading a TUF-2000M Ultrasonic Flow Meter with an Arduino or ESP8266<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[75],"tags":[],"class_list":["post-1937","post","type-post","status-publish","format-standard","hentry","category-home-automation"],"_links":{"self":[{"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/posts\/1937","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/comments?post=1937"}],"version-history":[{"count":22,"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/posts\/1937\/revisions"}],"predecessor-version":[{"id":2071,"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/posts\/1937\/revisions\/2071"}],"wp:attachment":[{"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/media?parent=1937"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/categories?post=1937"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/partofthething.com\/thoughts\/wp-json\/wp\/v2\/tags?post=1937"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}