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: "Health Monitor"
- - Source Code NOT compiled for: Arduino Nano
- - Source Code created on: 2025-06-13 19:17:54
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* using max30102 ,oled display 128x64 ,analog */
- /* vibration sensor ,write a code so that oled shows */
- /* vibration reading ,heart beats and oxygen all */
- /* together in the oled */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <Adafruit_SSD1306.h> // OLED display library
- #include <U8g2_for_Adafruit_GFX.h> // U8g2 fonts for Adafruit GFX
- #include <MAX30105.h> // MAX30102 library for heart rate and SpO2
- #include <Arduino.h> // Arduino core library
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void displayReadings(float heartRate, float spo2, int vibration);
- /***** DEFINITION OF I2C PINS *****/
- const uint8_t myDisplay_SSD1306OledDisplay_I2C_PIN_SDA_A4 = A4;
- const uint8_t myDisplay_SSD1306OledDisplay_I2C_PIN_SCL_A5 = A5;
- const uint8_t myDisplay_SSD1306OledDisplay_I2C_SLAVE_ADDRESS = 60;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- Adafruit_SSD1306 display(128, 64, &Wire, -1); // Create display object
- MAX30105 particleSensor; // Create MAX30102 object
- void setup(void)
- {
- // Initialize the OLED display
- display.begin(SSD1306_SWITCHCAPVCC, myDisplay_SSD1306OledDisplay_I2C_SLAVE_ADDRESS);
- display.clearDisplay();
- display.setTextSize(1);
- display.setTextColor(WHITE);
- display.setCursor(0, 0);
- display.println("Initializing...");
- // Initialize the MAX30102 sensor
- if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) {
- display.println("MAX30102 not found!");
- display.display();
- while (1);
- }
- // Set the sensor to read heart rate and SpO2
- particleSensor.setup(); // Configure sensor settings
- }
- void loop(void)
- {
- // Read heart rate and SpO2
- float heartRate = particleSensor.getHeartRate();
- float spo2 = particleSensor.getSpO2();
- // Read vibration sensor (assuming it's connected to A0)
- int vibration = analogRead(A0);
- // Display the readings on the OLED
- displayReadings(heartRate, spo2, vibration);
- delay(1000); // Update every second
- }
- void displayReadings(float heartRate, float spo2, int vibration) {
- display.clearDisplay();
- display.setCursor(0, 0);
- display.print("Heart Rate: ");
- display.print(heartRate);
- display.println(" bpm");
- display.print("SpO2: ");
- display.print(spo2);
- display.println(" %");
- display.print("Vibration: ");
- display.print(vibration);
- display.println(" ADC");
- display.display(); // Refresh the display
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement