Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
In this article, we will explore how to create a smart home temperature monitor using an Arduino microcontroller. This project is crucial for anyone interested in home automation, as it allows for real-time temperature monitoring and control. By integrating a temperature sensor with an Arduino, we can gather temperature data and display it on an LCD screen. Additionally, we can set up alerts for specific temperature thresholds. This project is designed to be beginner-friendly and is a great way to get started with Arduino and microcontroller projects.
Project: The objective of this project is to create a smart temperature monitoring system that displays the current temperature on an LCD screen and triggers an alert when the temperature exceeds a predefined threshold. The functionalities include:
Components List:
Examples: Below is the Arduino code for the smart home temperature monitor project. The code reads temperature data from the DHT11 sensor, displays it on the LCD, and turns on an LED if the temperature exceeds 30°C.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
// Define the DHT sensor type and pin
#define DHTTYPE DHT11
#define DHTPIN 2
// Initialize the DHT sensor
DHT dht(DHTPIN, DHTTYPE);
// Initialize the LCD with I2C address 0x27 and 16x2 characters
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Define the LED pin
const int ledPin = 13;
// Set the temperature threshold
const float tempThreshold = 30.0;
void setup() {
// Start the serial communication
Serial.begin(9600);
// Initialize the DHT sensor
dht.begin();
// Initialize the LCD
lcd.begin();
lcd.backlight();
// Set the LED pin as output
pinMode(ledPin, OUTPUT);
// Display a welcome message
lcd.setCursor(0, 0);
lcd.print("Temp Monitor");
delay(2000);
lcd.clear();
}
void loop() {
// Read temperature as Celsius
float temp = dht.readTemperature();
// Check if the reading is valid
if (isnan(temp)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print the temperature to the serial monitor
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" *C");
// Display the temperature on the LCD
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temp);
lcd.print(" C");
// Check if the temperature exceeds the threshold
if (temp > tempThreshold) {
// Turn on the LED
digitalWrite(ledPin, HIGH);
} else {
// Turn off the LED
digitalWrite(ledPin, LOW);
}
// Wait for 2 seconds before the next reading
delay(2000);
}
Code Explanation:
DHT.h
) and the LCD (LiquidCrystal_I2C.h
).setup()
function. The LED pin is set as an output.loop()
function reads the temperature from the DHT sensor and checks if the reading is valid.