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.