/********* 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 compiled for: Arduino Uno
- Source Code created on: 2024-04-20 14:54:25
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* Measure temperature using DS18B20 sensor every */
/* 10s. Display temperature on serial monitor. */
/* Control heater based on temperature. Turn off */
/* heater if temperature >= 37°C. Turn on heater if */
/* temperature < 37°C. */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include // https://github.com/PaulStoffregen/OneWire
#include // https://github.com/milesburton/Arduino-Temperature-Control-Library
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t Temp_sensor_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*****/
OneWire oneWire(Temp_sensor_DS18B20_DQ_PIN_D2); // Create an instance of the OneWire class
DallasTemperature sensors(&oneWire); // Pass the OneWire instance to the DallasTemperature library
void setup(void)
{
// put your setup code here, to run once:
pinMode(Temp_sensor_DS18B20_DQ_PIN_D2, INPUT);
pinMode(Heater_LED_PIN_D3, OUTPUT);
Serial.begin(9600);
sensors.begin(); // Initialize the DallasTemperature library
}
void loop(void)
{
// put your main code here, to run repeatedly:
sensors.requestTemperatures(); // Send the command to get temperatures
float temperatureC = sensors.getTempCByIndex(0); // Read the temperature in Celsius
// Display temperature on serial monitor
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println("°C");
// Control heater based on temperature
if (temperatureC >= 37.0)
{
Heater_LED_PIN_D3_rawData = LOW; // Turn off heater
}
else
{
Heater_LED_PIN_D3_rawData = HIGH; // Turn on heater
}
updateOutputs(); // Refresh output data
delay(10000); // Wait for 10 seconds before measuring again
}
void updateOutputs()
{
digitalWrite(Heater_LED_PIN_D3, Heater_LED_PIN_D3_rawData);
}