Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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: Temperature Monitor
- - Source Code compiled for: Arduino Uno
- - Source Code created on: 2023-12-29 00:33:51
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Leer la temperatura y la humedad y escribirla en */
- /* el display LCD cada 1s. Si la temperatura supera */
- /* los 40°C entonces encienda el zumbador, si no */
- /* apague el zumbador. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <DHT.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup();
- void loop();
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t DHTPIN = 3;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t BUZZERPIN = 4;
- /***** DEFINITION OF I2C PINS *****/
- const uint8_t I2C_PIN_SDA = A4;
- const uint8_t I2C_PIN_SCL = A5;
- const uint8_t I2C_SLAVE_ADDRESS = 39;
- /****** DEFINITION OF LIBRARY CLASS INSTANCES *****/
- DHT dht(DHTPIN, DHT11);
- LiquidCrystal_I2C lcd(I2C_SLAVE_ADDRESS, 16, 2);
- void setup()
- {
- pinMode(DHTPIN, INPUT_PULLUP);
- pinMode(BUZZERPIN, OUTPUT);
- dht.begin();
- lcd.begin(16, 2);
- lcd.backlight();
- }
- void loop()
- {
- float humidity = dht.readHumidity();
- float temperature = dht.readTemperature();
- if (isnan(humidity) || isnan(temperature))
- {
- Serial.println(F("Failed to read from DHT sensor!"));
- return;
- }
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Temp: ");
- lcd.print(temperature);
- lcd.print("C");
- lcd.setCursor(0, 1);
- lcd.print("Humidity: ");
- lcd.print(humidity);
- lcd.print("%");
- if (temperature > 40)
- {
- digitalWrite(BUZZERPIN, HIGH);
- }
- else
- {
- digitalWrite(BUZZERPIN, LOW);
- }
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement