Advertisement
pleasedontcode

"Temperature Control" rev_01

Apr 14th, 2024
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Temperature Control"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-04-14 12:23:05
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* if temp is greater than 38 degree celcius or less */
  21.     /* than 16 degree celcius turn red light otherwise */
  22.     /* turn green */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <DS18B20.h> //https://github.com/matmunk/DS18B20
  27. #include <Servo.h>   //https://github.com/arduino-libraries/Servo
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32. void updateOutputs(void);
  33.  
  34. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  35. const uint8_t temp_sensor_DS18B20_DQ_PIN_D2 = 2;
  36.  
  37. /***** DEFINITION OF PWM OUTPUT PINS *****/
  38. const uint8_t my_servo_Servomotor_PWMSignal_PIN_D3 = 3;
  39. const uint8_t my_servo_Servomotor_PWMSignal_PIN_D5 = 5;
  40.  
  41. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  42. /***** used to store raw data *****/
  43. uint8_t my_servo_Servomotor_PWMSignal_PIN_D3_rawData = 0;
  44. uint8_t my_servo_Servomotor_PWMSignal_PIN_D5_rawData = 0;
  45.  
  46. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  47. /***** used to store data after characteristic curve transformation *****/
  48. float my_servo_Servomotor_PWMSignal_PIN_D3_phyData = 0.0;
  49. float my_servo_Servomotor_PWMSignal_PIN_D5_phyData = 0.0;
  50.  
  51. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  52. DS18B20 ds(temp_sensor_DS18B20_DQ_PIN_D2);
  53. Servo my_servo_D3;
  54. Servo my_servo_D5;
  55.  
  56. /****** SYSTEM REQUIREMENTS *****/
  57. const float HIGH_TEMP_THRESHOLD = 38.0;  // High temperature threshold in degree Celsius
  58. const float LOW_TEMP_THRESHOLD = 16.0;   // Low temperature threshold in degree Celsius
  59.  
  60. void setup(void)
  61. {
  62.   // put your setup code here, to run once:
  63.   Serial.begin(9600);
  64.  
  65.   ds.resetSearch();
  66.   while (ds.selectNext())
  67.   {
  68.     ds.setAlarms(LOW_TEMP_THRESHOLD, HIGH_TEMP_THRESHOLD);
  69.   }
  70.  
  71.   my_servo_D3.attach(my_servo_Servomotor_PWMSignal_PIN_D3);
  72.   my_servo_D5.attach(my_servo_Servomotor_PWMSignal_PIN_D5);
  73.  
  74.   pinMode(temp_sensor_DS18B20_DQ_PIN_D2, INPUT);
  75.  
  76.   pinMode(my_servo_Servomotor_PWMSignal_PIN_D3, OUTPUT);
  77.   pinMode(my_servo_Servomotor_PWMSignal_PIN_D5, OUTPUT);
  78. }
  79.  
  80. void loop(void)
  81. {
  82.   // put your main code here, to run repeatedly:
  83.   ds.doConversion();
  84.  
  85.   ds.resetSearch();
  86.   while (ds.selectNextAlarm())
  87.   {
  88.     Serial.print("Alarm Low: ");
  89.     Serial.print(ds.getAlarmLow());
  90.     Serial.println(" C");
  91.     Serial.print("Alarm High: ");
  92.     Serial.print(ds.getAlarmHigh());
  93.     Serial.println(" C");
  94.     Serial.print("Temperature: ");
  95.     Serial.print(ds.getTempC());
  96.     Serial.println(" C\n");
  97.   }
  98.  
  99.   float currentTemp = ds.getTempC(); // Get the current temperature reading
  100.  
  101.   // Check if the temperature is within the desired range
  102.   if (currentTemp > HIGH_TEMP_THRESHOLD || currentTemp < LOW_TEMP_THRESHOLD)
  103.   {
  104.     // Turn on the red light
  105.     my_servo_D3.write(180); // Assuming 180 degrees corresponds to the red light position
  106.     my_servo_D5.write(0);   // Assuming 0 degrees corresponds to the off position
  107.   }
  108.   else
  109.   {
  110.     // Turn on the green light
  111.     my_servo_D3.write(0);   // Assuming 0 degrees corresponds to the off position
  112.     my_servo_D5.write(180); // Assuming 180 degrees corresponds to the green light position
  113.   }
  114.  
  115.   delay(10000);
  116. }
  117.  
  118. void updateOutputs()
  119. {
  120.   my_servo_D3.write(my_servo_Servomotor_PWMSignal_PIN_D3_rawData);
  121.   my_servo_D5.write(my_servo_Servomotor_PWMSignal_PIN_D5_rawData);
  122. }
  123.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement