Advertisement
pleasedontcode

"Sensor Data" rev_39

Oct 7th, 2024
60
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: "Sensor Data"
  13.     - Source Code NOT compiled for: Arduino Nano ESP32
  14.     - Source Code created on: 2024-10-07 22:47:52
  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. /****** END SYSTEM REQUIREMENTS *****/
  29.  
  30. /* START CODE */
  31.  
  32. /****** DEFINITION OF LIBRARIES *****/
  33. #include <Wire.h>
  34. #include <DS18B20.h>    // https://github.com/matmunk/DS18B20
  35. #include <LiquidCrystal.h>    // https://github.com/arduino-libraries/LiquidCrystal
  36. #include <DHT.h>    // https://github.com/adafruit/DHT-sensor-library
  37. #include <MAX30100_PulseOximeter.h>    // https://github.com/gabriel-milan/Arduino-MAX30100
  38.  
  39. /****** FUNCTION PROTOTYPES *****/
  40. void setup(void);
  41. void loop(void);
  42. void updateOutputs();
  43. void displayTemperature(float temperature);
  44. void countdown(int seconds);
  45.  
  46. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  47. const uint8_t temperatureSensor_DHT22_DOUT_PIN_D9        = 9;
  48. const uint8_t PulseOximeter_MAX30100_INT_PIN_D2        = 2;
  49. const uint8_t temperatureSensor_DS18B20_DQ_PIN_D4        = 4;
  50.  
  51. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  52. const uint8_t myLCD_LCD1602_RS_PIN_D3        = 3;
  53. const uint8_t myLCD_LCD1602_D4_PIN_D5        = 5;
  54. const uint8_t myLCD_LCD1602_D5_PIN_D6        = 6;
  55. const uint8_t myLCD_LCD1602_D6_PIN_D7        = 7;
  56. const uint8_t myLCD_LCD1602_D7_PIN_D8        = 8;
  57.  
  58. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  59. bool    myLCD_LCD1602_RS_PIN_D3_rawData        = 0;
  60. bool    myLCD_LCD1602_D4_PIN_D5_rawData        = 0;
  61. bool    myLCD_LCD1602_D5_PIN_D6_rawData        = 0;
  62. bool    myLCD_LCD1602_D6_PIN_D7_rawData        = 0;
  63. bool    myLCD_LCD1602_D7_PIN_D8_rawData        = 0;
  64.  
  65. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  66. float   myLCD_LCD1602_RS_PIN_D3_phyData        = 0.0;
  67. float   myLCD_LCD1602_D4_PIN_D5_phyData        = 0.0;
  68. float   myLCD_LCD1602_D5_PIN_D6_phyData        = 0.0;
  69. float   myLCD_LCD1602_D6_PIN_D7_phyData        = 0.0;
  70. float   myLCD_LCD1602_D7_PIN_D8_phyData        = 0.0;
  71.  
  72. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  73. // Create instances for the sensors and display
  74. 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);
  75. DHT dht(temperatureSensor_DHT22_DOUT_PIN_D9, DHT22); // Assuming DHT22 sensor
  76. PulseOximeter pox;
  77.  
  78. void setup(void)
  79. {
  80.     // put your setup code here, to run once:
  81.     Serial.begin(115200);
  82.    
  83.     // Initialize LCD
  84.     lcd.begin(16, 2);
  85.     lcd.clear();
  86.    
  87.     // Initialize DHT sensor
  88.     dht.begin();
  89.  
  90.     // Initialize Pulse Oximeter
  91.     if (!pox.begin()) {
  92.         Serial.println("Failed to initialize Pulse Oximeter");
  93.         while (1);
  94.     }
  95.  
  96.     // Set up the Pulse Oximeter
  97.     pox.setOnBeatDetectedCallback([]() {
  98.         Serial.println("Beat detected!");
  99.     });
  100.  
  101.     // Set pin modes
  102.     pinMode(temperatureSensor_DS18B20_DQ_PIN_D4, INPUT);
  103. }
  104.  
  105. void loop(void)
  106. {
  107.     // Read temperature from DS18B20 sensor
  108.     float temperature = dht.readTemperature(); // Use DHT for temperature reading
  109.  
  110.     // Display temperature
  111.     displayTemperature(temperature);
  112.  
  113.     // Perform a countdown of 10 seconds
  114.     countdown(10);
  115.  
  116.     // Update Pulse Oximeter readings
  117.     pox.update();
  118.    
  119.     // Output heart rate and SpO2 values
  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 displayTemperature(float temperature) {
  128.     lcd.clear();
  129.     lcd.setCursor(0, 0);
  130.     lcd.print("Temp: ");
  131.     lcd.print(temperature);
  132.     lcd.print(" C");
  133. }
  134.  
  135. void countdown(int seconds) {
  136.     for (int i = seconds; i > 0; i--) {
  137.         lcd.setCursor(0, 1);
  138.         lcd.print("Countdown: ");
  139.         lcd.print(i);
  140.         delay(1000); // Wait for 1 second
  141.     }
  142. }
  143.  
  144. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement