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: "Climate Control" - Source Code NOT compiled for: Arduino Uno - Source Code created on: 2024-06-30 03:07:25 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* sensor DHT22 untuk suhu dan kelembapan, dan LED */ /* RGB. Gunakan LCD untuk menampilkan suhu dan */ /* kelembapan. Kontrol LED RGB berdasarkan ambang */ /* batas suhu. jika suhu rendah berwarna hijau dan */ /* jika suhu tinggi warna merah */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include
#include
//https://github.com/marcoschwartz/LiquidCrystal_I2C #include
//https://github.com/adafruit/DHT-sensor-library /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void updateOutputs(void); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t DHT22_DOUT_PIN_D5 = 5; /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t led1_LEDRGB_Red_PIN_D3 = 3; const uint8_t led1_LEDRGB_Green_PIN_D4 = 4; /***** DEFINITION OF I2C PINS *****/ const uint8_t lcd_LCD1602I2C_I2C_PIN_SDA_A4 = A4; const uint8_t lcd_LCD1602I2C_I2C_PIN_SCL_A5 = A5; const uint8_t lcd_LCD1602I2C_I2C_SLAVE_ADDRESS = 0x27; // 39 in decimal /***** DEFINITION OF OUTPUT RAW VARIABLES *****/ /***** used to store raw data *****/ bool led1_LEDRGB_Red_PIN_D3_rawData = 0; bool led1_LEDRGB_Green_PIN_D4_rawData = 0; /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/ /***** used to store data after characteristic curve transformation *****/ float led1_LEDRGB_Red_PIN_D3_phyData = 0.0; float led1_LEDRGB_Green_PIN_D4_phyData = 0.0; /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ LiquidCrystal_I2C lcd(lcd_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // Initialize the LCD with address, columns, and rows #define DHTTYPE DHT22 // DHT 22 (AM2302) DHT dht(DHT22_DOUT_PIN_D5, DHTTYPE); // Initialize DHT sensor for DHT22 void setup(void) { // put your setup code here, to run once: pinMode(DHT22_DOUT_PIN_D5, INPUT_PULLUP); pinMode(led1_LEDRGB_Red_PIN_D3, OUTPUT); pinMode(led1_LEDRGB_Green_PIN_D4, OUTPUT); lcd.init(); // Initialize the LCD lcd.backlight(); // Turn on the backlight lcd.setCursor(0, 0); // Set cursor to column 0, row 0 lcd.print("Hello, world!"); // Print a message to the LCD dht.begin(); // Initialize the DHT sensor Serial.begin(9600); // Initialize serial communication } void loop(void) { // put your main code here, to run repeatedly: updateOutputs(); // Refresh output data delay(2000); // Wait a few seconds between measurements float h = dht.readHumidity(); // Read humidity float t = dht.readTemperature(); // Read temperature as Celsius // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t)) { Serial.println(F("Failed to read from DHT sensor!")); return; } // Print the results to the Serial Monitor Serial.print(F("Humidity: ")); Serial.print(h); Serial.print(F("% Temperature: ")); Serial.print(t); Serial.println(F("°C")); // Update LCD display lcd.clear(); lcd.setCursor(0, 0); lcd.print("Temp: "); lcd.print(t); lcd.print(" C"); lcd.setCursor(0, 1); lcd.print("Humidity: "); lcd.print(h); lcd.print(" %"); // Control RGB LED based on temperature if (t < 25.0) { // Temperature is low, turn on green LED led1_LEDRGB_Green_PIN_D4_rawData = HIGH; led1_LEDRGB_Red_PIN_D3_rawData = LOW; } else { // Temperature is high, turn on red LED led1_LEDRGB_Green_PIN_D4_rawData = LOW; led1_LEDRGB_Red_PIN_D3_rawData = HIGH; } updateOutputs(); // Refresh output data } void updateOutputs() { digitalWrite(led1_LEDRGB_Red_PIN_D3, led1_LEDRGB_Red_PIN_D3_rawData); digitalWrite(led1_LEDRGB_Green_PIN_D4, led1_LEDRGB_Green_PIN_D4_rawData); } /* 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)