IoT-Based Remote Patient Monitoring System to Measure Vital
When we are talking about major vital signs of a human body, there are four major parameters that we need to be aware of, they are body temp
Components and supplies
1
MLX90614
1
Silicone sleeve Arduino Nano 33 BLE Sense
1
Perfboard
1
jumpers
1
MAX30100
1
Ad8232
Apps and platforms
1
Arduino IDE 2.0 (beta)
Project description
Code
IoT-Based Remote Patient Monitoring System to Measure Vital
c
Code
1#include <Wire.h> 2#include "MAX30100_PulseOximeter.h" 3#include "MAX30100.h" 4#include <Adafruit_MLX90614.h> 5#include <Adafruit_GFX.h> 6#include <U8x8lib.h> 7#include <avr/dtostrf.h> 8#define REPORTING_PERIOD_MS 500 //update rate of hr, spo2, ambient, object, hrv, etc parameters in milli seconds 9#define DISPLAY_INTERVAL 5 //update rate for the i2c display = REPORTING_PERIOD_MS*DISPLAY_INTERVAL 10#define COMPENSATION 5 //compensation in object temperature. Different body parts have different temperatures. Fingers are around 5 degF lower than core body temperature 11// objects 12PulseOximeter pox; //this offers spo2 and hr calculation 13Adafruit_MLX90614 mlx = Adafruit_MLX90614(); 14U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); 15MAX30100 sensor; 16//variables 17uint32_t tsLastReport = 0; 18int hr, spo2, count = 0, flag = 0, PatientID = 0; 19float ambient, object, hrv; 20long time1 = 0, time2 = 0; 21uint16_t ir = 0, red = 0, ecg = 0, mic; ; 22char str_hrv[10], str_object[10], str_ambient[10], str_ir[10], str_red[10]; 23// Callback (registered below) fired when a pulse is detected 24void onBeatDetected() 25{ 26 time1 = micros() - time2; 27 time2 = micros(); 28} 29void setup() 30{ 31 //display connected 32 u8x8.begin(); 33 u8x8.setPowerSave(0); 34 u8x8.setFont(u8x8_font_chroma48medium8_r); 35 //pinMode(10, INPUT); // Setup for leads off detection LO + 36 //pinMode(11, INPUT); // Setup for leads off detection LO - 37 Serial.begin(115200); 38 /* 39 while (!Serial) { 40 ; // wait for serial port to connect. Needed for native USB port only 41 } 42 */ 43 // Initialize the PulseOximeter instance 44 // Failures are generally due to an improper I2C wiring, missing power supply 45 // or wrong target chip 46 if (!pox.begin(PULSEOXIMETER_DEBUGGINGMODE_RAW_VALUES)) { 47 //Serial.println("FAILED"); 48 for(;;); 49 } else { 50 //Serial.println("SUCCESS"); 51 } 52 // The default current for the IR LED is 50mA and it could be changed 53 // by uncommenting the following line. Check MAX30100_Registers.h for all the 54 // available options. 55 pox.setIRLedCurrent(MAX30100_LED_CURR_11MA); 56 // Register a callback for the beat detection 57 pox.setOnBeatDetectedCallback(onBeatDetected); 58 mlx.begin(); 59 time2 = micros(); 60} 61void loop() 62{ 63 // Make sure to call update as fast as possible 64 pox.update(); 65 sensor.update(); 66 //reading continuous functions (signals) every loop 67 while (sensor.getRawValues(&ir, &red)) {} 68 ecg = analogRead(A0); 69 ecg = map(ecg, 250, 500, 0, 100); 70 mic = analogRead(A1); 71 delay(1); 72 // Asynchronously calculate other variables every REPORTING_PERIOD_MS 73 // For hr and spo2, a value of 0 means "invalid", for object and ambient temperatures a value less than 70 degF or higher than 110 degF can be considered abnormal 74 if (millis() - tsLastReport > REPORTING_PERIOD_MS) { 75 hr = pox.getHeartRate(); 76 spo2 = pox.getSpO2(); 77 ambient = mlx.readAmbientTempF(); 78 object = mlx.readObjectTempF() + COMPENSATION; 79 hrv = (60000000/hr - (float)time1)/1000; 80 //send_serial(); 81 tsLastReport = millis(); 82 count++; 83 flag = 0; 84 } 85 //Display all variables on the display after DISPLAY_INTERVAL seconds 86 if ((count%DISPLAY_INTERVAL == 0) && (flag != 1)) { 87 flag = 1; //This flag makes sure the display is updated only once every DISPLAY_INTERVAL seconds 88 Wire.end(); 89 send_display(); 90 Wire.begin(); 91 } 92 Telemetry(); 93} 94//serial monitor print function. 95//Not required actually as telemetry function prints all values in csv format on the serial monitor 96void send_serial() { 97 Serial.print("bpm / SpO2:"); 98 Serial.print("Heart rate:"); 99 Serial.print(hr); 100 Serial.print(spo2); 101 Serial.print("% / hrv:"); 102 Serial.print(hrv); 103 Serial.print("ms / Ambient:"); 104 Serial.print(ambient); 105 Serial.print("*F / tObject = "); 106 Serial.print(object); 107 Serial.println("*F"); 108} 109//display print function 110void send_display() { 111 u8x8.clearDisplay(); 112 u8x8.setCursor(0,1); 113 u8x8.print("HRV:"); 114 u8x8.print(hrv); 115 u8x8.print(" ms"); 116 u8x8.setCursor(0,2); 117 u8x8.print("SpO2:"); 118 u8x8.print(spo2); 119 u8x8.print(" %"); 120 u8x8.setCursor(0,3); 121 u8x8.print("HR:"); 122 u8x8.print(hr); 123 u8x8.print(" bpm"); 124 u8x8.setCursor(0,4); 125 u8x8.print("Temp:"); 126 u8x8.print(object); 127 u8x8.print(" degF"); 128 u8x8.setCursor(0,5); 129 u8x8.print("ecg:"); 130 u8x8.print(ecg); 131 u8x8.setCursor(0,6); 132 u8x8.print("mic"); 133 u8x8.print(mic); 134 //delay(200); 135} 136//serial telemetry for edge impulse data forwarder 137void Telemetry() { 138 char buffer[150]; 139 dtostrf(hrv, 4, 2, str_hrv); 140 dtostrf(object, 4, 2, str_object); 141 dtostrf(ambient, 4, 2, str_ambient); 142 dtostrf((float)ir/100, 5, 2, str_ir); 143 dtostrf((float)red/100, 5, 2, str_red); 144 sprintf(buffer,"%d,%d,%d,%d,%s,%s,%s,%s,%s,%d,%d",PatientID,count/10,hr,spo2,str_hrv,str_object,str_ambient,str_ir,str_red,ecg,mic); 145 Serial.println(buffer);
Comments
Only logged in users can leave comments