Advertisement
pleasedontcode

**Health Monitor** rev_59

Oct 9th, 2024
80
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-09 23:36:06
  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. /* START CODE */
  33.  
  34. /****** DEFINITION OF LIBRARIES *****/
  35. #include <Wire.h>
  36. #include <DS18B20.h>    //https://github.com/matmunk/DS18B20
  37. #include <LiquidCrystal.h>  //https://github.com/arduino-libraries/LiquidCrystal
  38. #include <DHT.h>    //https://github.com/adafruit/DHT-sensor-library
  39. #include <MAX30100_PulseOximeter.h> //https://github.com/gabriel-milan/Arduino-MAX30100
  40.  
  41. /****** FUNCTION PROTOTYPES *****/
  42. void setup(void);
  43. void loop(void);
  44. void updateOutputs();
  45. void readTemperature();
  46. void displayCountdown();
  47.  
  48. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  49. const uint8_t temperatureSensor_DHT22_DOUT_PIN_D9 = 9;
  50. const uint8_t PulseOximeter_MAX30100_INT_PIN_D2 = 2;
  51. const uint8_t temperatureSensor_DS18B20_DQ_PIN_D4 = 4;
  52.  
  53. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  54. const uint8_t myLCD_LCD1602_RS_PIN_D3 = 3;
  55. const uint8_t myLCD_LCD1602_D4_PIN_D5 = 5;
  56. const uint8_t myLCD_LCD1602_D5_PIN_D6 = 6;
  57. const uint8_t myLCD_LCD1602_D6_PIN_D7 = 7;
  58. const uint8_t myLCD_LCD1602_D7_PIN_D8 = 8;
  59.  
  60. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  61. // Create instances for the sensors and LCD
  62. DS18B20 ds(temperatureSensor_DS18B20_DQ_PIN_D4);
  63. 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);
  64. PulseOximeter pulseOximeter;
  65.  
  66. // Non-blocking countdown variables
  67. unsigned long countdownStartTime = 0;
  68. bool countdownActive = false;
  69. int countdownSeconds = 10;
  70.  
  71. void setup(void)
  72. {
  73.     Serial.begin(9600);
  74.     lcd.begin(16, 2); // Initialize the LCD
  75.     lcd.clear(); // Clear the LCD
  76.  
  77.     pinMode(temperatureSensor_DHT22_DOUT_PIN_D9, INPUT_PULLUP);
  78.     pinMode(PulseOximeter_MAX30100_INT_PIN_D2, INPUT_PULLUP);
  79.     pinMode(temperatureSensor_DS18B20_DQ_PIN_D4, INPUT);
  80.  
  81.     // Initialize the pulse oximeter
  82.     if (!pulseOximeter.begin()) {
  83.         Serial.println("Failed to initialize pulse oximeter!");
  84.         while (1);
  85.     }
  86. }
  87.  
  88. void loop(void)
  89. {
  90.     // Read temperature from DS18B20
  91.     readTemperature();
  92.  
  93.     // Check if countdown is active
  94.     if (countdownActive) {
  95.         unsigned long currentMillis = millis();
  96.         if (currentMillis - countdownStartTime >= 1000) { // Check if 1 second has passed
  97.             countdownSeconds--;
  98.             countdownStartTime = currentMillis; // Reset the timer
  99.             if (countdownSeconds <= 0) {
  100.                 countdownActive = false; // Stop countdown when it reaches 0
  101.                 lcd.setCursor(0, 1);
  102.                 lcd.print("Done!       "); // Clear the line after countdown
  103.             } else {
  104.                 displayCountdown(); // Update countdown display
  105.             }
  106.         }
  107.     }
  108.  
  109.     // Update pulse oximeter readings
  110.     pulseOximeter.update();
  111.  
  112.     // Start countdown if not active
  113.     if (!countdownActive) {
  114.         countdownActive = true;
  115.         countdownSeconds = 10; // Reset countdown to 10 seconds
  116.         countdownStartTime = millis(); // Start the countdown timer
  117.     }
  118. }
  119.  
  120. void readTemperature() {
  121.     float temperature = ds.getTempC(); // Get temperature in Celsius
  122.     if (temperature != DEVICE_DISCONNECTED_C) {
  123.         lcd.setCursor(0, 0);
  124.         lcd.print("Temp: ");
  125.         lcd.print(temperature);
  126.         lcd.print(" C");
  127.     } else {
  128.         lcd.setCursor(0, 0);
  129.         lcd.print("Temp: Error");
  130.     }
  131. }
  132.  
  133. void displayCountdown() {
  134.     lcd.setCursor(0, 1);
  135.     lcd.print("Countdown: ");
  136.     lcd.print(countdownSeconds);
  137. }
  138.  
  139. void updateOutputs()
  140. {
  141.     // This function can be used for other output updates if needed
  142. }
  143.  
  144. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement