Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/********* 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-04 02:01:26 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* This project focuses on integrating various */ /* sensors and actuators with Arduino to create a */ /* responsive environment, enhancing interaction and */ /* functionality in real-time applications. */ /****** END SYSTEM REQUIREMENTS *****/ /* START CODE */ /****** DEFINITION OF LIBRARIES *****/ #include
// Include Wire library for I2C communication #include
// Include Servo library for controlling servo motors #include
// Include DHT library for temperature and humidity sensor /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /****** GLOBAL VARIABLES *****/ DHT dht(2, DHT11); // Initialize DHT sensor on pin 2 with DHT11 type 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 values 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 if (temperature > 25) { myServo.write(180); // Move servo to 180 degrees if temperature is above 25°C } else { myServo.write(0); // Move servo to 0 degrees if temperature is below or equal to 25°C } // Wait a few seconds between measurements delay(2000); } /* END CODE */
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)