This shows you the differences between two versions of the page.
iothings:proiecte:2021:pulsemonitorsystem [2022/01/28 00:44] ana_maria.cretan [Software code detailed] |
iothings:proiecte:2021:pulsemonitorsystem [2022/01/28 08:40] (current) ana_maria.cretan [Software flow] |
||
---|---|---|---|
Line 5: | Line 5: | ||
====== Project description ====== | ====== Project description ====== | ||
- | The goal of this project is to create a real-time pulse and oxygen level monitor platform using an ESP32 board and MAX30100 sensor. The data provided by the sensor will be displayed in the Adafuit IO interface and interpreted by two flag indicators. The indicators aim to translate the values of the pulse and oxygen level into a simple good(green)/bad(red) lamp indication. If the registered values are out of the normal range, an e-mail alert will be sent to the user/user`s contacts. | + | The goal of this project is to create a real-time pulse and oxygen level monitor platform using an ESP32 board and MAX30100 sensor. The data provided by the sensor will be displayed in the Adafuit IO interface and interpreted either by a flag indicator or an email alert. The indicator aims to translate the values of the pulse and oxygen level into a simple good(green)/bad(red) lamp indication. If the registered values for the pulse monitor are out of the normal range, an e-mail alert will be sent to the user/user`s contacts. |
| | ||
====== Hardware implementation ====== | ====== Hardware implementation ====== | ||
Line 17: | Line 17: | ||
{{:iothings:proiecte:2021:schematic_iot_prj_2022-01-24.png?500|}} | {{:iothings:proiecte:2021:schematic_iot_prj_2022-01-24.png?500|}} | ||
- | ====== Software code flow ====== | + | ====== Work flow ====== |
+ | The implementation consists of three connections: | ||
+ | * Connection with the pulse sensor MAX301000 - for data receiving | ||
+ | * Connection to the Adafruit IO through MQTT client - for displaying the data and its interpretation | ||
+ | * Connection to the IFTTT API - for the email alert feature | ||
The main functionality of the code is displayed by the following diagram. The //setup()// function is executed first and is used to enable the wi-fi connection, connect to the MQTT client, and config the pulse sensor. | The main functionality of the code is displayed by the following diagram. The //setup()// function is executed first and is used to enable the wi-fi connection, connect to the MQTT client, and config the pulse sensor. | ||
- | {{:iothings:proiecte:2021:iot_prj_pulse_monitor_soft.drawio.png?500|}} | + | {{ :iothings:proiecte:2021:iot_prj_pulse_monitor_soft.drawio_1_.png?500 |}} |
In the setup section of the code, the Wi-Fi connection is established, followed by the MQTT connection for the web application and the configuration of the pulse sensor. | In the setup section of the code, the Wi-Fi connection is established, followed by the MQTT connection for the web application and the configuration of the pulse sensor. | ||
- | During the loop section, the connection to the MQTT client is checked first along with the switch state from the application. The data published to the web display can we stopped at any time (while connected) by turning the switch block off. | + | During the loop section, the connection to the MQTT client is checked first along with the switch state from the application. The data published to the web display can be stopped at any time (while connected) by turning the switch block off. |
- | ====== Software code detailed ====== | + | ====== Software implementation ====== |
The code is developed using Arduino IDE,and the following libraries: | The code is developed using Arduino IDE,and the following libraries: | ||
Line 38: | Line 43: | ||
- | In this section we will go over the main blocks of the diagram presented in the previous section: | + | The sensor data read and the publish to the MQTT client are split into tasks.For the sensor read, we use update() from the Max30100 library and getHeartRate()/pox.getSpO2 to obtain the actual values. Before they are published we test if the recorded values are in the normal range: |
<code c> | <code c> | ||
- | this is ok | + | if (BPM == 0){ //Asystole: flat linig |
- | </code c> | + | BPMState_ns = "Asystole"; |
+ | }else if(BPM != 0 && BPM <= 40){ //Idioventricular Rhythm: Heart rate between 20 - 40 BPM | ||
+ | BPMState_ns = "Idioventricular Rhythm"; | ||
+ | } else if(BPM > 40 && BPM <= 60){ //Junctional Escape Rhythm: Heart rate 40 - 60 BPM | ||
+ | BPMState_ns = "Junctional Escape Rhythm"; | ||
+ | } else if(BPM > 60 && BPM <= 120){ //Normal: Heart rate 60 - 100 BPM | ||
+ | BPMState_ns = "Normal"; | ||
+ | } else if(BPM >= 121){ //Tachycardia: Heart rate >= 100 BPM | ||
+ | BPMState_ns = "Tachycardia"; | ||
+ | }; | ||
+ | |||
+ | </code> | ||
+ | |||
+ | * for the Oxigen level the interpretation is into the interface block \\ | ||
+ | For the email alert we used the following format, including the medical term of the non regular range (BPMState_ps) | ||
+ | <code c > | ||
+ | client.print(String("POST ") + URL + API_KEY + " HTTP/1.1\r\n" + | ||
+ | "Host: " + HOST + "\r\n" + | ||
+ | "Content-Type: application/x-www-form-urlencoded\r\n" + | ||
+ | "Content-Length: 13\r\n\r\n" + | ||
+ | "value1=" + BPMState_ps + "\r\n"); | ||
+ | } | ||
+ | </code> | ||
+ | Source code link: [[https://github.com/Ana99889/IOT_prj/blob/main/arduino_source_code | GitHub Repo]] | ||
+ | |||
+ | ===== Software Interface ===== | ||
+ | |||
+ | The interface consists of four blocks: | ||
+ | * Switch - to turn on/off the sensor readings | ||
+ | * Pulse Monitor - displays the BPM values recorded from the sensor | ||
+ | * Oxygen level - displayed the SpO2 % recorded from the sensor | ||
+ | * Oxygen level interpreter - red (values not in the normal range), green(values in the normal range) | ||
+ | |||
+ | {{ :iothings:proiecte:2021:pulse_interface.png?400 |}} | ||
+ | ===== Demo ===== | ||
+ | In the video, we can see a normal reading of the sensor data and its interpretation, along with a simulation without the pulse sensor, using random data published to the interface. The random data simulation has only a testing purpose. | ||
+ | * [[https://youtu.be/C3xvUPrdKlY | Demo Video ]] | ||
+ | ===== Resources ===== | ||
+ | * [[https://github.com/Ana99889/IOT_prj/blob/main/arduino_source_code | Source code - GitHub Repo]] | ||
+ | * [[https://www.espressif.com/sites/default/files/documentation/esp32-wroom-32_datasheet_en.pdf | ESP32 Datasheet]] | ||
+ | * [[https://datasheets.maximintegrated.com/en/ds/MAX30100.pdf | Pulse Oxi - MAX30100 Datasheet]] | ||
+ | * [[https://learn.adafruit.com/ | Adafruit IO tutorials]] | ||
+ | * [[https://ifttt.com/explore/welcome_to_ifttt | IFTTT Guide]] | ||
+ | * Schematics: | ||
+ | * [[https://easyeda.com/ | EasyEda]] | ||
+ | * [[https://draw.io | Draw IO]] | ||