CCCPaste

Temperature Controller rev_03

/********* 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 Controller
	- Source Code compiled for: Arduino Uno
	- Source Code created on: 2024-04-20 08:06:46

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* Develop an Arduino code using DS18B20 sensor to */
	/* measure temperature every 10s. Display temperature */
	/* on serial monitor. Implement a heater. If */
	/* temperature is >= 37°C, turn off the heater. If */
	/* temperature is < 37°C, turn on the heater. */
/****** SYSTEM REQUIREMENT 2 *****/
	/* Develop an Arduino code using DS18B20 sensor to */
	/* measure temperature every 10s. Display temperature */
	/* on serial monitor. Implement a heater. If */
	/* temperature is >= 37°C, turn off the heater. If */
	/* temperature is < 37°C, turn on the heater. */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include  //https://github.com/matmunk/DS18B20

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* Develop an Arduino code using DS18B20 sensor to */
/* measure temperature every 10s. Display temperature */
/* on serial monitor. Implement a heater. If */
/* temperature is >= 37°C, turn off the heater. If */
/* temperature is < 37°C, turn on the heater. */

/****** 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*****/
DS18B20 ds(Temp_sensor_DS18B20_DQ_PIN_D2);

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);
}

void loop(void)
{
  // put your main code here, to run repeatedly:

  // Read temperature from DS18B20 sensor
  float temperature = ds.getTempC();

  // Display temperature on serial monitor
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" °C");

  // Control the heater based on temperature
  if (temperature >= 37.0)
  {
    Heater_LED_PIN_D3_rawData = 0; // Turn off the heater
  }
  else
  {
    Heater_LED_PIN_D3_rawData = 1; // Turn on the heater
  }

  updateOutputs(); // Refresh output data

  delay(10000); // Wait for 10 seconds
}

void updateOutputs()
{
  digitalWrite(Heater_LED_PIN_D3, Heater_LED_PIN_D3_rawData);
}