/********* 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: **Sensor Control** - Source Code NOT compiled for: Arduino Uno - Source Code created on: 2024-11-03 23:33:46 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* The project aims to develop an interactive Arduino */ /* application leveraging connected sensors and */ /* actuators for real-time data acquisition and */ /* control, ensuring seamless integration of modular */ /* libraries for enhanced functionality and user */ /* engagement. */ /****** END SYSTEM REQUIREMENTS *****/ /* START CODE */ /****** DEFINITION OF LIBRARIES *****/ #include // I2C communication #include // SPI communication #include // Control servo motors #include // DHT sensor library /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /****** GLOBAL VARIABLES *****/ DHT dht(2, DHT11); // Initialize DHT sensor on pin 2, using DHT11 Servo myServo; // Create a Servo object void setup(void) { // Initialize serial communication for debugging Serial.begin(9600); // Initialize DHT sensor dht.begin(); // Attach the servo on pin 9 myServo.attach(9); } void loop(void) { // Read temperature and humidity from DHT sensor 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 the results to the serial monitor Serial.print("Humidity: "); Serial.print(humidity); Serial.print(" %\t"); Serial.print("Temperature: "); Serial.print(temperature); Serial.println(" *C"); // Control the servo based on temperature int servoPosition = map(temperature, 0, 40, 0, 180); // Map temperature to servo position myServo.write(servoPosition); // Set servo position // Wait a few seconds between measurements delay(2000); } /* END CODE */