Advertisement
safwan092

Untitled

Oct 22nd, 2023
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #include <Wire.h>
  2. #include "MAX30100_PulseOximeter.h"
  3. #include <LiquidCrystal_I2C.h>
  4. #define REPORTING_PERIOD_MS 1000
  5. LiquidCrystal_I2C lcd(0x27, 16, 2);
  6.  
  7. PulseOximeter pox;
  8.  
  9. uint32_t tsLastReport = 0;
  10. int Buzzer = 4;
  11. int LED = 18 ;
  12.  
  13. void onBeatDetected()
  14. {
  15. Serial.println("Beat!");
  16. }
  17.  
  18. void setup()
  19. {
  20. lcd.init();
  21. lcd.backlight();
  22. Serial.begin(115200);
  23. Wire.begin();
  24. pinMode(Buzzer, OUTPUT);
  25. pinMode(LED, OUTPUT);
  26. Serial.print("Initializing pulse oximeter..");
  27.  
  28. if (!pox.begin()) {
  29. Serial.println("FAILED");
  30. for (;;);
  31. } else {
  32. Serial.println("SUCCESS");
  33. }
  34.  
  35. pox.setOnBeatDetectedCallback(onBeatDetected);
  36. }
  37.  
  38. void loop()
  39. {
  40. pox.update();
  41. if (millis() - tsLastReport > REPORTING_PERIOD_MS)
  42. {
  43. int hR = pox.getHeartRate();
  44. int oR = pox.getSpO2();
  45. Serial.print("Heart rate:");
  46. Serial.print(hR);
  47. Serial.print("bpm / O2:");
  48. Serial.print(oR);
  49. Serial.println("%");
  50. lcd.setCursor(0, 0); // positionner le cursor a 0,0
  51. lcd.print("Heart rate:"); // Printe "Distance" sur LCD
  52. lcd.print(hR);
  53. lcd.setCursor(0, 1); // positionner le cursor a 0,0
  54. lcd.print("O2:"); // Printe "Distance" sur LCD
  55. lcd.print(oR);
  56. if (pox.getSpO2() == 0)
  57. {
  58. digitalWrite(Buzzer, LOW);
  59. digitalWrite(LED, LOW);
  60. }
  61. else if (pox.getSpO2() >= 95)
  62. {
  63. digitalWrite(Buzzer, LOW);
  64. digitalWrite(LED, LOW);
  65.  
  66. }
  67. else if (pox.getSpO2() < 95 && pox.getSpO2() > 0)
  68. {
  69. digitalWrite(Buzzer, HIGH);
  70. digitalWrite(LED, HIGH);
  71.  
  72.  
  73. } tsLastReport = millis();
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement