Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: "Sensor Display"
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-06-10 18:02:39
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Develop a heart rate and SpO2 monitoring system */
- /* using the MAX30100 sensor. The system should */
- /* initialize the sensor, read data continuously, and */
- /* display the results on a I2C oled display */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <MAX30100_PulseOximeter.h> // https://github.com/gabriel-milan/Arduino-MAX30100
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t SENSOR_MAX30100_INT_PIN_D2 = 2;
- /***** DEFINITION OF I2C PINS *****/
- const uint8_t SENSOR_MAX30100_I2C_PIN_SDA_A4 = A4;
- const uint8_t SENSOR_MAX30100_I2C_PIN_SCL_A5 = A5;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- PulseOximeter pox; // Create an instance of the PulseOximeter class
- Adafruit_SSD1306 display(128, 64, &Wire); // Create an instance of the OLED display class
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(SENSOR_MAX30100_INT_PIN_D2, INPUT_PULLUP);
- Serial.begin(115200);
- // Initialize the PulseOximeter
- if (!pox.begin()) {
- Serial.println("FAILED: Unable to initialize the PulseOximeter");
- for (;;); // Halt the program
- } else {
- Serial.println("PulseOximeter initialized successfully");
- }
- // Set the IR LED current
- pox.setIRLedCurrent(MAX30100_LED_CURR_50MA);
- // Initialize the OLED display
- if (!display.begin(SSD1306_I2C_ADDRESS, SENSOR_MAX30100_I2C_PIN_SDA_A4, SENSOR_MAX30100_I2C_PIN_SCL_A5)) {
- Serial.println("SSD1306 allocation failed");
- for (;;); // Halt the program
- }
- display.display();
- delay(2000); // Pause for 2 seconds
- // Clear the buffer
- display.clearDisplay();
- display.setTextSize(1);
- display.setTextColor(SSD1306_WHITE);
- display.setCursor(0, 0);
- display.print("PulseOximeter initialized");
- display.display();
- delay(2000); // Pause for 2 seconds
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- pox.update();
- // Get the heart rate and SpO2 values
- float heartRate = pox.getHeartRate();
- uint8_t spO2 = pox.getSpO2();
- // Print the heart rate and SpO2 values to the Serial Monitor
- Serial.print("Heart rate: ");
- Serial.print(heartRate);
- Serial.print(" bpm / SpO2: ");
- Serial.print(spO2);
- Serial.println(" %");
- // Display the heart rate and SpO2 values on the OLED display
- display.clearDisplay();
- display.setCursor(0, 0);
- display.print("Heart rate: ");
- display.print(heartRate);
- display.print(" bpm");
- display.setCursor(0, 16);
- display.print("SpO2: ");
- display.print(spO2);
- display.print(" %");
- display.display();
- delay(1000); // Wait for 1 second before the next update
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement