Arduino开发实例-DIY简单脉搏血氧仪(基于MAX30100)
DIY 脉搏血氧仪(基于MAX30100)
1、应用介绍
本文将介绍如何通过MAX30100制作一个简易的脉搏血氧仪。脉搏血氧仪用于测量心率和 SpO2 水平,在这里,我们将使用 Arduino、MAX30100 传感器和 0.96 英寸 SSD1306 OLED 显示屏 DIY 脉搏血氧仪。
在前面的文章中,对MAX30100传感器模块驱动做了详细的介绍,请参考:
在前面的文章,对MAX30100传感器模块的连接问题解决做了详细的介绍,请参考:
关于SSD1306 OLED驱动请参考:
本次DIY应用使用的配件列表如下:
| 序号 |
配件名称 |
描述 |
数量 |
| 1 |
Arduino Uno R3 |
Arduino Uno R3 |
1 |
| 2 |
MAX30100 传感器模块 |
MAX30100 心率血氧计传感器 Arduino 模块 |
1 |
| 3 |
OLED 显示屏 |
0.96” I2C OLED显示模块 |
1 |
| 4 |
4.7K欧姆电阻 |
4.7K欧姆电阻 |
3 |
| 5 |
连接线 |
面包板连接线 |
20 |
| 6 |
面包板 |
微型面包板 |
1 |
2、硬件接线

3、应用驱动实现
下面为 Arduino 和 MAX30100 传感器的脉搏血氧仪的程序代码。 在代码中使用了一些重要的库。 需要将它们安装在 Arduino IDE 中。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| #include "MAX30100\_PulseOximeter.h" #include <Adafruit\_SSD1306.h> #include <U8g2lib.h> #include <Wire.h>
#define REPORTING\_PERIOD\_MS 500 U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);
// MAX3010传感器设备对象 PulseOximeter pox;
const int numReadings=15; float filterweight=0.5; uint32\_t tsLastReport = 0; uint32\_t last_beat=0; int readIndex=0; int average_beat=0; int average_SpO2=0; bool calculation_complete=false; bool calculating=false; bool initialized=false; byte beat=0;
// 心跳中断回调 void onBeatDetected() { show\_beat(); last_beat=millis(); } // 显示心跳数据 void show\_beat() { u8g2.setFont(u8g2_font_cursor_tf); u8g2.setCursor(8,10); if (beat==0) { u8g2.print("\_"); beat=1; } else { u8g2.print("^"); beat=0; } u8g2.sendBuffer(); }
// OLED设备初始化 void initial\_display() { if (not initialized) { u8g2.clearBuffer(); show\_beat(); u8g2.setCursor(24,12); u8g2.setFont(u8g2_font_unifont_t_bengali); u8g2.print("Place Finger"); u8g2.setCursor(0,30); u8g2.print("On The Sensor.."); u8g2.sendBuffer(); initialized=true; } }
// 显示测量进度 void display\_calculating(int j) { if (not calculating) { u8g2.clearBuffer(); calculating=true; initialized=false; } show\_beat(); u8g2.setCursor(24,12); u8g2.setFont(u8g2_font_unifont_t_bengali); u8g2.print("Measuring...."); u8g2.setCursor(0,30); for (int i=0;i<=j;i++) { u8g2.print("."); } u8g2.sendBuffer(); }
// 显示测量结果 void display\_values() { u8g2.clearBuffer(); u8g2.setFont(u8g2_font_unifont_t_bengali); u8g2.setCursor(65,12); u8g2.print(average_beat); u8g2.print(" Bpm"); u8g2.setCursor(0,30); u8g2.print("SpO2 "); u8g2.setCursor(65,30); u8g2.print(average_SpO2); u8g2.print(" %"); u8g2.sendBuffer(); }
// 计算平均值 void calculate\_average(int beat, int SpO2) { if (readIndex==numReadings) { calculation_complete=true; calculating=false; initialized=false; readIndex=0; display\_values(); } if (not calculation_complete and beat>30 and beat<220 and SpO2>50) { average_beat = filterweight \* (beat) + (1 - filterweight ) \* average_beat; average_SpO2 = filterweight \* (SpO2) + (1 - filterweight ) \* average_SpO2; readIndex++; display\_calculating(readIndex); } }
void setup() { Serial.begin(115200); u8g2.begin(); pox.begin(); pox.setOnBeatDetectedCallback(onBeatDetected); initial\_display(); }
void loop() { pox.update(); if ((millis() - tsLastReport > REPORTING_PERIOD_MS) and (not calculation_complete)) { calculate\_average(pox.getHeartRate(),pox.getSpO2()); tsLastReport = millis(); } if ((millis()-last_beat>5000)) { calculation_complete=false; average_beat=0; average_SpO2=0; initial\_display(); } }
|
郑重声明:本文演示的实例只能用于实验原理演示,不能用于医用目的。不对任何用于医用效果负责!!!
文章来源: https://iotsmart.blog.csdn.net/article/details/128077562
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!