the code uses an NTC thermistor to measure the respiration rate.

Committer:
moe414
Date:
Sat May 26 03:59:57 2018 +0000
Revision:
0:eefa433e1005
Respiration sensor using a Thermistor

Who changed what in which revision?

UserRevisionLine numberNew contents of line
moe414 0:eefa433e1005 1 /*
moe414 0:eefa433e1005 2 Repiration rate using an NTC thermistor
moe414 0:eefa433e1005 3 this porgam is desgined to read the the voltage on the thrmistor sensor and convert it to temperature.
moe414 0:eefa433e1005 4 A timer will start at the begining and after 60 seconds the program will print the breath per minute.
moe414 0:eefa433e1005 5 the program will set the first tempeature as the threshold and compare it with the threshold if the
moe414 0:eefa433e1005 6 temperature increased by 0.5 degrees a count will increase each time it occures. when the program reaches
moe414 0:eefa433e1005 7 60 seconds, the program will print the number of counts which relates to the breathing rate per minute.
moe414 0:eefa433e1005 8 created by Mohammed Al Qanber on APR 10, 2018.
moe414 0:eefa433e1005 9 */
moe414 0:eefa433e1005 10 #include "mbed.h"
moe414 0:eefa433e1005 11 #include "therm.h"// the temperature eqiuation written in a function in a seperate file.
moe414 0:eefa433e1005 12 AnalogIn sensor(A0);//attache AnalogIn to pin A0.
moe414 0:eefa433e1005 13 Serial pc(USBTX, USBRX);// serial communications.
moe414 0:eefa433e1005 14 //varibales definition
moe414 0:eefa433e1005 15 float tempinf(float sensor) ;
moe414 0:eefa433e1005 16 float TT;
moe414 0:eefa433e1005 17 float tempin;
moe414 0:eefa433e1005 18 Timer mytimer; // create the timer function.
moe414 0:eefa433e1005 19 int count =0; // initial the count with zero value.
moe414 0:eefa433e1005 20 int main(){
moe414 0:eefa433e1005 21 while(1){
moe414 0:eefa433e1005 22
moe414 0:eefa433e1005 23 float reading = sensor; //set the voltage reading from the function to a variable.
moe414 0:eefa433e1005 24 //pc.printf("the reading value is %f\n",reading);//print the analog reading voltage
moe414 0:eefa433e1005 25 float threshold=tempinf(sensor); //set the first temperature as the threshold.
moe414 0:eefa433e1005 26 mytimer.start(); //start the timer.
moe414 0:eefa433e1005 27 // pc.printf("the reading value is %f\n",threshold);// print the threshold value if needed.
moe414 0:eefa433e1005 28 tempin=tempinf(sensor);//use the temprature equation output and assgin it to tempin
moe414 0:eefa433e1005 29 //pc.printf(" %f C \n",tempin);//print the temperature value if needed.
moe414 0:eefa433e1005 30 wait(1.5); // wait 1.5 seconds between readings.
moe414 0:eefa433e1005 31 //the if function will compare the temperature reading to the threshold.
moe414 0:eefa433e1005 32 if (tempin>threshold+1/2){
moe414 0:eefa433e1005 33 count++; // the count will increase by one when the if statment is true.
moe414 0:eefa433e1005 34 }
moe414 0:eefa433e1005 35 int timer=mytimer.read(); // this function will read the timer value.
moe414 0:eefa433e1005 36 // if the timer value reaches 60 seconds the if statment will be true.
moe414 0:eefa433e1005 37 if (timer>=60){
moe414 0:eefa433e1005 38 // pc.printf(" time: %d \n",timer); // print the time to make sure it reached 60 seconds if needed.
moe414 0:eefa433e1005 39 pc.printf(" %d \n",count); // print the breath per minute.
moe414 0:eefa433e1005 40 mytimer.reset();// reset the timer for the next cycle
moe414 0:eefa433e1005 41 count =0;// reset the counter for the next cycle.
moe414 0:eefa433e1005 42 }
moe414 0:eefa433e1005 43 }
moe414 0:eefa433e1005 44 }
moe414 0:eefa433e1005 45