I am building a water flow measuring device. What I did was to digitalRead an input and store the result in a bool variable (bSignal), which has a friend called bOldSig (also a bool variable). The input is read repeatedly while inside a While command that loops for about a minute before the program goes off to do other stuff (after which it returns). The way it works is bOldSig is one cycle behind bSignal.
To explain the basics of how it works, say both bSignal and bOldSig are true. Then some water flows through the water pipe and the hall sensor changes state of the input, e.g. it goes low or false. When the input is read (using the digitalRead command) that state is stored in bSignal. Now bSignal is low and bOldSig is high. So you use an if command that looks for bSignal ==LOW && (that's the logic AND command) bOldSig = H... oops sorry, I should have used the double equals ... bOldSig == HIGH. This condition only happens once per cycle of ... in my case a propeller. When you get this condition you increment a counter. At the end of a predetermined amount of time, in my case I use a minute, but you could use longer if you wanted to, I calculate how much water has flowed through the pipe.
When I started prototyping I used a brass flow meter and attached it to a water pipe and a funnel and poured water through the funnel. That gave me a reasonable idea of what I could achieve with an Arduino, which is what I'm describing here. To help with writing the software, I bought a smaller plastic water flow measuring device which runs off the same 5v supply and has the same electrical connections, so maybe you can make or buy something much smaller that can fit on your desk while you're writing the software.
Oh, a word of caution: the ESP 8266 and ESP32 operate at 3 volts, while the flow meters run at 5 volts, so you need to have something like a reed relay to act as safety device for the chip. So the Reed Relay works with the flow meter and keeps the ESP 8266 or 32 safely isolated from 5 volt supply In my case I tapped off the 5 volt supply from the Printed Circuit Board and feed it to the coil of the reed relay, and then from the output of the coil to the centre wire on the flow meter. When the water flows, (or I blow through the plastic flow device) the hall effect sensor in the flow meter changes state and magnetises (or stops magnetising) the coil, the contacts within the reed relay close and open. My current thinking is it is better to use an input which has PULLUP or PULLDOWN capability if you're using a relay to avoid false signals. I fed an earth or "ground" to one side of the relay's electrical contacts, and fed the other side of the electrical contact to an input. The PULLUP or PULLDOWN minimises stray voltages that happen to be induced into the wiring.
I don't let the while command cycle as fast as it can, mainly because the while command can cycle far faster than the flow meter could ever work. I actually have some delay in it to stop that from happening (20 milliseconds). If you are using something like an ESP 8266 or ESP32 then it is important to include either delay() or yield() in the cycle as these units have WiFi access and so use that small amount of time for housework. I read somewhere not to use the delayMicroseconds command for this purpose as it doesn't actually allow the ESP 8266 or 32 to go off and do housework. The yield () is just another way of writing delay(0).
While this all sounds a lot, the While command and such like is done in about 40 lines of code, which is small compared to all the other stuff going on.
I have split this post from the unconnected topic that it was posted on
Do NOT hijack threads
As to the actual post, it is almost unreadable. Please edit it and at the very least split it into paragraphs with blank lines between them. At the moment it is all but unreadable
Do you actually have a question ?
Is there code? Is there a question?