Advertisement
pleasedontcode

Temperature Monitor rev_03

Dec 28th, 2023
101
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 Monitor
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-29 00:33:51
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Leer la temperatura y la humedad y escribirla en */
  21.     /* el display LCD cada 1s. Si la temperatura supera */
  22.     /* los 40°C entonces encienda el zumbador, si no */
  23.     /* apague el zumbador. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <Arduino.h>
  28. #include <Wire.h>
  29. #include <LiquidCrystal_I2C.h>
  30. #include <DHT.h>
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup();
  34. void loop();
  35.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t DHTPIN = 3;
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t BUZZERPIN = 4;
  41.  
  42. /***** DEFINITION OF I2C PINS *****/
  43. const uint8_t I2C_PIN_SDA = A4;
  44. const uint8_t I2C_PIN_SCL = A5;
  45. const uint8_t I2C_SLAVE_ADDRESS = 39;
  46.  
  47. /****** DEFINITION OF LIBRARY CLASS INSTANCES *****/
  48. DHT dht(DHTPIN, DHT11);
  49. LiquidCrystal_I2C lcd(I2C_SLAVE_ADDRESS, 16, 2);
  50.  
  51. void setup()
  52. {
  53.   pinMode(DHTPIN, INPUT_PULLUP);
  54.   pinMode(BUZZERPIN, OUTPUT);
  55.  
  56.   dht.begin();
  57.  
  58.   lcd.begin(16, 2);
  59.   lcd.backlight();
  60. }
  61.  
  62. void loop()
  63. {
  64.   float humidity = dht.readHumidity();
  65.   float temperature = dht.readTemperature();
  66.  
  67.   if (isnan(humidity) || isnan(temperature))
  68.   {
  69.     Serial.println(F("Failed to read from DHT sensor!"));
  70.     return;
  71.   }
  72.  
  73.   lcd.clear();
  74.   lcd.setCursor(0, 0);
  75.   lcd.print("Temp: ");
  76.   lcd.print(temperature);
  77.   lcd.print("C");
  78.   lcd.setCursor(0, 1);
  79.   lcd.print("Humidity: ");
  80.   lcd.print(humidity);
  81.   lcd.print("%");
  82.  
  83.   if (temperature > 40)
  84.   {
  85.     digitalWrite(BUZZERPIN, HIGH);
  86.   }
  87.   else
  88.   {
  89.     digitalWrite(BUZZERPIN, LOW);
  90.   }
  91.  
  92.   delay(1000);
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement