Advertisement
pleasedontcode

"Temperature Control" rev_01

Jan 2nd, 2024
74
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-01-02 09:16:10
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Read temperature and humidity. Turn on fan when */
  21.     /* temperature rises above 28 degrees */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Arduino.h>
  26. #include <DHT.h>
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t Temp_DHT11_DOUT_PIN_D2 = 2;
  34. const uint8_t Fan_PIN = 3;
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  37. DHT dht(Temp_DHT11_DOUT_PIN_D2, DHT11);
  38.  
  39. void setup(void)
  40. {
  41.   // put your setup code here, to run once:
  42.   pinMode(Temp_DHT11_DOUT_PIN_D2, INPUT_PULLUP);
  43.   pinMode(Fan_PIN, OUTPUT);
  44.   dht.begin();
  45. }
  46.  
  47. void loop(void)
  48. {
  49.   // put your main code here, to run repeatedly:
  50.   float humidity = dht.readHumidity();
  51.   float temperature = dht.readTemperature();
  52.  
  53.   // Check if any reads failed and exit early (to try again).
  54.   if (isnan(humidity) || isnan(temperature)) {
  55.     Serial.println("Failed to read from DHT sensor!");
  56.     return;
  57.   }
  58.  
  59.   // Print temperature and humidity values.
  60.   Serial.print("Humidity: ");
  61.   Serial.print(humidity);
  62.   Serial.print("%\t");
  63.   Serial.print("Temperature: ");
  64.   Serial.print(temperature);
  65.   Serial.println("°C");
  66.  
  67.   // Check if temperature is above 28 degrees and turn on the fan.
  68.   if (temperature > 28) {
  69.     digitalWrite(Fan_PIN, HIGH);
  70.   } else {
  71.     digitalWrite(Fan_PIN, LOW);
  72.   }
  73.  
  74.   delay(2000);
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement