Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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-19 17:50:09
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Measure temperature using DS18B20 sensor every */
- /* 10s. Display temperature. If temp > 37°C, turn off */
- /* heater. If temp <= 37°C, turn on heater. */
- /****** END SYSTEM REQUIREMENTS *****/
- /********* User code review feedback **********
- #### Feedback 1 ####
- - i need the temperature to be displayed on the serial monitor
- ********* User code review feedback **********/
- /****** DEFINITION OF LIBRARIES *****/
- #include <OneWire.h>
- #include <DallasTemperature.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Temp_sensor_DS18B20_DQ_PIN_D3 = 3;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t Heater_LED_PIN_D2 = 2;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- bool Heater_LED_PIN_D2_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- float Heater_LED_PIN_D2_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- OneWire oneWire(Temp_sensor_DS18B20_DQ_PIN_D3);
- DallasTemperature sensors(&oneWire);
- void setup(void)
- {
- // Initialize serial communication
- Serial.begin(9600);
- // Configure input and output pins
- pinMode(Temp_sensor_DS18B20_DQ_PIN_D3, INPUT);
- pinMode(Heater_LED_PIN_D2, OUTPUT);
- // Initialize DS18B20 sensor
- sensors.begin();
- sensors.setResolution(12);
- }
- void loop(void)
- {
- // Read temperature from DS18B20 sensor
- sensors.requestTemperatures();
- float temperature = sensors.getTempCByIndex(0);
- // Display temperature on the serial monitor
- Serial.print("Temperature: ");
- Serial.print(temperature);
- Serial.println("°C");
- // Update Heater LED based on temperature
- if (temperature > 37) {
- Heater_LED_PIN_D2_rawData = LOW; // Turn off heater
- } else {
- Heater_LED_PIN_D2_rawData = HIGH; // Turn on heater
- }
- updateOutputs(); // Refresh output data
- delay(10000); // Delay for 10 seconds
- }
- void updateOutputs(void)
- {
- digitalWrite(Heater_LED_PIN_D2, Heater_LED_PIN_D2_rawData);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement