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

Files at this revision

API Documentation at this revision

Comitter:
moe414
Date:
Sat May 26 03:59:57 2018 +0000
Commit message:
Respiration sensor using a Thermistor

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
therm.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r eefa433e1005 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat May 26 03:59:57 2018 +0000
@@ -0,0 +1,45 @@
+/*
+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.
+    } 
+}
+}
+ 
diff -r 000000000000 -r eefa433e1005 therm.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/therm.h	Sat May 26 03:59:57 2018 +0000
@@ -0,0 +1,12 @@
+
+//this function is programmed to take the analong voltage value and convert it to temperature.
+float tempinf(float sensor) {
+        // first it will convert the voltage to resistance
+        double R_ratio = (1/sensor- 1);
+        double logR_ratio=log(R_ratio);
+        //the next line will convert the resistance to temperatue in Kelvin units using Steinhart and Hart equation.
+        double T_kelvin=1/(.003354016+.000256985*logR_ratio+.000002620131*logR_ratio*logR_ratio);
+        float T = (T_kelvin - 273);//conver the temperture to celsious 
+        return T; // returen the temperature value.
+
+}
\ No newline at end of file