Advertisement
pleasedontcode

Temperature Countdown rev_72

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