After trying to use others type of temperature sensor (LM35 and DHT22) we proceed to testing the thermistor again. So, the respiration rate was measured based on the coding that have been set.
#include <LiquidCrystal.h>
enum respState
{
Inhaling,
Exhaling
};
unsigned long prevRespTime = 0;
unsigned long currRespTime = 0;
respState currentRespState;
int movingAvgRespRate = 0;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
pinMode(9,OUTPUT); //buzzer
}
void loop()
{
//delay(500);
// don't need to delay because we'll only fire once per inhalation and once per exhalation
int sensorValue = analogRead(A0);
if (sensorValue > 510 && currentRespState == Exhaling)
{
currentRespState = Inhaling;
prevRespTime = currRespTime; // save time from last cycle
currRespTime = millis();
float period_respiration = currRespTime - prevRespTime;
float breathrate = 60000 / period_respiration;
Serial.print("Inhaling \tRespirations per minute: ");
Serial.println(breathrate);
lcd.setCursor(0, 1);
lcd.print("RPM");
lcd.print(breathrate);
if (breathrate>1 && breathrate<9)
{
digitalWrite(9,HIGH);
delay(2000);
digitalWrite(9,LOW);
delay(200);
}
if (breathrate>60 && breathrate<100)
{
digitalWrite(9,HIGH);
delay(1000);
digitalWrite(9,LOW);
delay(200);
}
else if (breathrate>101 && breathrate<500 )
{
digitalWrite(9,HIGH);
delay(500);
digitalWrite(9,LOW);
delay(200);
}
else
{
digitalWrite(9,LOW);
}
}
else if (currentRespState == Inhaling && sensorValue < 490)
{
currentRespState = Exhaling;
Serial.println("Exhaling");
lcd.setCursor(0, 0);
lcd.print("Exhaling ");
}
}
Measure the Respiration Rate
The measurement of the respiration rate was based on what value of the temperature sensor recorded. After knowing how the temperature was recorded, Arduino can process the data to measure respiration rate. When exhalation the temperature increase while inhalation the temperature decrease. From the value of the temperature measurement, the Arduino convert temperature value to the digital value so that the controller can calculate the respiration rate. The calculation for the respiration rate depends on the coding.
The sensor value (temperature sensor) in digital was set up for exhalation
The sensor value (temperature sensor) in digital was set up for inhalation
The calculation to measure respiration rate.
The result for the respiration rate cannot be measured accurately. This is because of the temperature sensor that has been used is not suitable and not to be used to measure accurate breathing. But, there is some result from the testing might be the right value for the respiration rate because the normal respiration rate for an adult is 12-20breath per minute.
The result measured that get normal respiration rate.
The normal respiration rate (RPM 13) result display in the LCD
The result measured that get abnormal respiration rate
The abnormal respiration rate (RPM 38) result display in the LCD
The RPM:13.42 respirations per minute can be the normal result for the respiration rate while RPM:38.10 respirations per minute can be the abnormal respiration rate. Other than that must be the wrong result because of the wrong calculation that has been processed with wrong temperature changes by the microcontroller. When there is an abnormal result, the coding was set up for the buzzer to ringing.
No comments:
Post a Comment