|
在本篇文章中,我们使用Arduino开发板和脉搏传感器(Pulse Sensor)设计了一款心跳/脉搏/BPM速率监视器。脉搏传感器连接到Arduino开发板以监控心跳/脉搏/BPM速率,然后将结果显示在20 * 4 LCD显示屏上。您也可以使用1602或其他形式的LCD显示屏。
该传感器非常易于使用和操作。将手指放在传感器上方,它将通过测量毛细血管扩张引起的光变化来感应心跳。
脉搏传感器简介
脉搏传感器(Pulse Sensor)是一款适用于Arduino的即插即用心率传感器。想要将实时心率数据轻松整合到他们的项目中的学生、运动员、制造商以及游戏和移动开发人员都可以使用它,其本质是集成的光放大电路和降噪电路传感器。将脉搏传感器夹到您的耳垂或指尖,然后将其插入Arduino,即可随时读取心率。它还具有一个易于使用的Arduino演示代码。
脉搏传感器有三个引脚:VCC、GND和模拟引脚。
该传感器模块的中心还有一个LED,可帮助检测心跳。在LED下方,有一个消除噪音的电路,该电路应能防止噪音影响读数。
心跳/脉搏/BPM速率监视器的电路连接图: 下面给出了将脉搏传感器与Arduino和LCD连接的电路图。只需按如下所示进行连接并上传代码。
项目工作过程: 当心跳时,血液被运送通过人体,并被挤入毛细血管组织中。因此,这些毛细组织的体积增加。但是,在两次相应的心跳之间,毛细血管组织内部的体积减小了。心跳之间体积的这种变化会影响将通过这些组织传输的光量。这可以在微控制器的帮助下进行测量。
脉搏传感器模块带有一个有助于测量脉搏频率的灯。当我们将手指放在脉搏传感器上时,反射的光将根据毛细管血管内的血液量而变化。可以从脉搏传感器的输出中获取脉搏形式的光透射和反射变化。然后可以调节此脉搏以测量心跳,然后使用Arduino对其进行相应编程以读取为心跳计数。
源代码: 下面给出了使用Arduino和脉搏传感器的心跳/脉搏/BPM速率监视器的源代码。按照电路图中的上方所示组装电路,然后在下面上传此代码。首先,您需要添加Pulse Sensor库文件。从这里下载库。然后只需上传此代码。 - #define USE_ARDUINO_INTERRUPTS true // Set-up low-level interrupts for most acurate BPM math.
- #include <PulseSensorPlayground.h> // Includes the PulseSensorPlayground Library.
- #include<LiquidCrystal.h>
- LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
- // Variables
- const int PulseWire = 0; // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
- const int LED13 = 13; // The on-board Arduino LED, close to PIN 13.
- int Threshold = 550; // Determine which Signal to "count as a beat" and which to ignore.
- // Use the "Gettting Started Project" to fine-tune Threshold Value beyond default setting.
- // Otherwise leave the default "550" value.
- PulseSensorPlayground pulseSensor; // Creates an instance of the PulseSensorPlayground object called "pulseSensor"
- void setup() {
- Serial.begin(9600); // For Serial Monitor
- lcd.begin(20,4);
- // Configure the PulseSensor object, by assigning our variables to it.
- pulseSensor.analogInput(PulseWire);
- pulseSensor.blinkOnPulse(LED13); //auto-magically blink Arduino's LED with heartbeat.
- pulseSensor.setThreshold(Threshold);
- // Double-check the "pulseSensor" object was created and "began" seeing a signal.
- if (pulseSensor.begin()) {
- Serial.println("We created a pulseSensor Object !"); //This prints one time at Arduino power-up, or on Arduino reset.
- lcd.setCursor(0,0);
- lcd.print(" Heart Rate Monitor");
- }
- }
- void loop() {
- int myBPM = pulseSensor.getBeatsPerMinute(); // Calls function on our pulseSensor object that returns BPM as an "int".
- // "myBPM" hold this BPM value now.
- if (pulseSensor.sawStartOfBeat()) { // Constantly test to see if "a beat happened".
- Serial.println("♥ A HeartBeat Happened ! "); // If test is "true", print a message "a heartbeat happened".
- Serial.print("BPM: "); // Print phrase "BPM: "
- Serial.println(myBPM); // Print the value inside of myBPM.
- lcd.setCursor(0,2);
- lcd.print("HeartBeat Happened !"); // If test is "true", print a message "a heartbeat happened".
- lcd.setCursor(5,3);
- lcd.print("BPM: "); // Print phrase "BPM: "
- lcd.print(myBPM);
- }
- delay(20); // considered best practice in a simple sketch.
- }
复制代码
|