Introduction: Arduino Flowmeter With a State Machine

About: Interest in PUNK/HARDCORE/METAL/HIGHLAND BAGPIPES

My boss has been got a flowmeter for several years. This one was manufactured by a famous company : PARKER. But this analog flowcoder was broken: no signal from the measurement circuit inside. So I decided to repair it in a cheap way, a new one withe the same skills will cost about 400 EUROS.

So i used an atmega328p burnt with the arduino bootload.

Step 1: The Project Skills and Details

This flowmeter is included in a system of flow/pressure regulation. It gives a masurement of the flow (1.5l/mn to 100l/mn) converted in an electrical signal (4/20mA). The signal is directed to a flow/pressure regulator wich controls the speed increasing/decreasing of a water pump.

This project is used to measure waterflow as you can see on the use case and the requierments diagrams.

I would like to create a more simple solution but the initial broken circuit was covered of a sort of black epoxy resin in order to make components no recognisable, hidden and impossible to repair.

So I used a LC (100uH/0.5nF) circuit supplied with DC square HF signal (710kHz, f=1/(2.pi.square root (LC)). In front of the coil rotates the blades (3 blades each covered of a small piece of iron) : the speed of the turbine gives you the flow. The most important difficulty was to choose the right frequency: it must be the highest in order to have the right distance of detection beetween the coil and the blade.The distance of detection increases with the frequency.

Here, the distance is about 4 mm through the glass cylinder. When a piece of metal is in front of the coil, it creates Foucault currents in the ferrite which decrease the magnetic field. So L decrease and the sinus voltage on C decrease too. The measurement of this voltage fluctuation in a short time gives the flow. It's an intrusive method.

Other sensor solution would be used:

-a magnet and a hall effect sensor like this https://www.instructables.com/id/Flow-Meter/

a very good project but you need strong and very small magnets to cut them in the right forms and a special sensor.

-an inductive sensor but the distance of detection, the sensibility and the un-compact solution (these sensors are hudge in comparison with the distance between 2 blades) are not suitable with this kind of detection: it doesn't work.

The project is controlled by an atmega328p and programed with Arduino.


Step 2: The Schematics, the Components and the Cheapest Way to Succeed

Here are 3 diagrams to present the different components of the new flowmeter:

- the bdd is to see where is the flow meter in the system

- the ibd organizes the different signals and interraction between the components

- the electronic schematic, the more detailed.

The power supply: the system gives a 24VDC power supply to the flowmeter. The components need 0V/5V/12V generated by 2 voltage regulator 7805 and 7812 without dissipator. I used 13 diodes 1N4007 to lower the voltage input of the 78xx in oder to avoid the dissipator: the cases are not warming too much. It's a simple solution.

The microcontroller needs 5V and the PWM/4-20mA needs 12V for the LM358.

The microcontroller: an atmega328p bootloaded in Arduino generates 710kHz to the LC resonnant circuit. The AC sinus voltage on C10/C11 (+/- 15V) is send to the analog input A0 through an envellop detection circuit with a voltage divider/rectifier. Then the microcontroller measures the voltage fluctuation between 2 blades in a short time and generates a proportional PWM to this short time to the PWM/4-20mA converter.

You will need an USBasp converter+HE10 connector to program the atmega328p with Arduino software.

Step 3: The State Machine and the Program Skills

The method is based on simple a state machine to measure with accuracy the time beetween 2 blade transitions. The program will need 2 special library:

- my favourite library SM like STATE MACHINE

- the PWM library to generate a square HF PWM on pin9 only!

Why the state machine? To avoid analog or digital interrupts by using its reliable and very quick rising edge function.

Also, in the program I modified the time conversion of the ADC A0 in oder to have a fast measure. See the program with comments.

The dectection threshold depends on:

- the thickness of the glass pipe

- the physical size of the coil

- the size of the small pieces of metal of each blade

May be you don't have the same value on your flowmeter: use the external debugger to tune it.

Step 4: Measurements, Tests and Conclusion

The measurement is very accurate and gives the same result as the flowgauge indicator of the system. The value displayed on the regulator is correct too.

But in the pipes, there are a lot of turbulence flow which go on the turbine: so the are fluctuation in the measurment. To compensate this unwanted point you can activate a delay time filter on the regulator (1s delay seems to be good on this system, it 's up to you).

The coil must be carrefully put in front of the blades. If not, you'll got nothing measured.

Thanks to you, with your interesting tutorial!!