Advertisement
pleasedontcode

Sensor Monitoring rev_02

Jun 21st, 2025
328
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: Sensor Monitoring
  13.     - Source Code NOT compiled for: Arduino Nano 33 BLE
  14.     - Source Code created on: 2025-06-21 10:14:43
  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.  
  28. /********* User code review feedback **********
  29. #### Feedback 1 ####
  30. - it did not work
  31. ********* User code review feedback **********/
  32.  
  33. /* START CODE */
  34.  
  35. #include <MAX30100_PulseOximeter.h> // Library for MAX30100 pulse oximeter sensor
  36. #include <Wire.h> // Included for compatibility, though MAX30100_PulseOximeter.h may include it already
  37.  
  38. // Instantiate the PulseOximeter object
  39. PulseOximeter pox;
  40.  
  41. uint32_t tsLastReport = 0;
  42. const uint32_t REPORTING_PERIOD_MS = 1000; // Reporting interval in milliseconds
  43.  
  44. // Callback (registered below) fired when a pulse is detected
  45. void onBeatDetected()
  46. {
  47.     Serial.println("Beat!");
  48. }
  49.  
  50. void setup()
  51. {
  52.     Serial.begin(115200);
  53.  
  54.     Serial.print("Initializing pulse oximeter..");
  55.  
  56.     // Initialize the PulseOximeter instance
  57.     // Failures are generally due to an improper I2C wiring, missing power supply
  58.     // or wrong target chip
  59.     if (!pox.begin()) {
  60.         Serial.println("FAILED");
  61.         for(;;);
  62.     } else {
  63.         Serial.println("SUCCESS");
  64.     }
  65.  
  66.     // The default current for the IR LED is 50mA and it could be changed
  67.     //   by uncommenting the following line. Check MAX30100_Registers.h for all the
  68.     //   available options.
  69.     // pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
  70.  
  71.     // Register a callback for the beat detection
  72.     pox.setOnBeatDetectedCallback(onBeatDetected);
  73. }
  74.  
  75. void loop()
  76. {
  77.     // Make sure to call update as fast as possible
  78.     pox.update();
  79.  
  80.     // Asynchronously dump heart rate and oxidation levels to the serial
  81.     // For both, a value of 0 means "invalid"
  82.     if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
  83.         Serial.print("Heart rate:");
  84.         Serial.print(pox.getHeartRate());
  85.         Serial.print(" bpm / SpO2:");
  86.         Serial.print(pox.getSpO2());
  87.         Serial.println("%");
  88.  
  89.         tsLastReport = millis();
  90.     }
  91. }
  92.  
  93. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement