Advertisement
pleasedontcode

**Health Monitor** rev_71

Oct 13th, 2024
69
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-13 10:28:41
  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_E_PIN_D5        = 5;
  56. const uint8_t myLCD_LCD1602_D4_PIN_D6       = 6;
  57. const uint8_t myLCD_LCD1602_D5_PIN_D7       = 7;
  58. const uint8_t myLCD_LCD1602_D6_PIN_D8       = 8;
  59. const uint8_t myLCD_LCD1602_D7_PIN_D10      = 10;
  60.  
  61. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  62. bool    myLCD_LCD1602_RS_PIN_D3_rawData     = 0;
  63. bool    myLCD_LCD1602_E_PIN_D5_rawData      = 0;
  64. bool    myLCD_LCD1602_D4_PIN_D6_rawData     = 0;
  65. bool    myLCD_LCD1602_D5_PIN_D7_rawData     = 0;
  66. bool    myLCD_LCD1602_D6_PIN_D8_rawData     = 0;
  67. bool    myLCD_LCD1602_D7_PIN_D10_rawData        = 0;
  68.  
  69. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  70. float   myLCD_LCD1602_RS_PIN_D3_phyData     = 0.0;
  71. float   myLCD_LCD1602_E_PIN_D5_phyData      = 0.0;
  72. float   myLCD_LCD1602_D4_PIN_D6_phyData     = 0.0;
  73. float   myLCD_LCD1602_D5_PIN_D7_phyData     = 0.0;
  74. float   myLCD_LCD1602_D6_PIN_D8_phyData     = 0.0;
  75. float   myLCD_LCD1602_D7_PIN_D10_phyData        = 0.0;
  76.  
  77. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  78. // DS18B20 temperature sensor instance
  79. DS18B20 ds(temperatureSensor_DS18B20_DQ_PIN_D4);
  80. // LiquidCrystal instance
  81. LiquidCrystal lcd(myLCD_LCD1602_RS_PIN_D3, myLCD_LCD1602_E_PIN_D5, myLCD_LCD1602_D4_PIN_D6, myLCD_LCD1602_D5_PIN_D7, myLCD_LCD1602_D6_PIN_D8, myLCD_LCD1602_D7_PIN_D10);
  82. // MAX30100 pulse oximeter instance
  83. PulseOximeter pox;
  84.  
  85. unsigned long previousMillis = 0; // Store last time temperature was read
  86. const long interval = 10000; // Interval to read temperature (10 seconds)
  87. int countdown = 10; // Countdown timer
  88.  
  89. void setup(void)
  90. {
  91.     // Initialize pins
  92.     pinMode(temperatureSensor_DHT22_DOUT_PIN_D9, INPUT_PULLUP);
  93.     pinMode(PulseOximeter_MAX30100_INT_PIN_D2, INPUT_PULLUP);
  94.     pinMode(temperatureSensor_DS18B20_DQ_PIN_D4, INPUT);
  95.  
  96.     pinMode(myLCD_LCD1602_RS_PIN_D3, OUTPUT);
  97.     pinMode(myLCD_LCD1602_E_PIN_D5, OUTPUT);
  98.     pinMode(myLCD_LCD1602_D4_PIN_D6, OUTPUT);
  99.     pinMode(myLCD_LCD1602_D5_PIN_D7, OUTPUT);
  100.     pinMode(myLCD_LCD1602_D6_PIN_D8, OUTPUT);
  101.     pinMode(myLCD_LCD1602_D7_PIN_D10, OUTPUT);
  102.  
  103.     // Initialize the LCD
  104.     lcd.begin(16, 2);
  105.     // Initialize the pulse oximeter
  106.     if (!pox.begin()) {
  107.         lcd.print("MAX30100 Error");
  108.         while (1);
  109.     }
  110. }
  111.  
  112. void loop(void)
  113. {
  114.     unsigned long currentMillis = millis();
  115.  
  116.     // Check if it's time to read the temperature
  117.     if (currentMillis - previousMillis >= interval) {
  118.         previousMillis = currentMillis; // Save the last time temperature was read
  119.         readTemperature(); // Read temperature
  120.         displayCountdown(countdown); // Display countdown
  121.     }
  122.  
  123.     updateOutputs(); // Refresh output data
  124. }
  125.  
  126. void readTemperature()
  127. {
  128.     float temperature = ds.getTempC(); // Get temperature in Celsius
  129.     lcd.clear();
  130.     lcd.print("Temp: ");
  131.     lcd.print(temperature);
  132.     lcd.print(" C");
  133. }
  134.  
  135. void displayCountdown(int seconds)
  136. {
  137.     for (int i = seconds; i > 0; i--) {
  138.         lcd.setCursor(0, 1); // Set cursor to second line
  139.         lcd.print("Countdown: ");
  140.         lcd.print(i);
  141.         delay(1000); // Wait for 1 second
  142.     }
  143.     lcd.clear(); // Clear the display after countdown
  144. }
  145.  
  146. void updateOutputs()
  147. {
  148.     // Update LCD display outputs
  149.     digitalWrite(myLCD_LCD1602_RS_PIN_D3, myLCD_LCD1602_RS_PIN_D3_rawData);
  150.     digitalWrite(myLCD_LCD1602_E_PIN_D5, myLCD_LCD1602_E_PIN_D5_rawData);
  151.     digitalWrite(myLCD_LCD1602_D4_PIN_D6, myLCD_LCD1602_D4_PIN_D6_rawData);
  152.     digitalWrite(myLCD_LCD1602_D5_PIN_D7, myLCD_LCD1602_D5_PIN_D7_rawData);
  153.     digitalWrite(myLCD_LCD1602_D6_PIN_D8, myLCD_LCD1602_D6_PIN_D8_rawData);
  154.     digitalWrite(myLCD_LCD1602_D7_PIN_D10, myLCD_LCD1602_D7_PIN_D10_rawData);
  155. }
  156.  
  157. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement