Monday 8 May 2017

Making a Venturi Tube

In order to perform a little more testing on the Spirometer device I have designed a venturi tube which can be 3D printed.  It is possibly the most ugly and square shaped device ever to be designed but it will 3D print perfectly and because I designed it - I know the internal dimensions.  It was designed in the free version of google sketchup and assuming it works well I will share the design files.

The previous post for those that are interested is below:

http://langster1980.blogspot.co.uk/2017/04/create-spirometer-using-msp7002dp.html

Knowing the internal dimensions means the calculations performed will be more correct which in theory means the accuracy of the measurements will be correct.

I'm not going to go into how I designed the venturi tube - there are plenty of diagrams available.

Here is a picture of how the tube will look when printed:

Solid Version Venturi Tube
See Through Diagram of the Venturi Tube with dimensions
I used this and many other sites as a reference on how to make a venturi tube:




I'm going to 3D print this tomorrow but in the mean time lets repeat the calculations to calculate the areas of the first and second sections (The internal tube sections).

In order to make the measurements using the arduino we need the areas calculating for A1 and A2. The formula we are applying in total is:


The dimensions of A1 can be calculated using:





or


Next A2 can be calculated in the same way:






or



Lets now attempt to calculate Q, the Volumetric flow rate.  Lets use a value of 320 for P1 and 200 for P2:



Simplifying gives:





And for the second thinner section:



Simplifying gives:





Both values come in almost exactly the same - close enough for my requirements.  Good to know the mathematics works out!

From that as before the velocity of flow can then be calculated using:







Just for completeness lets use the value for A2 also:







We can now check all is correct as:





This actually computes to:



Which is really good - as we set the values for P1 and P2 to be 320 and 200 Pa to begin with!  The really small error is probably due to rounding errors creeping in with my calculations.  Not of significant importance in this case.

Here is a picture of the tube printed and displayed connected to the mask:

The venturi tube connected to a face mask

We can now use the values for A1 and A2 in the arduino code with the newly printed venturi tube. Hopefully the accuracy will be much improved.

Here is the new code - same as before but updated with the new constants for the venturi tube.

 // MPX7002DP Test Code with conversion   
 // to volumetric flow rate and velocity   
 // of flow  
 //  
 // A.Lang - 2017  
   
 // This code exercises the MPX7002DP  
 // Pressure sensor connected to A0  
   
   
 #include <Average.h>  
   
 Average<float> averageValue(100);  
   
   
 //variables  
   
 int sampleNumber = 0;      // variable to store the sample number   
 int sensorPin = A0;       // select the input pin for the Pressure Sensor  
 int sensorValue = 0;      // variable to store the Raw Data value coming from the sensor  
   
 float averageInitialValue = 0; // variable to store the average inital value  
   
 float diffPressure = 0;     // variable to store converted kPa value   
 float volumetricFlow = 0;    // variable to store volumetric flow rate value   
 float velocityFlow = 0;     // variable to store velocity of flow value   
 float offset = 0;        // variable to store offset differential pressure  
   
 //constants - these will not change  
 const float tubeArea1 = 0.01592994; // area of venturi tube first section 0.003095 0.01592994  
 const float tubeArea2 = 0.0042417; // area of venturi tube second section  
 const float airDensity = 1.225;  
   
 void setup() {  
  // start serial port at 9600 bps and wait for port to open:  
  Serial.begin(9600);  
   
  pinMode(sensorPin, INPUT);  // Pressure sensor is on Analogue pin 0  
   
  Serial.flush();  
  //Serial.println();  
   
  //Header for CSV data  
    
  Serial.print("Sample Number,  Raw Sensor Value, Differential Pressure,  Volumetric Flow Rate,  Velocity of Flow,");  
  Serial.println();  
  Serial.print("       ,     bits    ,      Pa     ,    m^3/second    ,     m/s    ,");  
  Serial.println();  
   
  // get initial sensor value  
   for (int i = 0; i < 100; i++) {  
       
     // read the value from the sensor:   
     sensorValue = analogRead(sensorPin);   
       
     //push sensor values to averageValue object  
     averageValue.push(sensorValue);  
   }  
   
   for (int i = 0; i < 100; i++)   
   {  
    // get average Sensor values  
    averageValue.get(i);  
      
   }  
   
   //calculate mean average sensor and store it  
   averageInitialValue = averageValue.mean();   
   
   Serial.print("Average Initial Value :");  
   Serial.print(averageInitialValue);  
   Serial.println();  
   
 }  
   
 void loop() {  
   
     
   //read the value from the sensor:   
   sensorValue = analogRead(sensorPin);   
     
   // initial value   
   sensorValue = sensorValue - (int)averageInitialValue;  
    
   // increment sample counter   
   sampleNumber++;   
   
  // map the Raw data to kPa  
  diffPressure = map(sensorValue, 0, 1023, 0, 4000);   
   
  if (sensorValue >= 0)  
    {  
     //calculate volumetric flow rate for Exhalation  
     volumetricFlow = tubeArea1 * (sqrt((2/airDensity) * (diffPressure/(sq(tubeArea1/tubeArea2)-1))));  
   
     //calculate velocity of flow   
     velocityFlow = volumetricFlow / tubeArea1;  
    }  
  // convert reading to a positive value  
  else if (sensorValue <= 0) {  
   diffPressure = diffPressure *-1;  
      
    //calculate volumetric flow rate for Inhalation  
    volumetricFlow = tubeArea2 * (sqrt((2/airDensity) * (diffPressure/(1-sq(tubeArea2/tubeArea1)))));  
      
    //calculate velocity of flow   
    velocityFlow = volumetricFlow / tubeArea2;  
  }  
    
  // Print the results as comma separated values for easier processing  
  // in a spreadsheet program  
   
  Serial.print(sampleNumber);  
  Serial.print(",");  
  Serial.print(sensorValue);  
  Serial.print(",");  
  Serial.print(diffPressure);  
  Serial.print(",");  
  Serial.print(volumetricFlow);  
  Serial.print(",");  
  Serial.print(velocityFlow);  
  Serial.print(",");  
  Serial.println();  
    
  // wait 100 milliseconds before the next loop  
  // for the analog-to-digital converter and  
  // pressure sensor to settle after the last reading:  
  delay(100);   
    
 }  

I have added to the setup function to provide an initial average.  This zeros the sensorValue so that there are no issues with negative numbers during the calculation stage.  It is always a good idea to zero things before performing calculations.  I have also reduced the number of variables needed.

If people wish to use this code they will need to download the Average.H library from here:

https://github.com/MajenkoLibraries/Average

The library has been kindly provided by Majenko Technologies and appears to work very well.  It was much quicker to use this library than to write my own function to calculate the average!

Here is the output from the new arduino serial plotter - which is very cool!


Blue trace: Raw sensor Value
Red trace: Differential pressure value, (Positive = Exhaling, Negative = Inhaling)
Green trace: Volumetric Flow
Orange trace: Velocity of Flow

If I could adjust the scales and print each graph on a separate line I'd be half way to displaying the data as requested!

I'm going to look at python scripting to achieve this functionality as I believe it will work best.

That is all for now people - take care always!

Update 2020: Here are the 3D modelling files so anyone can print their own venturi tube - Good luck and stay safe everyone!

19 comments :

  1. I'm doing the same research now, and could you share your Venturimeter Tube design with me, thanks a lot! And I'd like to know if the design have a lot effiect on the result

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. Good job.
    I have a request.
    Can you share your 3d Model?
    Thank You.

    ReplyDelete
    Replies
    1. I will try and find it! I haven't done anything on this for some time. I appreciate others will be though.

      Delete
    2. I have updated the post with a link to the 3D models and STL file so you can make your own venturi tube if you have access to a 3D printer - Good luck!

      https://drive.google.com/drive/folders/1sWd3kXV83VfKSi-DVNcrHFs-n-9aCsfM

      Delete
    3. hello, you've done an amazing job. Congratulations. I'm trying to do something like this, could you please share the 3D model for me to attach to a project?

      Delete
    4. https://drive.google.com/drive/folders/1k0qGE02V4vNY91AUSaYQCAFxW8NmvOt1?usp=sharing - here is a later and better version

      Delete
  4. DearAlexander Lang
    Honest greetings and respect
    we are group of (nonprofit) researcher’s& students working on method to combat covid19 in Africa
    we are impressed about your grate project (experimental Powered air purifying respirator) this project can save people life in Africa.
    we are working on emergency ventilator based on rice university project
    https://github.com/apollobvm
    we are trying to integrate your spirometer design in the (apollobvm ventilator project) please can you help us with
    software (surce code for ) spirometer monitoring & calibration on screen using serial port show consistent real time loop with no mobile application no phone only we have stm32 microcontroller
    our screen options
    • 7.5 Inch Bare e-Paper Screen + Driver Board Onboard ESP8266 +spi interface
    https://www.banggood.com/Waveshare-7_5-Inch-Bare-e-Paper-Screen-Driver-Board-Onboard-ESP8266-Module-Wireless-WiFi-Yellow-Black-and-White-Display-p-1478331.html?rmmds=search&cur_warehouse=CN
    • Nextion Enhanced NX8048K070 7.0 Inch HMI Intelligent Smart USART UART Serial Touch TFT LCD Module
    https://www.banggood.com/7_0-Inch-Nextion-Enhanced-HMI-Intelligent-Smart-USART-UART-Serial-Touch-TFT-LCD-Module-Display-Panel-p-1229187.html?rmmds=myorder&cur_warehouse=CN
    .........................................
    please can you help us with software (source code for ) spirometer monitoring & calibration on windows pc ?
    we are happy if you give us any hardware software suggestion & learning source to modify and implement the spirometer monitoring –calibration source code
    thanks alot in advance

    ReplyDelete
    Replies
    1. Dear friends, if you need I can provide you with support and I would like to know your project.
      I'm a IoT mentor and Developer from Sardinia (Italy).

      Delete
    2. I am happy to assist where I can of course.

      If I understand correctly you wish to use an STM32 Microcontroller to receive the signals from the sensor connected to the venturi tube. You then want to display the result from that measurement on a display and you provide two options:

      7.5 Inch Bare e-Paper Screen + Driver Board Onboard ESP8266 +spi interface

      Nextion Enhanced NX8048K070 7.0 Inch HMI Intelligent Smart USART UART Serial Touch TFT LCD Module

      I need to know which STM32 microcontroller you have so I can re-write the code to work for it. I'm not sure I have one available so I would need to get one...

      Either display will probably work as required. I have not used either before so I cannot really comment - E-paper screens use less electrical power but the ESP8266 module is possibly unnecessary. The UART controlled touch screen is probably my first choice as I have used one before - not that one but a similar device.

      Are you looking to reproduce the ApolloBVM and combine the spirometer into it?

      If you want to calibrate the system you will need a reference device to compare it to which I cannot provide - I don't have one or access to one. I can tell you how to perform a rough calibration and tailor the response but that is all I can do.

      I suggest you email me: alexanderlang1980@gmail.com

      Good luck!

      Delete
  5. PS Alexander Lang is very strong

    ReplyDelete
    Replies
    1. Grazie per il complimento - ho il sospetto che il tuo programma di traduttore abbia leggermente perso il tuo significato, ma è stato molto gentile da parte tua scriverlo! ;)

      Thank you for the compliment - I suspect your translator program has slightly missed your meaning however it was very kind of you to write that! ;)

      Delete
    2. Non hai fatto niente di male! In inglese la parola forza quando viene data come un complimento normalmente si riferisce alla forza fisica. Nulla di cui ho scritto qui dà un'idea delle mie capacità fisiche, quindi sembrava un po 'fuori. Non sono particolarmente forte fisicamente ma suppongo di avere momenti di forza mentale ;)

      You did nothing wrong! In English the word strength when given as a compliment normally relates to physical strength. Nothing I have written about on here gives any idea of my physical capability so it seemed a little off. I am not particularly strong physically but I suppose I have moments of mental strength ;)

      Delete
    3. Hi Alexander, in Italy "Strong = Forza" is use to physical strenght and mental strenght

      Then double compliment ;-)

      Delete
    4. thanks alot for your replay any help will be appreciated
      id170072@aou.edu.sd

      Delete
  6. Hi, really enjoy your posts.Very useful. However, I think you made a mistake, you converted area from mm^2 to m^2 whereas you should have converted to m^3 as Area(Volume) is measured in cubed meters. Let me know if you agree.

    Wkr,

    Andrew

    ReplyDelete
    Replies
    1. Andrew,

      I think you are correct. The area of the cylinder units should be mm^3 and then converted to m^3. I will update the post and thank you for the feedback. The computation is hopefully correct though. It has been a while since I wrote this post...

      Delete