/********* 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: Temperature Monitoring - Source Code NOT compiled for: Arduino Nano ESP32 - Source Code created on: 2024-08-12 13:51:30 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* surveillance de temperature à l'aide du capteur */ /* DS18B20 connecté à la broche numérique D2. Lire et */ /* traiter les données de température pour les */ /* applications d'énergie solaire, garantissant des */ /* relevés précis et opportuns. */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include //https://github.com/matmunk/DS18B20 /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t temp_DS18B20_DQ_PIN_D2 = 2; /***** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ // Create a Bus instance for communication on the specified pin MaximWire::Bus bus(temp_DS18B20_DQ_PIN_D2); // Create a DS18B20 instance without specifying an address (will need to discover devices) MaximWire::DS18B20 device; /****** SETUP FUNCTION *****/ void setup(void) { // Initialize serial communication for debugging Serial.begin(9600); // Set the pin mode for the temperature sensor data pin pinMode(temp_DS18B20_DQ_PIN_D2, INPUT); } /****** LOOP FUNCTION *****/ void loop(void) { // Check if the device is valid if (device.IsValid()) { // Get the temperature in Celsius float temp = device.GetTemperature(bus); if (!isnan(temp)) { // Print the temperature to the serial monitor Serial.print("Temperature: "); Serial.print(temp); Serial.println(" °C"); } else { // If the temperature reading is invalid, print a message Serial.println("Temperature reading lost."); device.Reset(); // Reset the device if lost } } else { // If the device is not valid, try to discover it if (bus.Discover().FindNextDevice(device) && device.GetModelCode() == MaximWire::DS18B20::MODEL_CODE) { Serial.print("Found device: "); Serial.println(device.ToString()); device.Update(bus); // Update the device state } else { // If no device is found, print a message Serial.println("No DS18B20 device found."); device.Reset(); // Reset the device if not found } } // Delay before the next loop iteration delay(1000); } /* END CODE */