Advertisement
pleasedontcode

**Health Monitor** rev_40

Oct 7th, 2024
65
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-07 22:53:43
  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. /****** END SYSTEM REQUIREMENTS *****/
  29.  
  30.  
  31. /********* User code review feedback **********
  32. #### Feedback 1 ####
  33. - use a non blocking countdown
  34. ********* User code review feedback **********/
  35.  
  36. /* START CODE */
  37.  
  38. /****** DEFINITION OF LIBRARIES *****/
  39. #include <Wire.h>
  40. #include <DS18B20.h>    // https://github.com/matmunk/DS18B20
  41. #include <LiquidCrystal.h>    // https://github.com/arduino-libraries/LiquidCrystal
  42. #include <DHT.h>    // https://github.com/adafruit/DHT-sensor-library
  43. #include <MAX30100_PulseOximeter.h>    // https://github.com/gabriel-milan/Arduino-MAX30100
  44. #include "custom_functions.h" // Include the custom functions for non-blocking countdown
  45.  
  46. /****** FUNCTION PROTOTYPES *****/
  47. void setup(void);
  48. void loop(void);
  49. void updateOutputs();
  50. void displayTemperature(float temperature);
  51.  
  52. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  53. const uint8_t temperatureSensor_DHT22_DOUT_PIN_D9        = 9;
  54. const uint8_t PulseOximeter_MAX30100_INT_PIN_D2        = 2;
  55. const uint8_t temperatureSensor_DS18B20_DQ_PIN_D4        = 4;
  56.  
  57. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  58. const uint8_t myLCD_LCD1602_RS_PIN_D3        = 3;
  59. const uint8_t myLCD_LCD1602_D4_PIN_D5        = 5;
  60. const uint8_t myLCD_LCD1602_D5_PIN_D6        = 6;
  61. const uint8_t myLCD_LCD1602_D6_PIN_D7        = 7;
  62. const uint8_t myLCD_LCD1602_D7_PIN_D8        = 8;
  63.  
  64. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  65. // Create instances for the sensors and display
  66. 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);
  67. DHT dht(temperatureSensor_DHT22_DOUT_PIN_D9, DHT22); // Assuming DHT22 sensor
  68. PulseOximeter pox;
  69. NonBlockingCountdown countdownTimer; // Instance of the countdown timer
  70.  
  71. void setup(void)
  72. {
  73.     Serial.begin(115200);
  74.    
  75.     // Initialize LCD
  76.     lcd.begin(16, 2);
  77.     lcd.clear();
  78.    
  79.     // Initialize DHT sensor
  80.     dht.begin();
  81.  
  82.     // Initialize Pulse Oximeter
  83.     if (!pox.begin()) {
  84.         Serial.println("Failed to initialize Pulse Oximeter");
  85.         while (1);
  86.     }
  87.  
  88.     // Set up the Pulse Oximeter
  89.     pox.setOnBeatDetectedCallback([]() {
  90.         Serial.println("Beat detected!");
  91.     });
  92.  
  93.     // Set pin modes
  94.     pinMode(temperatureSensor_DS18B20_DQ_PIN_D4, INPUT);
  95. }
  96.  
  97. void loop(void)
  98. {
  99.     // Read temperature from DHT sensor
  100.     float temperature = dht.readTemperature(); // Use DHT for temperature reading
  101.  
  102.     // Display temperature
  103.     displayTemperature(temperature);
  104.  
  105.     // Start countdown if not already counting
  106.     if (countdownTimer.isFinished()) {
  107.         countdownTimer.start(10); // Start a new countdown of 10 seconds
  108.     }
  109.  
  110.     // Update countdown
  111.     countdownTimer.update(lcd);
  112.  
  113.     // Update Pulse Oximeter readings
  114.     pox.update();
  115.    
  116.     // Output heart rate and SpO2 values
  117.     Serial.print("Heart rate: ");
  118.     Serial.print(pox.getHeartRate());
  119.     Serial.print(" bpm / SpO2: ");
  120.     Serial.print(pox.getSpO2());
  121.     Serial.println(" %");
  122. }
  123.  
  124. void displayTemperature(float temperature) {
  125.     lcd.clear();
  126.     lcd.setCursor(0, 0);
  127.     lcd.print("Temp: ");
  128.     lcd.print(temperature);
  129.     lcd.print(" C");
  130. }
  131.  
  132. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement