疫情期间,指夹式血氧检测仪全网脱销,好不容易在某多多上买到一个,发现检测值很不靠谱,于是尝试DIY了一个。
将MAX30102心率血氧传感器采样信息输入到Arduino Pro Mini单片机,把经计算后的心率、血氧数据显示到LCD1602显示屏。
MAX30102心率血氧传感器


Arduino Pro Mini单片机

LCD1602显示屏


USB转TTL-CH340模块


GitHub血氧心率检测开源项目
GitHub - sparkfun/MAX30105_Particle_Sensor_Breakout: Breakout to sense smoke, SpO2, Pulse Detection, as well as airborne particles.
3.安装完成后,点击“确定”。
4.在“我的电脑”--->“设备管理器”查看COM端口选项(记住这个COM口号,烧写程序时需选择该COM口)。
下载地址:ch340驱动下载_ch340驱动官方下载【绿色版】-华军软件园
从GitHub下载开源软件,并解压缩。

GitHub血氧心率检测开源项目
GitHub - sparkfun/MAX30105_Particle_Sensor_Breakout: Breakout to sense smoke, SpO2, Pulse Detection, as well as airborne particles.
Arduino Pro Mini
CH340
RX
TX
TX
RX
GND
GND
VCC
5V或3.3V(由Arduino Pro Mini具体型号确定)
注意:如果你的USB转TTL模块有DTR引脚,将板子的DTR连接到USB转TTL模块上的DTR引脚,这样烧录时就不需要按Reset按钮。
启动Arduino IDE,选择之前CH340安装的端口号,将“开发板”型号设置为“Arduino Pro or Pro Mini”。


由于开源项目仅通过串口监测查看检测结果,因此需添加LCD显示输出代码,修改如下:
#include <Wire.h>
#include "MAX30105.h"
#include "spo2_algorithm.h"
#include <LiquidCrystal.h> //LCD
MAX30105 particleSensor;
#define MAX_BRIGHTNESS 255
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
//Arduino Uno doesn't have enough SRAM to store 100 samples of IR led data and red led data in 32-bit format
//To solve this problem, 16-bit MSB of the sampled data will be truncated. Samples become 16-bit data.
uint16_t irBuffer[100]; //infrared LED sensor data
uint16_t redBuffer[100]; //red LED sensor data
#else
uint32_t irBuffer[100]; //infrared LED sensor data
uint32_t redBuffer[100]; //red LED sensor data
#endif
int32_t bufferLength; //data length
int32_t spo2; //SPO2 value
int8_t validSPO2; //indicator to show if the SPO2 calculation is valid
int32_t heartRate; //heart rate value
int8_t validHeartRate; //indicator to show if the heart rate calculation is valid
//byte pulseLED = 11; //Must be on PWM pin
byte readLED = 13; //Blinks with each data read
LiquidCrystal lcd(12,11,5,4,3,2);//init LCD
void setup()
//Serial.println(F("Attach sensor to finger with rubber band. Press any key to start conversion"));
//while (Serial.available() == 0) ; //wait until user presses a key
Serial.read();
byte ledBrightness = 60; //Options: 0=Off to 255=50mA
byte sampleAverage = 4; //Options: 1, 2, 4, 8, 16, 32
byte ledMode = 2; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green
byte sampleRate = 100; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
int pulseWidth = 411; //Options: 69, 118, 215, 411
int adcRange = 4096; //Options: 2048, 4096, 8192, 16384
particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings
}
void loop()
//calculate heart rate and SpO2 after first 100 samples (first 4 seconds of samples)
maxim_heart_rate_and_oxygen_saturation(irBuffer, bufferLength, redBuffer, &spo2, &validSPO2, &heartRate, &validHeartRate);
//Continuously taking samples from MAX30102. Heart rate and SpO2 are calculated every 1 second
while (1)
//take 25 sets of samples before calculating the heart rate.
for (byte i = 75; i < 100; i++)
//After gathering 25 new samples recalculate HR and SP02
maxim_heart_rate_and_oxygen_saturation(irBuffer, bufferLength, redBuffer, &spo2, &validSPO2, &heartRate, &validHeartRate);
}
}
程序编译没有问题的话,就可以开始上传,但要注意,如USB转TTL模块没有DTR引脚,需要你在IDE开始上传的一瞬间(差不多就行)按下板子上的Reset按钮,这样才能上传成功。

根据LCD1602的引脚定义如上图,和Arduino Pro mini的连接方法如下:
LCD VSS 接地
LCD VDD 接5V电源
LCD VL 用于调节对比度,通过电位器再接地。
LCD RS pin 链接数字口 pin12
LCD R/W pin 接地
LCD Enable pin 链接数字口 pin11
LCD D4 pin 链接数字口 pin5
LCD D5 pin 链接数字口 pin4
LCD D6 pin 链接数字口 pin3
LCD D7 pin 链接数字口 pin2
LCD BLA 光源正极
LCD BLK 光源负极
MAX30102和Arduino Pro mini的连接方法如下:
MAX30102
Arduino Pro mini
GND
GND
SCL
A5
SDA
A4
VIN
5V电源

