Advertisement
pleasedontcode

**Temperature Control** rev_07

Jan 26th, 2025
29
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 NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-01-26 06:32:06
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* 温度到达 60led亮灯 */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /* START CODE */
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <DHT.h>    //https://github.com/adafruit/DHT-sensor-library
  27. #include <Deneyap_Servo.h>  //https://github.com/deneyapkart/deneyap-servo-arduino-library
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32. void updateOutputs(void);
  33. void readTemperature(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t DHT22_DOUT_PIN_D4 = 4;
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t LED_PIN_D14 = 14;
  40.  
  41. /***** DEFINITION OF PWM OUTPUT PINS *****/
  42. const uint8_t Servomotor_PWMSignal_PIN_D13 = 13;
  43.  
  44. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  45. bool LED_PIN_D14_rawData = 0;
  46. uint8_t Servomotor_PWMSignal_PIN_D13_rawData = 0;
  47.  
  48. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  49. float LED_PIN_D14_phyData = 0.0;
  50. float Servomotor_PWMSignal_PIN_D13_phyData = 0.0;
  51.  
  52. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  53. // Create an instance of the DHT sensor
  54. DHT dht(DHT22_DOUT_PIN_D4, DHT22);
  55.  
  56. // Create an instance of the Servo
  57. Servo servo;
  58.  
  59. void setup(void)
  60. {
  61.     // Initialize the DHT sensor
  62.     dht.begin();
  63.  
  64.     // Set pin modes
  65.     pinMode(LED_PIN_D14, OUTPUT);
  66.     pinMode(Servomotor_PWMSignal_PIN_D13, OUTPUT);
  67. }
  68.  
  69. void loop(void)
  70. {
  71.     // Read temperature and update outputs
  72.     readTemperature();
  73.     updateOutputs(); // Refresh output data
  74. }
  75.  
  76. void readTemperature()
  77. {
  78.     // Read temperature from the DHT sensor
  79.     float temperature = dht.readTemperature();
  80.  
  81.     // Check if the reading is valid
  82.     if (isnan(temperature)) {
  83.         Serial.println("Failed to read from DHT sensor!");
  84.         return;
  85.     }
  86.  
  87.     // Check if temperature reaches 60 degrees
  88.     if (temperature >= 60) {
  89.         LED_PIN_D14_rawData = true; // Turn on LED
  90.     } else {
  91.         LED_PIN_D14_rawData = false; // Turn off LED
  92.     }
  93.  
  94.     // You can add additional logic for the servo if needed
  95. }
  96.  
  97. void updateOutputs()
  98. {
  99.     digitalWrite(LED_PIN_D14, LED_PIN_D14_rawData);
  100.     analogWrite(Servomotor_PWMSignal_PIN_D13, Servomotor_PWMSignal_PIN_D13_rawData);
  101. }
  102.  
  103. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement