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: Temp Control
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-10-21 05:40:41
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* If DUT temperature is less than 50°C & POT voltage */
- /* is less than 2 Volts starts output connected to */
- /* pin3 else no output */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <DS18B20.h> //https://github.com/matmunk/DS18B20
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t TC1_DS18B20_DQ_PIN_D2 = 2; // Pin for DS18B20 data line
- const uint8_t TC1_DS18B20_DQ_PIN_D3 = 3; // Output pin for control
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create an instance of the DS18B20 class, using pin D2
- DS18B20 ds(TC1_DS18B20_DQ_PIN_D2);
- // Define alarm temperature thresholds
- #define LOW_ALARM 20
- #define HIGH_ALARM 25
- // Address of the DS18B20 device (example address)
- uint8_t address[] = {40, 250, 31, 218, 4, 0, 0, 52};
- /****** SETUP FUNCTION *****/
- void setup(void)
- {
- // Start serial communication for debugging
- Serial.begin(9600);
- // Set pin modes for the digital input pins
- pinMode(TC1_DS18B20_DQ_PIN_D2, INPUT);
- pinMode(TC1_DS18B20_DQ_PIN_D3, OUTPUT); // Set pin D3 as output
- // Select the DS18B20 device using its address
- if (ds.select(address)) {
- // Set the alarm thresholds for the temperature sensor
- ds.setAlarms(LOW_ALARM, HIGH_ALARM);
- } else {
- Serial.println("Device not found!");
- }
- }
- /****** LOOP FUNCTION *****/
- void loop(void)
- {
- // Check if the DS18B20 device is selected
- if (ds.select(address)) {
- // Get the current temperature
- float currentTemperature = ds.getTempC();
- // Simulate reading POT voltage (replace with actual voltage reading code)
- float potVoltage = analogRead(A0) * (5.0 / 1023.0); // Assuming a 5V reference
- // Check the system requirements
- if (currentTemperature < 50.0 && potVoltage < 2.0) {
- digitalWrite(TC1_DS18B20_DQ_PIN_D3, HIGH); // Activate output
- } else {
- digitalWrite(TC1_DS18B20_DQ_PIN_D3, LOW); // Deactivate output
- }
- // Check if the temperature alarm has been triggered
- if (ds.hasAlarm()) {
- // Print a warning message with the current temperature
- Serial.print("Warning! Temperature is ");
- Serial.print(currentTemperature);
- Serial.println(" C");
- }
- } else {
- Serial.println("Device not found!");
- }
- // Wait for 10 seconds before the next loop iteration
- delay(10000);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement