/********* 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 Control - Source Code NOT compiled for: Arduino Uno - Source Code created on: 2024-05-11 16:58:08 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Use a D518820 sensor to measure temperature every */ /* 10 seconds and use a heater. the temperature is > */ /* 37 turn off the heater and if it's < 37 turn on */ /* the heater. Display the current temperature on the */ /* serial monitor. */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include #include //https://github.com/matmunk/DS18B20 /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void updateOutputs(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t tms_DS18B20_DQ_PIN_D2 = 2; /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t heater_LED_PIN_D3 = 3; /***** DEFINITION OF OUTPUT RAW VARIABLES *****/ /***** used to store raw data *****/ bool heater_LED_PIN_D3_rawData = 0; /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/ /***** used to store data after characteristic curve transformation *****/ float heater_LED_PIN_D3_phyData = 0.0; /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ MaximWire::Bus bus(9); // Define the MaximWire bus on pin 9 MaximWire::DS18B20 device; // Define the DS18B20 device void setup(void) { // put your setup code here, to run once: Serial.begin(9600); pinMode(tms_DS18B20_DQ_PIN_D2, INPUT); pinMode(heater_LED_PIN_D3, OUTPUT); // Initialize the DS18B20 device device = MaximWire::DS18B20(bus.Discover().FindNextDevice().GetAddress()); } void loop(void) { // put your main code here, to run repeatedly: // Measure temperature every 10 seconds device.requestTemperatures(); float temperature = device.getTempCByIndex(0); // Control the heater based on temperature if (temperature > 37) { heater_LED_PIN_D3_rawData = LOW; // Turn off the heater } else { heater_LED_PIN_D3_rawData = HIGH; // Turn on the heater } updateOutputs(); // Refresh output data // Display the current temperature on the serial monitor Serial.print("Temperature: "); Serial.print(temperature); Serial.println(" C"); delay(10000); // Wait for 10 seconds } void updateOutputs() { digitalWrite(heater_LED_PIN_D3, heater_LED_PIN_D3_rawData); }