I'm trying to upgrade a multiple gas flow controller, which must be capable of controlling the mass flowrates of three gases independently through one outlet line to our system, and am in need of a bit of advice on programming it. I'm using an arduino and a few DACs to tell the proportioning solenoid valves how open they should be. The current setup schematic is below, though I have more pressure sensors and mass flow sensors at my disposal if necessary.

enter image description here

My colleagues' advice is to use PID loops for each of the gases. This would be easy, particularly as there's an arduino code already available - however I'm not convinced that's either necessary or the best option, because:

  1. There is hardly any inertia in the system, unlike the thermal inertia in an oven for example. If it were just one gas, with one inlet pressure and one outlet, just the P part of a PID would be enough I think.
  2. The flow rate of each gas is dependent on the pressure differential before and after the valve, which is then dependent on the mass flow of the other gases and the outlet pressure, hence a PID could reach the optimal flow for one gas but in doing so change the flow rates of the other gases - leaving oscillation in the system. (the pressure in the system at the outlet may be changing slightly also)

  3. I don't know if its possible, or if so then how, to write a PID loop for simultaneous multiple input/outputs.

Hence I would appreciate any ideas, or solutions that exist which I was unaware of, for how my program should go to control the proportioning solenoid valves?

P.S. I'm not asking anyone to actually write a code for me, but just a basic idea of how I should do it would be great please?

P.P.S. (There is a formula for gas flow rate here, so I suppose you could try to work out theoretically what the optimal signal to the valves would be based on some kind of simultaneous solution of this formula for the three gases, taking into account friction factors for all the little fittings and parts in the system and expansion factors for the particular gas mixtures concerned (I don't think any of the gas cylinders are absolutely pure mixtures) etc. but I would think it's possible not to go that complex here!)

  • $\begingroup$ What is the goal of monitoring the individual gas flows? Some more details on what you would like to physically accomplish would help us help you. $\endgroup$
    – J. Ari
    Sep 9, 2018 at 21:27
  • 1
    $\begingroup$ Do you need to have the gases directly feed the artificial lung? If you could fill a ballast tank before the lung, then you could do just P control on each gas flow independently. You just have to make sure the source pressure of each gas source is high enough to overcome the dP of the tubing and the increasing pressure in the tank. Is modifying the setup possible at all? $\endgroup$
    – J. Ari
    Sep 10, 2018 at 2:15
  • 1
    $\begingroup$ Every mass flow controller that I've seen has the valve after the flow meter. I suspect they do this to better ensure that the meter has a suitable delta-p across it for proper operation (avoids back-flow if other inputs change their downstream flow & increase pressure). $\endgroup$ Sep 10, 2018 at 18:29
  • 1
    $\begingroup$ It sounds like you have access to spare meters and sensors. So why not save a bunch of programming effort, and use parallel mass-flow controllers instead? $\endgroup$ Sep 10, 2018 at 18:32
  • 1
    $\begingroup$ You can dose into the tank the amount of mass needed to replicate normal air one component at a time. The mass and volume can be related via an equation of state that is suitable for the temperatures and pressures of your system. $\endgroup$
    – J. Ari
    Sep 13, 2018 at 2:29

1 Answer 1


My best stab at this would be to attach parallel inputs of:

Gas1(100psi) -> Flow Meter1 -> Valve1 -> Manifold Input1
Gas2(100psi) -> Flow Meter2 -> Valve2 -> Manifold Input2
Gas3(100psi) -> Flow Meter3 -> Valve3 -> Manifold Input3

  • I picked "100psi" to stress that the input pressure should be >> the output pressure. Could be 50psi, or whatever...
  • Valve[n] is controlled by your spiffy Arduino code taking Flow Meter[n] as its input.
  • All Valve[n] outputs go to a manifold that effectively connects together all inputs.
  • The Manifold output (not shown) connects to your artificial lung.

In addition:

Manifold Output -> Lung -> Px Sensor
' | Purge Valve


  • Open purge valve.
  • Control Proportional Valve[n] so each gas has its proportional mass flow input. (This is where the spiffy software comes in, more on that later).
  • Allow purge to stay open while all 3 gasses are flowing, until steady state has been achieved.
  • Close the purge valve.
  • Monitor the Px sensor while the pressure builds up. While in the background, maintain proper flow proportions.
  • Once the target Px is reached, close all Valve[n] valves simultaneously.

Control Algorithm

I would suspect that you could get away with a straight P controller. I assume that you are not too concerned with small errors (you didn't say). I do not think that you will need to work the pressure sensor data into any of your calculations. However, if delta-p starts getting too small, then maybe you would need to build in a higher order control system, or perhaps the Px data to scale the valve outputs as delta-p goes down. TBD.

You will spend 80% of your time prototyping 1 control system to work. Then another 80% of your time integrating the hardware.

Getting the proportional valve to work as you expect, well that's the golden goose. Stability will be dependent on a few things, but macroscopically I would be concerned about:

  • Valve Cv value (Ahh, Cv numbers. Mean different things to different people, and nothing to most.) Are the valves ported properly for the desire flow rates? Are the valve orifices a suitable size for the flow rates and control range?
  • Arduino limitations. We love Arduino's. They're fun. They also suck. Especially when you want to do something real, and real fast. I'd bet dollars-to-donuts that you could get this to work with some flavor of Arduino. I'd also bet that you will end up working around some wonky limitation that you could have avoided by spinning your own electronics, and programming in native c. But heck, it's fun. The parts, and more importantly your time, are really cheap - so why not.
  • Is it all really stable under all conditions? Everyone will scream "Model it!". Instead, just try it and find out. A few hundred times. It will be a good experience. Even if you do take the modeling route, you will still need to try it out a few hundred times, so leave the expensive modeling software to the interns, where it'll do less damage.

Purchase a $30 adjustable pressure relief valve, in case something goes awry. No need to blow the poor fella's lungs apart.

It sounds like a fun project.

Good luck!

  • $\begingroup$ Thanks for that - it hadn't occurred to me to 'spin my own electronics' as you say, I've learnt everything I know using Arduinos, but maybe its time to get down to the next level! Many thanks $\endgroup$ Sep 12, 2018 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.