Advertisement
pleasedontcode

**Data Monitor** rev_44

Oct 7th, 2024
73
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: **Data Monitor**
  13.     - Source Code NOT compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-10-07 23:19:15
  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 VARIABLES *****/
  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. PulseOximeter pox;
  63. DS18B20 ds18b20(temperatureSensor_DS18B20_DQ_PIN_D4); // Initialize DS18B20 with the data pin
  64.  
  65. // Non-blocking timing variables
  66. unsigned long previousMillis = 0;
  67. const long interval = 1000; // Interval for reading temperature and updating display
  68. bool countdownActive = false;
  69. int countdownSeconds = 10;
  70.  
  71. void setup(void)
  72. {
  73.     // Initialize Serial for debugging
  74.     Serial.begin(115200);
  75.  
  76.     // Initialize LCD
  77.     lcd.begin(16, 2);
  78.     lcd.clear();
  79.  
  80.     // Initialize Pulse Oximeter
  81.     if (!pox.begin()) {
  82.         Serial.println("Failed to initialize pulse oximeter");
  83.         while (1);
  84.     }
  85.  
  86.     // Set up the DS18B20 sensor
  87.     ds18b20.Update(); // Start temperature conversion
  88. }
  89.  
  90. void loop(void)
  91. {
  92.     unsigned long currentMillis = millis();
  93.  
  94.     // Check if it's time to read temperature and update display
  95.     if (currentMillis - previousMillis >= interval) {
  96.         previousMillis = currentMillis;
  97.  
  98.         // Read temperature and display it
  99.         readTemperature();
  100.        
  101.         // Start countdown
  102.         countdownActive = true;
  103.         countdownSeconds = 10; // Reset countdown
  104.     }
  105.  
  106.     // Perform countdown if active
  107.     if (countdownActive) {
  108.         displayCountdown(countdownSeconds);
  109.         countdownSeconds--;
  110.  
  111.         if (countdownSeconds < 0) {
  112.             countdownActive = false; // Stop countdown when done
  113.         }
  114.     }
  115.  
  116.     // Update pulse oximeter readings
  117.     pox.update();
  118.    
  119.     // Display heart rate and SpO2
  120.     Serial.print("Heart rate: ");
  121.     Serial.print(pox.getHeartRate());
  122.     Serial.print(" bpm / SpO2: ");
  123.     Serial.print(pox.getSpO2());
  124.     Serial.println(" %");
  125. }
  126.  
  127. void readTemperature()
  128. {
  129.     float temperature = ds18b20.GetTemperature<float>();
  130.     lcd.setCursor(0, 0);
  131.     lcd.print("Temp: ");
  132.     lcd.print(temperature);
  133.     lcd.print(" C");
  134. }
  135.  
  136. void displayCountdown(int seconds)
  137. {
  138.     lcd.setCursor(0, 1);
  139.     lcd.print("Countdown: ");
  140.     lcd.print(seconds);
  141. }
  142.  
  143. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement