Advertisement
pleasedontcode

"Health Monitor" rev_01

Jun 13th, 2025
315
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: "Health Monitor"
  13.     - Source Code NOT compiled for: Arduino Nano
  14.     - Source Code created on: 2025-06-13 19:17:54
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* using max30102 ,oled display 128x64 ,analog */
  21.     /* vibration sensor ,write a code so that oled shows */
  22.     /* vibration reading ,heart beats and oxygen all */
  23.     /* together in the oled */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <Wire.h>
  30. #include <Adafruit_SSD1306.h>   // OLED display library
  31. #include <U8g2_for_Adafruit_GFX.h>  // U8g2 fonts for Adafruit GFX
  32. #include <MAX30105.h> // MAX30102 library for heart rate and SpO2
  33. #include <Arduino.h> // Arduino core library
  34.  
  35. /****** FUNCTION PROTOTYPES *****/
  36. void setup(void);
  37. void loop(void);
  38. void displayReadings(float heartRate, float spo2, int vibration);
  39.  
  40. /***** DEFINITION OF I2C PINS *****/
  41. const uint8_t myDisplay_SSD1306OledDisplay_I2C_PIN_SDA_A4       = A4;
  42. const uint8_t myDisplay_SSD1306OledDisplay_I2C_PIN_SCL_A5       = A5;
  43. const uint8_t myDisplay_SSD1306OledDisplay_I2C_SLAVE_ADDRESS        = 60;
  44.  
  45. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  46. Adafruit_SSD1306 display(128, 64, &Wire, -1); // Create display object
  47. MAX30105 particleSensor; // Create MAX30102 object
  48.  
  49. void setup(void)
  50. {
  51.     // Initialize the OLED display
  52.     display.begin(SSD1306_SWITCHCAPVCC, myDisplay_SSD1306OledDisplay_I2C_SLAVE_ADDRESS);
  53.     display.clearDisplay();
  54.     display.setTextSize(1);
  55.     display.setTextColor(WHITE);
  56.     display.setCursor(0, 0);
  57.     display.println("Initializing...");
  58.  
  59.     // Initialize the MAX30102 sensor
  60.     if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) {
  61.         display.println("MAX30102 not found!");
  62.         display.display();
  63.         while (1);
  64.     }
  65.  
  66.     // Set the sensor to read heart rate and SpO2
  67.     particleSensor.setup(); // Configure sensor settings
  68. }
  69.  
  70. void loop(void)
  71. {
  72.     // Read heart rate and SpO2
  73.     float heartRate = particleSensor.getHeartRate();
  74.     float spo2 = particleSensor.getSpO2();
  75.  
  76.     // Read vibration sensor (assuming it's connected to A0)
  77.     int vibration = analogRead(A0);
  78.  
  79.     // Display the readings on the OLED
  80.     displayReadings(heartRate, spo2, vibration);
  81.     delay(1000); // Update every second
  82. }
  83.  
  84. void displayReadings(float heartRate, float spo2, int vibration) {
  85.     display.clearDisplay();
  86.     display.setCursor(0, 0);
  87.     display.print("Heart Rate: ");
  88.     display.print(heartRate);
  89.     display.println(" bpm");
  90.  
  91.     display.print("SpO2: ");
  92.     display.print(spo2);
  93.     display.println(" %");
  94.  
  95.     display.print("Vibration: ");
  96.     display.print(vibration);
  97.     display.println(" ADC");
  98.  
  99.     display.display(); // Refresh the display
  100. }
  101.  
  102. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement