Advertisement
pleasedontcode

**Sensor Data** rev_60

Oct 10th, 2024
58
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-10 17:03:19
  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 readTemperatureAndDisplay();
  46. void countdownTimer();
  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 RAW VARIABLES *****/
  61. bool    myLCD_LCD1602_RS_PIN_D3_rawData     = 0;
  62. bool    myLCD_LCD1602_D4_PIN_D5_rawData     = 0;
  63. bool    myLCD_LCD1602_D5_PIN_D6_rawData     = 0;
  64. bool    myLCD_LCD1602_D6_PIN_D7_rawData     = 0;
  65. bool    myLCD_LCD1602_D7_PIN_D8_rawData     = 0;
  66.  
  67. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  68. // Instantiate the DS18B20 sensor
  69. DS18B20 ds(temperatureSensor_DS18B20_DQ_PIN_D4);
  70. // Instantiate the LiquidCrystal display
  71. 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);
  72. // Instantiate the PulseOximeter
  73. PulseOximeter pulseOximeter;
  74.  
  75. unsigned long previousMillis = 0; // Store last time temperature was read
  76. const long interval = 10000; // Interval for reading temperature (10 seconds)
  77. bool timerActive = false; // Timer status
  78. int countdown = 10; // Countdown variable
  79. unsigned long countdownMillis = 0; // Store last time countdown was updated
  80.  
  81. void setup(void)
  82. {
  83.     // put your setup code here, to run once:
  84.  
  85.     pinMode(temperatureSensor_DHT22_DOUT_PIN_D9,    INPUT_PULLUP);
  86.     pinMode(PulseOximeter_MAX30100_INT_PIN_D2,  INPUT_PULLUP);
  87.     pinMode(temperatureSensor_DS18B20_DQ_PIN_D4,    INPUT);
  88.  
  89.     pinMode(myLCD_LCD1602_RS_PIN_D3,     OUTPUT);
  90.     pinMode(myLCD_LCD1602_D4_PIN_D5,     OUTPUT);
  91.     pinMode(myLCD_LCD1602_D5_PIN_D6,     OUTPUT);
  92.     pinMode(myLCD_LCD1602_D6_PIN_D7,     OUTPUT);
  93.     pinMode(myLCD_LCD1602_D7_PIN_D8,     OUTPUT);
  94.  
  95.     lcd.begin(16, 2); // Initialize the LCD
  96.     pulseOximeter.begin(); // Initialize the Pulse Oximeter
  97. }
  98.  
  99. void loop(void)
  100. {
  101.     // put your main code here, to run repeatedly:
  102.     unsigned long currentMillis = millis();
  103.  
  104.     // Check if it's time to read the temperature
  105.     if (currentMillis - previousMillis >= interval) {
  106.         previousMillis = currentMillis; // Save the last time temperature was read
  107.         readTemperatureAndDisplay(); // Read temperature and display it
  108.         timerActive = true; // Activate the countdown timer
  109.         countdown = 10; // Reset countdown
  110.         countdownMillis = currentMillis; // Reset countdown timer
  111.     }
  112.  
  113.     // If the timer is active, perform countdown
  114.     if (timerActive) {
  115.         countdownTimer(currentMillis);
  116.     }
  117.    
  118.     pulseOximeter.update(); // Update pulse oximeter readings
  119. }
  120.  
  121. void readTemperatureAndDisplay() {
  122.     float temperature = ds.getTempC(); // Get temperature in Celsius
  123.     lcd.clear(); // Clear the LCD
  124.     lcd.print("Temp: "); // Display temperature label
  125.     lcd.print(temperature); // Display temperature value
  126.     lcd.print(" C"); // Display unit
  127. }
  128.  
  129. void countdownTimer(unsigned long currentMillis) {
  130.     if (currentMillis - countdownMillis >= 1000) { // Check if 1 second has passed
  131.         countdownMillis = currentMillis; // Reset the countdown timer
  132.         if (countdown > 0) {
  133.             lcd.setCursor(0, 1); // Set cursor to the second line
  134.             lcd.print("Countdown: "); // Display countdown label
  135.             lcd.print(countdown); // Display countdown value
  136.             countdown--; // Decrement countdown
  137.         } else {
  138.             timerActive = false; // Deactivate the timer
  139.         }
  140.     }
  141. }
  142.  
  143. void updateOutputs() {
  144.     digitalWrite(myLCD_LCD1602_RS_PIN_D3, myLCD_LCD1602_RS_PIN_D3_rawData);
  145.     digitalWrite(myLCD_LCD1602_D4_PIN_D5, myLCD_LCD1602_D4_PIN_D5_rawData);
  146.     digitalWrite(myLCD_LCD1602_D5_PIN_D6, myLCD_LCD1602_D5_PIN_D6_rawData);
  147.     digitalWrite(myLCD_LCD1602_D6_PIN_D7, myLCD_LCD1602_D6_PIN_D7_rawData);
  148.     digitalWrite(myLCD_LCD1602_D7_PIN_D8, myLCD_LCD1602_D7_PIN_D8_rawData);
  149. }
  150.  
  151. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement