Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Smart Gardening
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-04-21 23:58:29
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* I need that when the sensor detects a certain */
- /* humidity it will water my plants. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <DHT.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t DHTPIN = 2;
- const uint8_t DHTTYPE = DHT22; // Define the type of DHT sensor (DHT11, DHT22, etc.)
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- DHT dht(DHTPIN, DHTTYPE);
- void setup(void)
- {
- // put your setup code here, to run once:
- Serial.begin(9600);
- dht.begin();
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- delay(dht.getMinimumSamplingPeriod());
- sensors_event_t event;
- dht.temperature().getEvent(&event);
- if (isnan(event.temperature))
- {
- Serial.println(F("Error reading temperature!"));
- }
- else
- {
- Serial.print(F("Temperature: "));
- Serial.print(event.temperature);
- Serial.println(F("°C"));
- // Check if the humidity is above a certain threshold to water the plants
- if (event.relative_humidity > 60) // Adjust the threshold value as needed
- {
- // Water the plants
- Serial.println(F("Watering the plants!"));
- }
- }
- dht.humidity().getEvent(&event);
- if (isnan(event.relative_humidity))
- {
- Serial.println(F("Error reading humidity!"));
- }
- else
- {
- Serial.print(F("Humidity: "));
- Serial.print(event.relative_humidity);
- Serial.println(F("%"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement