Advertisement
pleasedontcode

Thermostat rev_01

Dec 6th, 2023
84
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: Thermostat
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-06 06:40:32
  15.     - Source Code generated by: Nishad
  16.  
  17. ********* Pleasedontcode.com **********/
  18.  
  19. /****** SYSTEM REQUIREMENTS *****/
  20. /****** SYSTEM REQUIREMENT 1 *****/
  21.     /* Turn on cooling if heat index above 40 degree */
  22.     /* celcius */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Arduino.h>
  27. #include "DHT.h"
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32.  
  33. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t DHTPIN = 2;
  35. const uint8_t COOLING_PIN = 3; // Replace with the actual pin number connected to the cooling system relay
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. DHT dht(DHTPIN, DHT22);
  39.  
  40. void setup(void)
  41. {
  42.   // put your setup code here, to run once:
  43.   pinMode(DHTPIN, INPUT_PULLUP);
  44.   pinMode(COOLING_PIN, OUTPUT); // Set the COOLING_PIN as an output
  45.   dht.begin();
  46. }
  47.  
  48. void loop(void)
  49. {
  50.   // put your main code here, to run repeatedly:
  51.  
  52.   float h = dht.readHumidity();
  53.   float t = dht.readTemperature();
  54.   float f = dht.readTemperature(true);
  55.  
  56.   if (isnan(h) || isnan(t) || isnan(f)) {
  57.     Serial.println(F("Failed to read from DHT sensor!"));
  58.     return;
  59.   }
  60.  
  61.   float hif = dht.computeHeatIndex(f, h);
  62.   float hic = dht.computeHeatIndex(t, h, false);
  63.  
  64.   Serial.print(F("Humidity: "));
  65.   Serial.print(h);
  66.   Serial.print(F("%  Temperature: "));
  67.   Serial.print(t);
  68.   Serial.print(F("°C "));
  69.   Serial.print(f);
  70.   Serial.print(F("°F  Heat index: "));
  71.   Serial.print(hic);
  72.   Serial.print(F("°C "));
  73.   Serial.print(hif);
  74.   Serial.println(F("°F"));
  75.  
  76.   /****** SYSTEM REQUIREMENTS *****/
  77.   /****** SYSTEM REQUIREMENT 1 *****/
  78.   /* Turn on cooling if heat index above 40 degree */
  79.   /* celcius */
  80.   if (hif > 40) {
  81.     // Code to turn on cooling
  82.     digitalWrite(COOLING_PIN, HIGH);
  83.   }
  84.   /****** END SYSTEM REQUIREMENTS *****/
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement