Hi,
Im trying to develop a device that can measure the respiration rate of a pt, but Im having trouble accurately determine the point when the chest is rissing or falling.
Im using a Tinkerkit T00002X acclerometer to try and do so was wondeering is it possible to accurately determine the velocity from this or would using a gyroscope as well help.
This is my unfinshed code:
#include <TinkerKit.h>
#include <LiquidCrystal.h>
#include <timer.h>
#include <arduino-timer.h>
int counter = 0;
static unsigned long currentime;
static unsigned long timer;
static unsigned long timerdone;
int pol[10];
int avgacc ;
float velocity = 0;
int counter2 = 0;
int x ;
int y ;
int z ;
int r ;
int trigger = 0;
TKAccelerometer acl(I0, I1, I2); // Creates a acclerometer object
LiquidCrystal lcd = LiquidCrystal(12, 11, 5, 4, 3, 2); // Creates a Lcd object
void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
noInterrupts();
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
TCCR1B |= (1 << WGM12);
TCCR1B |= (1 << CS11); // prescaler of 8
OCR1A = 19999;
TIMSK1 |= (1 << OCIE1A);
interrupts();
}
ISR(TIMER1_COMPA_vect)
{
x = acl.readX() - 484;
y = acl.readY() - 470;
z = acl.readZ() - 561;
r = sqrt((x * x) + (y * y) + (z * z));
//Serial.print(r);
// Serial.print(" ");
if (counter == 10)
{
avgacc = avgacc/10;
trigger = 1;
// Serial.print(avgacc);
// Serial.print(" \n");
counter = 0;
}
else
{
avgacc = avgacc + r;
counter = counter + 1;
}
}
void loop()
{
if (trigger == 1)
{
velocity = velocity + (y) * 0.1;
pol[0] = avgacc;
for (int i = 9; i >= 1; i--)
{
pol[i] = pol[i - 1];
//Serial.print(pol[i]);
//Serial.print(" ");
}
//Serial.print(pol[0]);
Serial.print(avgacc);
//Serial.print(" ");
Serial.print(" \n");
if(pol[6] > pol[7] && counter2 == 0)
{
delay(100);
counter2 = 1;
// Serial.print("test");
// Serial.print("\n");
}
if(counter2 == 1 && pol[5] < pol[6] )
{
Serial.print("test");
Serial.print(" ");
counter2 = 0;
}
trigger = 0;
avgacc = 0;
counter = 0;
}
}
For monitoring respiration you might want to look at the millimeter wavelength radar modules that SeedStudio.com recently brought to market one app they identify is respiration monitoring. One drawback is they cost about 10 times more than an accelerometer but the user won't have to wear any sensor, plus you won't have to concern yourself with the drift of the less than nav-grade accelerometer.
Well you can integrate the readings to give a velocity signal, but this will drift over time quite substatially due to the nature of these devices - you could then high-pass filter the signal to remove the drift, it might work. You'd need to keep a careful eye on phase issues doing this, perhaps a Bessel filter would be needed. Even a Bessel filter will have some delay though.
Another approach is build a drift estimator so it can be subtracted off.
But your Arduino doesn't know that and your program will not know that, so how will your program know when a breathing cycle begins and ends, based only on the accelerometer readings?
Im currently just using accleration and the values between each one seeing if that is sufficet and if I dont actually have to intergrate at all, but If I do I was planning to intergrte between every value I esseentially take a reading every 0.1 seconds
"For nasal breathing, the maximum propagation distance and derived velocity were 0.6 m and 1.4 m/s, respectively. The maximum 2-D area of dissemination and derived expansion rate were 0.11 m2 and 0.16 m2/s, respectively. Similarly, for mouth breathing, the maximum propagation distance and derived velocity were 0.8 m and 1.3 m/s, respectively. " Airflow Dynamics of Human Jets: Sneezing and Breathing - Potential Sources of Infectious Aerosols (plos.org) and that's for a sneeze.
Now to find a hobby grade thingy that can do the measurement.
A while ago I was reclining in my recliner and checked my breathing. Mouth breathing cause almost no chest movement. Nose breathing was a lot of chest movement. Strange how that works.