Advertisement
pleasedontcode

**Health Monitor** rev_64

Oct 12th, 2024
71
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 ESP32
  14.     - Source Code created on: 2024-10-12 22:31:48
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Read temperature from DS18B20 sensor and display */
  21.     /* on LCD screen. */
  22. /****** SYSTEM REQUIREMENT 2 *****/
  23.     /* Perform a countdown of 10 seconds after each */
  24.     /* temperature reading using LiquidCrystal library */
  25.     /* for display control. */
  26. /****** SYSTEM REQUIREMENT 3 *****/
  27.     /* use max pulse oximeter */
  28. /****** SYSTEM REQUIREMENT 4 *****/
  29.     /* use non blocking code. */
  30. /****** END SYSTEM REQUIREMENTS *****/
  31.  
  32.  
  33. /********* User code review feedback **********
  34. #### Feedback 1 ####
  35. - display also max pulse oximeter
  36. ********* User code review feedback **********/
  37.  
  38. /* START CODE */
  39.  
  40. /****** DEFINITION OF LIBRARIES *****/
  41. #include <Wire.h>
  42. #include <DS18B20.h>    //https://github.com/matmunk/DS18B20
  43. #include <LiquidCrystal.h>  //https://github.com/arduino-libraries/LiquidCrystal
  44. #include <DHT.h>    //https://github.com/adafruit/DHT-sensor-library
  45. #include <MAX30100_PulseOximeter.h> //https://github.com/gabriel-milan/Arduino-MAX30100
  46.  
  47. /****** FUNCTION PROTOTYPES *****/
  48. void setup(void);
  49. void loop(void);
  50. void updateOutputs();
  51. void readTemperature();
  52. void displayCountdown(int seconds);
  53. void displayPulseOximeterData(); // New function prototype
  54.  
  55. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  56. const uint8_t temperatureSensor_DHT22_DOUT_PIN_D9       = 9;
  57. const uint8_t PulseOximeter_MAX30100_INT_PIN_D2     = 2;
  58. const uint8_t temperatureSensor_DS18B20_DQ_PIN_D4       = 4;
  59.  
  60. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  61. const uint8_t myLCD_LCD1602_RS_PIN_D3       = 3;
  62. const uint8_t myLCD_LCD1602_D4_PIN_D5       = 5;
  63. const uint8_t myLCD_LCD1602_D5_PIN_D6       = 6;
  64. const uint8_t myLCD_LCD1602_D6_PIN_D7       = 7;
  65. const uint8_t myLCD_LCD1602_D7_PIN_D8       = 8;
  66.  
  67. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  68. float temperature = 0.0; // Variable to store temperature
  69. bool displayReady = true; // Flag to check if display is ready for next update
  70.  
  71. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  72. // DS18B20 sensor instance
  73. DS18B20 ds(temperatureSensor_DS18B20_DQ_PIN_D4);
  74. // LCD instance
  75. LiquidCrystal lcd(myLCD_LCD1602_RS_PIN_D3, myLCD_LCD1602_D4_PIN_D5, myLCD_LCD1602_D5_PIN_D6, myLCD_LCD1602_D6_PIN_D7, myLCD_LCD1602_D7_PIN_D8);
  76. // Pulse Oximeter instance
  77. PulseOximeter pox;
  78.  
  79. void setup(void)
  80. {
  81.     // put your setup code here, to run once:
  82.     Serial.begin(9600);
  83.    
  84.     // Initialize LCD
  85.     lcd.begin(16, 2);
  86.     lcd.clear();
  87.    
  88.     // Initialize DS18B20
  89.     ds.begin();
  90.    
  91.     // Initialize Pulse Oximeter
  92.     if (!pox.begin()) {
  93.         Serial.println("Failed to initialize Pulse Oximeter");
  94.         while (1);
  95.     }
  96.    
  97.     // Set up Pulse Oximeter
  98.     pox.setOnBeatDetectedCallback([]() {
  99.         Serial.println("Beat detected!");
  100.     });
  101. }
  102.  
  103. void loop(void)
  104. {
  105.     // put your main code here, to run repeatedly:
  106.     pox.update(); // Update pulse oximeter readings
  107.  
  108.     if (displayReady) {
  109.         readTemperature(); // Read temperature from DS18B20
  110.         displayCountdown(10); // Display countdown
  111.         displayPulseOximeterData(); // Display pulse oximeter data
  112.     }
  113. }
  114.  
  115. void readTemperature() {
  116.     // Read temperature from DS18B20
  117.     temperature = ds.getTempC();
  118.     lcd.clear();
  119.     lcd.print("Temp: ");
  120.     lcd.print(temperature);
  121.     lcd.print(" C");
  122.     displayReady = false; // Set flag to false until countdown is complete
  123. }
  124.  
  125. void displayCountdown(int seconds) {
  126.     for (int i = seconds; i > 0; i--) {
  127.         lcd.setCursor(0, 1); // Move cursor to the second line
  128.         lcd.print("Countdown: ");
  129.         lcd.print(i);
  130.         delay(1000); // Wait for 1 second
  131.     }
  132.     displayReady = true; // Set flag to true after countdown
  133. }
  134.  
  135. void displayPulseOximeterData() {
  136.     // Display heart rate and SpO2 on the LCD
  137.     lcd.clear();
  138.     lcd.setCursor(0, 0); // Move cursor to the first line
  139.     lcd.print("HR: ");
  140.     lcd.print(pox.getHeartRate());
  141.     lcd.print(" bpm");
  142.    
  143.     lcd.setCursor(0, 1); // Move cursor to the second line
  144.     lcd.print("SpO2: ");
  145.     lcd.print(pox.getSpO2());
  146.     lcd.print(" %");
  147. }
  148.  
  149. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement