/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: **Sensor Data** - Source Code NOT compiled for: Arduino Nano ESP32 - Source Code created on: 2024-10-09 23:03:18 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Read temperature from DS18B20 sensor and display */ /* on LCD screen. */ /****** SYSTEM REQUIREMENT 2 *****/ /* Perform a countdown of 10 seconds after each */ /* temperature reading using LiquidCrystal library */ /* for display control. */ /****** SYSTEM REQUIREMENT 3 *****/ /* use max pulse oximeter */ /****** SYSTEM REQUIREMENT 4 *****/ /* use non blocking code. */ /****** END SYSTEM REQUIREMENTS *****/ /* START CODE */ /****** DEFINITION OF LIBRARIES *****/ #include #include // DS18B20 temperature sensor library #include // LiquidCrystal library for LCD control #include // DHT sensor library #include // MAX30100 pulse oximeter library /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void readTemperatureAndDisplay(); void countdown(int seconds); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t temperatureSensor_DHT22_DOUT_PIN_D9 = 9; const uint8_t PulseOximeter_MAX30100_INT_PIN_D2 = 2; const uint8_t temperatureSensor_DS18B20_DQ_PIN_D4 = 4; /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t myLCD_LCD1602_RS_PIN_D3 = 3; const uint8_t myLCD_LCD1602_D4_PIN_D5 = 5; const uint8_t myLCD_LCD1602_D5_PIN_D6 = 6; const uint8_t myLCD_LCD1602_D6_PIN_D7 = 7; const uint8_t myLCD_LCD1602_D7_PIN_D8 = 8; /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ // Create instances for the sensors and LCD DS18B20 tempSensor(temperatureSensor_DS18B20_DQ_PIN_D4); 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); DHT dht(temperatureSensor_DHT22_DOUT_PIN_D9, DHT22); PulseOximeter pox; // Countdown variables unsigned long previousMillis = 0; int countdownTime = 10; bool countingDown = false; void setup(void) { // Initialize serial communication Serial.begin(9600); // Initialize the LCD lcd.begin(16, 2); lcd.print("Initializing..."); // Initialize the DHT sensor dht.begin(); // Initialize the pulse oximeter if (!pox.begin()) { Serial.println("Failed to initialize pulse oximeter"); while (1); } // Set up the pulse oximeter pox.setOnBeatDetectedCallback([]() { Serial.println("Beat detected!"); }); // Set pin modes pinMode(temperatureSensor_DHT22_DOUT_PIN_D9, INPUT_PULLUP); pinMode(PulseOximeter_MAX30100_INT_PIN_D2, INPUT_PULLUP); pinMode(temperatureSensor_DS18B20_DQ_PIN_D4, INPUT); } void loop(void) { // Read temperature and display it on the LCD readTemperatureAndDisplay(); // Perform a countdown of 10 seconds if not already counting down if (!countingDown) { countingDown = true; previousMillis = millis(); countdownTime = 10; // Reset countdown } // Non-blocking countdown logic if (countingDown) { unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= 1000) { // Check if 1 second has passed previousMillis = currentMillis; if (countdownTime > 0) { lcd.setCursor(0, 1); // Set cursor to the second line lcd.print("Countdown: "); lcd.print(countdownTime); countdownTime--; } else { countingDown = false; // Stop countdown when it reaches 0 } } } } void readTemperatureAndDisplay() { // Read temperature from DS18B20 float temperature = tempSensor.getTempC(); lcd.clear(); lcd.print("Temp: "); lcd.print(temperature); lcd.print(" C"); } /* END CODE */