Advertisement
safwan092

Untitled

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