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: "Temperature Control"
- - Source Code compiled for: Arduino Uno
- - Source Code created on: 2024-01-02 09:16:10
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Read temperature and humidity. Turn on fan when */
- /* temperature rises above 28 degrees */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h>
- #include <DHT.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Temp_DHT11_DOUT_PIN_D2 = 2;
- const uint8_t Fan_PIN = 3;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- DHT dht(Temp_DHT11_DOUT_PIN_D2, DHT11);
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(Temp_DHT11_DOUT_PIN_D2, INPUT_PULLUP);
- pinMode(Fan_PIN, OUTPUT);
- dht.begin();
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- float humidity = dht.readHumidity();
- float temperature = dht.readTemperature();
- // Check if any reads failed and exit early (to try again).
- if (isnan(humidity) || isnan(temperature)) {
- Serial.println("Failed to read from DHT sensor!");
- return;
- }
- // Print temperature and humidity values.
- Serial.print("Humidity: ");
- Serial.print(humidity);
- Serial.print("%\t");
- Serial.print("Temperature: ");
- Serial.print(temperature);
- Serial.println("°C");
- // Check if temperature is above 28 degrees and turn on the fan.
- if (temperature > 28) {
- digitalWrite(Fan_PIN, HIGH);
- } else {
- digitalWrite(Fan_PIN, LOW);
- }
- delay(2000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement