Advertisement
pleasedontcode

**Health Monitor** rev_69

Oct 13th, 2024
64
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:16:55
  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 readTemperature();
  45. void displayCountdown(int seconds);
  46.  
  47. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  48. const uint8_t temperatureSensor_DHT22_DOUT_PIN_D9 = 9;
  49. const uint8_t PulseOximeter_MAX30100_INT_PIN_D2 = 2;
  50. const uint8_t temperatureSensor_DS18B20_DQ_PIN_D4 = 4;
  51.  
  52. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  53. const uint8_t myLCD_LCD1602_RS_PIN_D3 = 3;
  54. const uint8_t myLCD_LCD1602_D4_PIN_D5 = 5;
  55. const uint8_t myLCD_LCD1602_D5_PIN_D6 = 6;
  56. const uint8_t myLCD_LCD1602_D6_PIN_D7 = 7;
  57. const uint8_t myLCD_LCD1602_D7_PIN_D8 = 8;
  58.  
  59. /***** DEFINITION OF OUTPUT VARIABLES *****/
  60. float temperature = 0.0;
  61. 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);
  62. DS18B20 ds(temperatureSensor_DS18B20_DQ_PIN_D4);
  63. PulseOximeter pox;
  64.  
  65. void setup(void)
  66. {
  67.     // Initialize serial communication
  68.     Serial.begin(9600);
  69.    
  70.     // Initialize LCD
  71.     lcd.begin(16, 2);
  72.     lcd.clear();
  73.    
  74.     // Initialize DS18B20
  75.     ds.begin();
  76.    
  77.     // Initialize Pulse Oximeter
  78.     if (!pox.begin()) {
  79.         Serial.println("Failed to initialize Pulse Oximeter");
  80.         while (1);
  81.     }
  82.    
  83.     // Set up the Pulse Oximeter
  84.     pox.setOnBeatDetectedCallback([]() {
  85.         Serial.println("Beat detected!");
  86.     });
  87. }
  88.  
  89. void loop(void)
  90. {
  91.     // Read temperature from DS18B20
  92.     readTemperature();
  93.    
  94.     // Display temperature on LCD
  95.     lcd.setCursor(0, 0);
  96.     lcd.print("Temp: ");
  97.     lcd.print(temperature);
  98.     lcd.print(" C");
  99.    
  100.     // Perform countdown
  101.     displayCountdown(10);
  102.    
  103.     // Update Pulse Oximeter
  104.     pox.update();
  105.    
  106.     // Add a delay to avoid flooding the serial output
  107.     delay(1000);
  108. }
  109.  
  110. void readTemperature() {
  111.     // Get temperature from DS18B20
  112.     temperature = ds.getTempC();
  113. }
  114.  
  115. void displayCountdown(int seconds) {
  116.     for (int i = seconds; i > 0; i--) {
  117.         lcd.setCursor(0, 1);
  118.         lcd.print("Countdown: ");
  119.         lcd.print(i);
  120.         delay(1000); // Wait for 1 second
  121.     }
  122.     lcd.clear(); // Clear the LCD after countdown
  123. }
  124.  
  125. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement