Advertisement
pleasedontcode

**Data Monitor** rev_42

Oct 7th, 2024
85
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:02:34
  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. #include <dht11esp8266.h>   //https://github.com/Adish0016/dht11esp8266
  41.  
  42. /****** FUNCTION PROTOTYPES *****/
  43. void setup(void);
  44. void loop(void);
  45. void updateOutputs();
  46. void readTemperature();
  47. void displayCountdown(int seconds);
  48.  
  49. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  50. const uint8_t temperatureSensor_DHT22_DOUT_PIN_D9 = 9;
  51. const uint8_t PulseOximeter_MAX30100_INT_PIN_D2 = 2;
  52. const uint8_t temperatureSensor_DS18B20_DQ_PIN_D4 = 4;
  53.  
  54. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  55. const uint8_t myLCD_LCD1602_RS_PIN_D3 = 3;
  56. const uint8_t myLCD_LCD1602_D4_PIN_D5 = 5;
  57. const uint8_t myLCD_LCD1602_D5_PIN_D6 = 6;
  58. const uint8_t myLCD_LCD1602_D6_PIN_D7 = 7;
  59. const uint8_t myLCD_LCD1602_D7_PIN_D8 = 8;
  60.  
  61. /****** DEFINITION OF OUTPUT VARIABLES *****/
  62. float temperature = 0.0;
  63. unsigned long previousMillis = 0; // Store last time temperature was read
  64. const long interval = 1000; // Interval for reading temperature (1 second)
  65.  
  66. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  67. // Create instances for the LCD and Pulse Oximeter
  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. PulseOximeter pox;
  70.  
  71. void setup(void)
  72. {
  73.     // put your setup code here, to run once:
  74.     lcd.begin(16, 2); // Initialize the LCD
  75.     Serial.begin(115200); // Initialize serial communication
  76.  
  77.     // Initialize Pulse Oximeter
  78.     if (!pox.begin()) {
  79.         Serial.println("Failed to initialize Pulse Oximeter");
  80.         while (1);
  81.     }
  82.     pox.setOnBeatDetectedCallback([]() {
  83.         Serial.println("Beat detected!");
  84.     });
  85.  
  86.     // Set pin modes
  87.     pinMode(temperatureSensor_DHT22_DOUT_PIN_D9, INPUT_PULLUP);
  88.     pinMode(PulseOximeter_MAX30100_INT_PIN_D2, INPUT_PULLUP);
  89.     pinMode(temperatureSensor_DS18B20_DQ_PIN_D4, INPUT);
  90. }
  91.  
  92. void loop(void)
  93. {
  94.     // Non-blocking code to read temperature every second
  95.     unsigned long currentMillis = millis();
  96.     if (currentMillis - previousMillis >= interval) {
  97.         previousMillis = currentMillis;
  98.         readTemperature(); // Read temperature
  99.         displayCountdown(10); // Display countdown
  100.     }
  101.  
  102.     pox.update(); // Update Pulse Oximeter readings
  103.     // Display heart rate and SpO2 on the serial monitor
  104.     Serial.print("Heart rate: ");
  105.     Serial.print(pox.getHeartRate());
  106.     Serial.print(" bpm / SpO2: ");
  107.     Serial.print(pox.getSpO2());
  108.     Serial.println(" %");
  109. }
  110.  
  111. void readTemperature() {
  112.     // Read temperature from DS18B20 sensor
  113.     temperature = DS18B20::GetTemperature<float>(temperatureSensor_DS18B20_DQ_PIN_D4);
  114.     lcd.clear();
  115.     lcd.print("Temp: ");
  116.     lcd.print(temperature);
  117.     lcd.print(" C");
  118. }
  119.  
  120. void displayCountdown(int seconds) {
  121.     for (int i = seconds; i > 0; i--) {
  122.         lcd.setCursor(0, 1); // Set cursor to second line
  123.         lcd.print("Countdown: ");
  124.         lcd.print(i);
  125.         delay(1000); // Wait for 1 second
  126.     }
  127. }
  128.  
  129. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement