Arduino

XD-58C 펄스심박센서 문자 LCD에 심박수 표시

작성자 임베디드코리아 작성일26-06-20 21:44 조회18회 댓글0건
<* XD-58C 펄스심박센서 문자 LCD에 심박수 표시 *>
▶ XD-58C 펄스심박센서의  값을 문자 LCD에 심박수 표시한다.
▶ 적외선을 통해 모세혈관의 수축 팽창 활동을 측정하여 심박수를 나타낸다.

< 1 >  I2C  문자 LCD
      ▶ 문자 LCD는 I2C 모듈을 결합하여 사용한다.
      ▶ 라이브러리는  ​LIQUIDCRYSTAL I2C 를 설치해야한다.
            "스케치 → 라이브러리 포함하기 → 라이브러리 관리"
              --> 라이브러리 매니저--> " ​LIQUIDCRYSTAL I2C"를 검색하고  라이브러리를 추가한다.

< 2 > PulseSensorPlayground 라이브러리 설치
          "스케치 → 라이브러리 포함하기 → 라이브러리 관리"
              --> 라이브러리 매니저--> " ​PULSESENSOR"를 검색하고  라이브러리를 추가한다.

---<  XD-58C_Pulse-Sensor_Char-LCD.ino  >------------------------------------------------------------
#define USE_ARDUINO_INTERRUPTS true  //Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h>      // Includes the PulseSensorPlayground Library.
#include <LiquidCrystal_I2C.h>    //LCD
#include <Wire.h>    //LCD

// 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.

LiquidCrystal_I2C lcd(0x27, 16, 2);      //LCD
PulseSensorPlayground pulseSensor;    // Creates an instance of the PulseSensorPlayground object called "pulseSensor"

void setup() {
    Serial.begin(9600);
    // 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.init(); // LCD
    lcd.backlight(); // LCD
}

void loop() {
    lcd.init(); //LCD
    int myBPM = pulseSensor.getBeatsPerMinute(); // Calls function on our pulseSensor object that returns BPM as an "int".
 
    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,0);
      lcd.print("BPM: ");
      lcd.print(myBPM);
  }
  delay(20); // considered best practice in a simple sketch.
}
------------------------------------------------------------------------------------------------