[아두이노] Max30102 센서를 LCD로 출력해보기

안녕하세요 대짜이찐입니다.

이전 포스팅중에 MAX30102 센서를 통해

산소포화도와 심박측정을 해본적 있습니다.


이번에는 이 MAX30102센서 모듈을 사용한 

심박측정을 LCD로 출력해보겠습니다.


우선 회로도 입니다.

Max30102 모듈과 Ic2 LCD모듈 둘 다 통신을 IC2 통신을 하기 때문에

같이 병렬로 묶어서 아두이노의 A4(SDA), A5(SCL)로 연결해줍니다.

I2C통신이기 때문에, I2C 주소값이 다르다면 각각 통신이 가능합니다.

그리고 아두이노의 5V출력핀과 GND를 각각 Max30102모듈과 LCD에 연결해줍니다.


 라이브러리는 제가 이전 포스팅에서도 사용했었던 I2C LCD 라이브러리와
스파크펀의 Max3010x시리즈 라이브러리를 사용해줍니다.
Max3010x 라이브러리는 아두이노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

 

#include <Wire.h>

#include "MAX30105.h"

#include <LiquidCrystal_I2C.h>

#include "heartRate.h"

 

 

LiquidCrystal_I2C lcd(0x27, 16, 2);

 

MAX30105 particleSensor;

 

const byte RATE_SIZE = 4;

byte rates[RATE_SIZE];

byte rateSpot = 0;

long lastBeat = 0;

 

float beatsPerMinute;

int beatAvg;

 

void setup()

{

  lcd.begin();

  lcd.backlight();

  Serial.begin(115200);

  Serial.println("Initializing...");

 

  

  if (!particleSensor.begin(Wire, I2C_SPEED_FAST))

  {

    Serial.println("MAX30105 was not found. Please check wiring/power. ");

    while (1);

  }

  Serial.println("Place your index finger on the sensor with steady pressure.");

 

  particleSensor.setup();

  particleSensor.setPulseAmplitudeRed(0x0A);

  particleSensor.setPulseAmplitudeGreen(0);

}

 

void loop()

{

  long irValue = particleSensor.getIR();

 

  if (checkForBeat(irValue) == true)

  {

    

    long delta = millis() - lastBeat;

    lastBeat = millis();

 

    beatsPerMinute = 60 / (delta / 1000.0);

 

    if (beatsPerMinute < 255 && beatsPerMinute > 20)

    {

      rates[rateSpot++] = (byte)beatsPerMinute;

      rateSpot %= RATE_SIZE;

 

   

      beatAvg = 0;

      for (byte x = 0 ; x < RATE_SIZE ; x++)

        beatAvg += rates[x];

      beatAvg /= RATE_SIZE;

    }

  }

 

  if (irValue < 50000)

  {

    Serial.print(" No finger?");

    lcd.clear();

    lcd.setCursor(0,0);

    lcd.print("No");

    lcd.setCursor(0,1);

    lcd.print("Finger");

    delay(150);

  }

 

  else

  {

  Serial.print("IR=");

  Serial.print(irValue);

  Serial.print(", BPM=");

  Serial.print(beatsPerMinute);

  Serial.print(", Avg BPM=");

  Serial.print(beatAvg);

  

  lcd.setCursor(0,0);

  lcd.print("BPM: ");

  lcd.print(beatAvg);

  lcd.setCursor(0,1);

  lcd.print("IR: ");

  lcd.print(irValue);

  }

  

  Serial.println();

}

 

Colored by Color Scripter

cs

소스 코드는 max3010x라이브러리에 있는 HeartRate 예제를 참고해서 

LCD기능만 추가했습니다.

본 포스팅에 사용된 제품은 디바이스마트에서 구매하실 수 있습니다.



감사합니다.



댓글 쓰기

2 댓글

  1. lcd에 불은 들어오나 어떠한 문자도 표기되지 않습니다

    답글삭제
    답글
    1. lcd 뒤쪽에 가변저항을 돌려서 문자가 나오는지 확인해보시길 바랍니다.

      삭제