Advertisement
pleasedontcode

PulseOximeter Readings rev_01

Jun 21st, 2025
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: PulseOximeter Readings
  13.     - Source Code NOT compiled for: Arduino Nano 33 BLE
  14.     - Source Code created on: 2025-06-21 10:04:52
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Develop a user requirement specifying the */
  21.     /* integration of the MAX30100 Pulse Oximeter sensor */
  22.     /* with the Arduino Nano 33 BLE to measure heart rate */
  23.     /* and SpO2 levels, ensuring proper library usage and */
  24.     /* sensor initialization. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <MAX30100_PulseOximeter.h> //https://github.com/gabriel-milan/Arduino-MAX30100
  31. #include <Wire.h> // Included for compatibility, though MAX30100_PulseOximeter.h may include it already
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. PulseOximeter pox;
  39.  
  40. uint32_t tsLastReport = 0;
  41. const uint32_t REPORTING_PERIOD_MS = 1000; // Reporting interval in milliseconds
  42.  
  43. // Callback (registered below) fired when a pulse is detected
  44. void onBeatDetected()
  45. {
  46.     Serial.println("Beat!");
  47. }
  48.  
  49. void setup()
  50. {
  51.     Serial.begin(115200);
  52.  
  53.     Serial.print("Initializing pulse oximeter..");
  54.  
  55.     // Initialize the PulseOximeter instance
  56.     // Failures are generally due to an improper I2C wiring, missing power supply
  57.     // or wrong target chip
  58.     if (!pox.begin()) {
  59.         Serial.println("FAILED");
  60.         for(;;);
  61.     } else {
  62.         Serial.println("SUCCESS");
  63.     }
  64.  
  65.     // The default current for the IR LED is 50mA and it could be changed
  66.     //   by uncommenting the following line. Check MAX30100_Registers.h for all the
  67.     //   available options.
  68.     // pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
  69.  
  70.     // Register a callback for the beat detection
  71.     pox.setOnBeatDetectedCallback(onBeatDetected);
  72. }
  73.  
  74. void loop()
  75. {
  76.     // Make sure to call update as fast as possible
  77.     pox.update();
  78.  
  79.     // Asynchronously dump heart rate and oxidation levels to the serial
  80.     // For both, a value of 0 means "invalid"
  81.     if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
  82.         Serial.print("Heart rate:");
  83.         Serial.print(pox.getHeartRate());
  84.         Serial.print(" bpm / SpO2:");
  85.         Serial.print(pox.getSpO2());
  86.         Serial.println("%");
  87.  
  88.         tsLastReport = millis();
  89.     }
  90. }
  91.  
  92. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement