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

main.cpp

Committer:
moe414
Date:
2018-05-26
Revision:
0:eefa433e1005

File content as of revision 0:eefa433e1005:

/*
Repiration rate using an NTC thermistor 
this porgam is desgined to read the the voltage on the thrmistor sensor and convert it to temperature.
A timer will start at the begining and after 60 seconds the program will print the breath per minute.
the program will set the first tempeature as the threshold and compare it with the threshold if the 
temperature increased by 0.5 degrees a count will increase each time it occures. when the program reaches 
60 seconds, the program will print the number of counts which relates to the breathing rate per minute.
created by Mohammed Al Qanber on APR 10, 2018.
*/
#include "mbed.h"
#include "therm.h"// the temperature eqiuation written in a function in a seperate file.
AnalogIn sensor(A0);//attache AnalogIn to pin A0.
 Serial pc(USBTX, USBRX);// serial communications.
 //varibales definition 
float tempinf(float sensor) ;
float TT;
float tempin;
Timer mytimer; // create the timer function. 
 int count =0; // initial the count with zero value.
int main(){
    while(1){
       
        float reading = sensor; //set the voltage reading from the function to a variable.
        //pc.printf("the reading value is %f\n",reading);//print the analog reading voltage
float threshold=tempinf(sensor); //set the first temperature as the threshold.
  mytimer.start(); //start the timer.
   // pc.printf("the reading value is %f\n",threshold);// print the threshold value if needed.
  tempin=tempinf(sensor);//use the temprature equation output and assgin it to tempin
//pc.printf(" %f C \n",tempin);//print the temperature value if needed.
   wait(1.5);  // wait 1.5 seconds between readings.  
   //the if function will compare the temperature reading to the threshold.   
if (tempin>threshold+1/2){
 count++; // the count will increase by one when the if statment is true.
}
 int timer=mytimer.read(); // this function will read the timer value.
 // if the timer value reaches 60 seconds the if statment will be true.
 if (timer>=60){
   // pc.printf(" time: %d  \n",timer); // print the time to make sure it reached 60 seconds if needed.
    pc.printf(" %d  \n",count); // print the breath per minute.
    mytimer.reset();// reset the timer for the next cycle 
    count =0;// reset the counter for the next cycle.
    } 
}
}