Advertisement
pleasedontcode

**Health Monitor** rev_63

Oct 12th, 2024
77
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:16:57
  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(int seconds);
  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 OUTPUT RAW VARIABLES *****/
  61. float temperature = 0.0; // Variable to store temperature
  62. bool displayReady = true; // Flag to check if display is ready for next update
  63.  
  64. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  65. // DS18B20 sensor instance
  66. DS18B20 ds(temperatureSensor_DS18B20_DQ_PIN_D4);
  67. // LCD instance
  68. 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);
  69. // Pulse Oximeter instance
  70. PulseOximeter pox;
  71.  
  72. void setup(void)
  73. {
  74.     // put your setup code here, to run once:
  75.     Serial.begin(9600);
  76.    
  77.     // Initialize LCD
  78.     lcd.begin(16, 2);
  79.     lcd.clear();
  80.    
  81.     // Initialize DS18B20
  82.     ds.begin();
  83.    
  84.     // Initialize Pulse Oximeter
  85.     if (!pox.begin()) {
  86.         Serial.println("Failed to initialize Pulse Oximeter");
  87.         while (1);
  88.     }
  89.    
  90.     // Set up Pulse Oximeter
  91.     pox.setOnBeatDetectedCallback([]() {
  92.         Serial.println("Beat detected!");
  93.     });
  94. }
  95.  
  96. void loop(void)
  97. {
  98.     // put your main code here, to run repeatedly:
  99.     pox.update(); // Update pulse oximeter readings
  100.  
  101.     if (displayReady) {
  102.         readTemperature(); // Read temperature from DS18B20
  103.         displayCountdown(10); // Display countdown
  104.     }
  105. }
  106.  
  107. void readTemperature() {
  108.     // Read temperature from DS18B20
  109.     temperature = ds.getTempC();
  110.     lcd.clear();
  111.     lcd.print("Temp: ");
  112.     lcd.print(temperature);
  113.     lcd.print(" C");
  114.     displayReady = false; // Set flag to false until countdown is complete
  115. }
  116.  
  117. void displayCountdown(int seconds) {
  118.     for (int i = seconds; i > 0; i--) {
  119.         lcd.setCursor(0, 1); // Move cursor to the second line
  120.         lcd.print("Countdown: ");
  121.         lcd.print(i);
  122.         delay(1000); // Wait for 1 second
  123.     }
  124.     displayReady = true; // Set flag to true after countdown
  125. }
  126.  
  127. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement