Advertisement
pleasedontcode

**Temperature Control** rev_06

Jan 26th, 2025
33
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:29: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 checkTemperature(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t DHT22_DOUT_PIN = 4; // Corrected variable name
  37.  
  38. /***** DEFINITION OF PWM OUTPUT PINS *****/
  39. const uint8_t Servomotor_PWMSignal_PIN = 13; // Corrected variable name
  40.  
  41. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  42. uint8_t Servomotor_PWMSignal_rawData = 0; // Corrected variable name
  43.  
  44. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  45. float Servomotor_PWMSignal_phyData = 0.0; // Corrected variable name
  46.  
  47. /****** DHT SENSOR INSTANCE *****/
  48. DHT dht(DHT22_DOUT_PIN, DHT22); // Create DHT sensor instance
  49.  
  50. /****** DEFINITION OF LED PIN *****/
  51. const uint8_t LED_PIN = 2; // Define LED pin
  52.  
  53. void setup(void)
  54. {
  55.     // put your setup code here, to run once:
  56.     pinMode(DHT22_DOUT_PIN, INPUT_PULLUP);
  57.     pinMode(Servomotor_PWMSignal_PIN, OUTPUT);
  58.     pinMode(LED_PIN, OUTPUT); // Set LED pin as output
  59.  
  60.     dht.begin(); // Initialize DHT sensor
  61. }
  62.  
  63. void loop(void)
  64. {
  65.     // put your main code here, to run repeatedly:
  66.     updateOutputs(); // Refresh output data
  67.     checkTemperature(); // Check temperature and control LED
  68. }
  69.  
  70. void updateOutputs()
  71. {
  72.     analogWrite(Servomotor_PWMSignal_PIN, Servomotor_PWMSignal_rawData);
  73. }
  74.  
  75. void checkTemperature()
  76. {
  77.     float temperature = dht.readTemperature(); // Read temperature from DHT sensor
  78.  
  79.     if (isnan(temperature)) {
  80.         Serial.println("Failed to read from DHT sensor!");
  81.         return;
  82.     }
  83.  
  84.     if (temperature >= 60) {
  85.         digitalWrite(LED_PIN, HIGH); // Turn on LED if temperature is 60 or above
  86.     } else {
  87.         digitalWrite(LED_PIN, LOW); // Turn off LED otherwise
  88.     }
  89. }
  90.  
  91. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement