33

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

ANNEXE 2: MAX30102 ARDUINO

1. #include <Wire.h>
2. #include "MAX30105.h"
3.
4. #include "heartRate.h"
5.
6. MAX30105 particleSensor;
7.
8. const byte RATE_SIZE = 4; //Increase this for more averaging. 4 is good.
9. byte rates[RATE_SIZE]; //Array of heart rates
10. byte rateSpot = 0;
11. long lastBeat = 0; //Time at which the last beat
occurred 12.
13. float beatsPerMinute;
14. int beatAvg;
15.
16. void setup()
17. {
18. Serial.begin(115200);
19. Serial.println("Initializing...");
20.
21. // Initialize sensor
22. if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed
23. {
24. Serial.println("MAX30105 was not found. Please check wiring/power. ");
25. while (1);
26. }
27. Serial.println("Place your index finger on the sensor with steady pressure.");
28.
29. particleSensor.setup(); //Configure sensor with default settings
30. particleSensor.setPulseAmplitudeRed(0x0A); //Turn Red LED to low to indicate sensor is
running
31. particleSensor.setPulseAmplitudeGreen(0); //Turn off Green LED
32. }
33.
34. void loop()
35. {
36. long irValue = particleSensor.getIR();
37.
38. if (checkForBeat(irValue) == true)
39. {
40. //We sensed a beat!
41. long delta = millis() - lastBeat;
42. lastBeat = millis();
43.
44. beatsPerMinute = 60 / (delta / 1000.0);
45.
46. if (beatsPerMinute < 255 && beatsPerMinute > 20)
47. {
48. rates[rateSpot++] = (byte)beatsPerMinute; //Store this reading in the array
49. rateSpot %= RATE_SIZE; //Wrap variable
50.
51. //Take average of readings
52. beatAvg = 0;
53. for (byte x = 0 ; x < RATE_SIZE ; x++)
54. beatAvg += rates[x];
55. beatAvg /= RATE_SIZE;
56. }
57. }
58.
59. Serial.print("IR=");
60. Serial.print(irValue);
61. Serial.print(", BPM=");
62. Serial.print(beatsPerMinute);
63. Serial.print(", Avg BPM=");
64. Serial.print(beatAvg);
65.
66. if (irValue < 50000)
67. Serial.print(" No finger?");
68.
69. Serial.println();
70. }
71.

You might also like