[Diao Ye learns programming] Arduino hands-on (100)---MAX30102 wrist heart rate module 3

The reference to 37 sensors and actuators has been widely circulated on the Internet. In fact, there must be more than 37 sensor modules compatible with Arduino. In view of the fact that I have accumulated some sensor and actuator modules on hand, according to the concept of true knowledge (must be done by hand), for the purpose of learning and communication, I am going to try a series of experiments one by one here, and will record them whether they are successful (the program goes through) or not.

[Arduino] 168 sensor module series experiments (data code + simulation programming + graphic programming)
experiment 100: MAX30102 oximeter wrist heart rate pulse detection heartbeat sensor module

insert image description here
insert image description here

Program 2: LED lights that light up synchronously with the heartbeat
Experiment open source graphics programming (Mind+, learning while editing)

insert image description here

Experimental serial port return

insert image description here
Arduino experiment scene diagram

insert image description here


Program 3: Arduino reference open source code for sensing the presence of Arduino through infrared readings

/*
  【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  程序三:通过红外读数感知存在
*/

#include <Wire.h>
#include "MAX30105.h"

MAX30105 particleSensor;

long samplesTaken = 0; //用于计算 Hz 或读取速率的计数器
long unblockedValue; //通电时的平均 IR
long startTime; //用于计算测量率

void setup() {
    
    
  Serial.begin(9600);
  Serial.println("MAX30105 存在感测示例");

  //初始化传感器
  if (particleSensor.begin(Wire, I2C_SPEED_FAST) == false) //使用默认 I2C 端口,400kHz 速度
  {
    
    
    Serial.println("没有找到MAX30105,请检查接线/电源。 ");
    while (1);
  }

  //设置感应最大 18 英寸,最大 LED 亮度
  byte ledBrightness = 0xFF; //选项:0=关到 255=50mA
  byte sampleAverage = 4; //样本平均值选项:1、2、4、8、16、32
  byte ledMode = 2;  //工作选项:1 = 仅红色,2 = 红色 + IR,3 = 红色 + IR + 绿色
  int sampleRate = 400; //采样率选项:50、100、200、400、800、1000、1600、3200
  int pulseWidth = 411; //脉宽选项:69、118、215、411
  int adcRange = 2048; //选项:2048、4096、8192、16384

  //使用这些设置来配置传感器
  particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange);

  particleSensor.setPulseAmplitudeRed(0); //关闭红色 LED
  particleSensor.setPulseAmplitudeGreen(0); //关闭绿色 LED

  //上电时取平均 IR 读数
  unblockedValue = 0;
  for (byte x = 0 ; x < 32 ; x++)
  {
    
    
    unblockedValue += particleSensor.getIR(); //读取 IR 值
  }
  unblockedValue /= 32;

  startTime = millis();
}

void loop() {
    
    
  samplesTaken++;

  Serial.print("IR[");
  Serial.print(particleSensor.getIR());
  Serial.print("] 赫兹[");
  Serial.print((float)samplesTaken / ((millis() - startTime) / 1000.0), 2);
  Serial.print("]");

  long currentDelta = particleSensor.getIR() - unblockedValue;

  Serial.print(" 增量[");
  Serial.print(currentDelta);
  Serial.print("]");

  if (currentDelta > (long)100)
  {
    
    
    Serial.print("开始测量!");
  }

  Serial.println();
  delay(1000);
}

Experimental serial port return

insert image description here

Program 4: Read the onboard temperature sensor
Arduino reference open source code

/*
  【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  程序四:读取板载温度传感器
  下载库: http://librarymanager/All#SparkFun_MAX30105
*/

#include <Wire.h>

#include "MAX30105.h"
MAX30105 particleSensor;

void setup() {
    
    
  Serial.begin(9600);
  Serial.println("正在初始化...");

  // 初始化传感器
  if (particleSensor.begin(Wire, I2C_SPEED_FAST) == false) //使用默认 I2C 端口,400kHz 速度
  {
    
    
    Serial.println("没有找到MAX30105,请检查接线/电源。");
    while (1);
  }

  //LED 的功率非常低,不会对温度读数产生太大影响,但是
  //您可能想要关闭 LED 以避免任何局部加热
  particleSensor.setup(0); //配置传感器。关闭 LED
  //particleSensor.setup(); //配置传感器。使用 25mA 驱动 LED

  particleSensor.enableDIETEMPRDY(); //启用临时就绪中断,这是必需的。
}

void loop() {
    
    
  float temperature = particleSensor.readTemperature();

  Serial.print("摄氏温度=");
  Serial.print(temperature, 4);

  float temperatureF = particleSensor.readTemperatureF();
  Serial.print(" 华氏温度=");
  Serial.println(temperatureF, 4);

  Serial.println();
  delay(1000);

}

Experimental serial port return

insert image description here

Guess you like

Origin blog.csdn.net/weixin_41659040/article/details/131875766