Advertisement
pleasedontcode

Smart Gardening rev_01

Apr 21st, 2024
82
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: Smart Gardening
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-04-21 23:58:29
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* I need that when the sensor detects a certain */
  21.     /* humidity it will water my plants. */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <DHT.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  32. const uint8_t DHTPIN = 2;
  33. const uint8_t DHTTYPE = DHT22; // Define the type of DHT sensor (DHT11, DHT22, etc.)
  34.  
  35. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  36. DHT dht(DHTPIN, DHTTYPE);
  37.  
  38. void setup(void)
  39. {
  40.   // put your setup code here, to run once:
  41.   Serial.begin(9600);
  42.   dht.begin();
  43. }
  44.  
  45. void loop(void)
  46. {
  47.   // put your main code here, to run repeatedly:
  48.   delay(dht.getMinimumSamplingPeriod());
  49.  
  50.   sensors_event_t event;
  51.  
  52.   dht.temperature().getEvent(&event);
  53.   if (isnan(event.temperature))
  54.   {
  55.     Serial.println(F("Error reading temperature!"));
  56.   }
  57.   else
  58.   {
  59.     Serial.print(F("Temperature: "));
  60.     Serial.print(event.temperature);
  61.     Serial.println(F("°C"));
  62.    
  63.     // Check if the humidity is above a certain threshold to water the plants
  64.     if (event.relative_humidity > 60) // Adjust the threshold value as needed
  65.     {
  66.       // Water the plants
  67.       Serial.println(F("Watering the plants!"));
  68.     }
  69.   }
  70.  
  71.   dht.humidity().getEvent(&event);
  72.   if (isnan(event.relative_humidity))
  73.   {
  74.     Serial.println(F("Error reading humidity!"));
  75.   }
  76.   else
  77.   {
  78.     Serial.print(F("Humidity: "));
  79.     Serial.print(event.relative_humidity);
  80.     Serial.println(F("%"));
  81.   }
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement