Detecting inward or outward breath with simple fan

Hi.

I am building a device to measure breath intensity and direction. I am breathing through a tube at whose far end sits a small 5V / 0.4W cooling fan. I am trying to use the voltage generated by the fan when air rushes in and out of the tube as a proxy for breath intensity and direction. The voltage (detected using analogRead at pin A3) however, always increases—no matter if I am breathing in or out. (See “fan in tube.jpg” in repo).

There is battery-powered Arduino that is reading these voltages, performing some smoothing and then sending them to another Arduino through a wireless nRF24 connection. This second Arduino is connected via Pyserial to the Python script where I am trying to invert the voltage crests caused by the “out-breaths”, so that I can have a signal that increases when I’m breathing out, and decreases when I’m breathing in. (See “setup.jpg” in repo).

As you can see in the image named “Graph” below, the voltages generated by breathing in are much higher. The green line represents my attempt at inverting the “out-breath” signals, with very limited success. The yellow line at the bottom is representing inversions in the gradients of the plotted voltages.

So, my questions are:

-Is there something basic I’m missing (first Arduino/programming project ever) and can the fan produce a signal that faithfully represents the fact that it is turning in one direction when I breathe in, and in the opposite one when I breathe out?

-If that is not the case, do you have any ideas on the software side (be it on the Arduino or the Python script) so that I can invert these voltages in real time? It’s easy doing it post-mortem so to say, but I’m feeling that the fact that I don’t know, in real time, how intense a breath will be, and where the gradient will change, means that I cannot reliably invert the second part of the “out-breath” crest as it approaches its trough. But I’m an absolute beginner so I really shouldn’t trust my feeling.

I’m linking the Github repository. There are three files. One for each Arduino (one for the transmitter/voltage reader and another for the receiver), and a third for the Python script performing the real-time correction attempt.

I’m aware that there are breathing detectors (Bitalino etc.) but they are 100€, and using such a simple fan feels like an interesting challenge.

Thank you so much in advance, really looking forward to any suggestions/ideas/corrections.

Gonzalo

Hold the fan in Your hand, connect a multimeter and blow from both directions and see what the meter shows. Remeber that Arduinos only handle positive analog voltages.

Try using a differential pressure sensor such as one from the MPX family: https://www.nxp.com/products/sensors/pressure-sensors:DRSNSPRSSR The output will be biased at mid supply, connect the output to one of the analog inputs. Connect one of the pressure inputs to the tube so it gets the internal pressure, leave the othe open, that is your reference. With no pressure you will get your zero point on the A/D then as you inhale or exhale the reading will swig positive or negative from the midpoint keeping everything in the 0-5 volt range. If it works backwards simply swap the pressure port connections. These sensors are very stable and accurate. Good Luck & Have Fun! Gil

Thank you for your suggestion Gil! I've been looking into them and I'm a bit confused regarding the pressure ranges. The differential gauges they recommend for Respiratory Systems and Hospital Beds: https://www.nxp.com/products/sensors/pressure-sensors/differential-gauge-up-to-10-kpa:DG_10KPA#/ have a pressure range of up 10kPa. Given that 1atm is 101kPa, will that 5% variance on each side be enough?

gilshultz: With no pressure you will get your zero point on the A/D then as you inhale or exhale the reading will swig positive or negative from the midpoint keeping everything in the 0-5 volt range. If it works backwards simply swap the pressure port connections.

Also, won't the sensor be measuring a drop in pressure in the tube as I blow in and out through it? In that case, won't the pressure difference always be negative? How can air blowing in one direction or the other cause the pressure to drop/increase, instead of just increasing to varying degrees depending on the airflow speed?

Cheers, Gonzalo