Advertisement
pleasedontcode

"Temperature Display" rev_01

Feb 7th, 2025
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Temperature Display"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-02-07 14:36:51
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Implementar un sistema de notificación que */
  21.     /* enciende un LED si el sensor DHT22 detecta */
  22.     /* temperatura sobre 28°C o humedad sobre 65%, */
  23.     /* asegurando una supervisión constante del entorno. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <dht.h>    //https://github.com/RobTillaart/DHTlib
  30. #include <Wire.h>
  31. #include <LiquidCrystal_I2C.h>
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38.  
  39. // Configura los pines y objetos
  40. #define DHTPIN 2     // Digital pin connected to the DHT sensor
  41. #define DHTTYPE DHT11   // DHT 11
  42. #define LCD_ADDR 0x27  // Dirección I2C del LCD (puede variar)
  43. #define LED_PIN 13     // Pin connected to the LED
  44.  
  45. DHT dht(DHTPIN, DHTTYPE);
  46. LiquidCrystal_I2C lcd(LCD_ADDR, 16, 2);
  47.  
  48. void setup(void)
  49. {
  50.     // put your setup code here, to run once:
  51.     Serial.begin(115200);
  52.    
  53.     // Inicializa el sensor DHT y el LCD
  54.     dht.begin();
  55.     lcd.init();
  56.     lcd.backlight();
  57.    
  58.     // Configura el pin del LED como salida
  59.     pinMode(LED_PIN, OUTPUT);
  60. }
  61.  
  62. void loop(void)
  63. {
  64.     // put your main code here, to run repeatedly:
  65.     // Lee la temperatura y humedad
  66.     float h = dht.readHumidity();
  67.     float t = dht.readTemperature();
  68.  
  69.     // Muestra la información en el LCD
  70.     lcd.clear();
  71.     lcd.setCursor(0, 0);
  72.     lcd.setCursor(10, 0);
  73.     lcd.print("T:");
  74.     lcd.print(t);
  75.     lcd.print("C ");
  76.     lcd.setCursor(10, 1);
  77.     lcd.print("H:");
  78.     lcd.print(h);
  79.     lcd.print("%");
  80.  
  81.     // Verifica las condiciones de temperatura y humedad
  82.     if (t > 28.0 || h > 65.0) {
  83.         digitalWrite(LED_PIN, HIGH); // Enciende el LED
  84.     } else {
  85.         digitalWrite(LED_PIN, LOW); // Apaga el LED
  86.     }
  87.  
  88.     delay(2000);
  89. }
  90.  
  91. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement