Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Intelligent Home Control (IHC) systems are becoming increasingly popular in modern homes due to their ability to automate and remotely control various household appliances. Integrating IHC with Arduino allows for a customizable and cost-effective solution for home automation enthusiasts. This article will guide you through the process of creating an IHC system using Arduino, highlighting its importance, and providing detailed instructions for implementation.
Project: The project aims to create a basic IHC system using Arduino to control household appliances such as lights and fans. The objectives are to:
Components List:
Examples:
// Include necessary libraries
#include <ESP8266WiFi.h>
#include <DHT.h>
// Define DHT sensor pin and type
#define DHTPIN 2
#define DHTTYPE DHT11
// Initialize DHT sensor
DHT dht(DHTPIN, DHTTYPE);
// Wi-Fi credentials
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
// Relay pins
const int relay1 = 5; // Light
const int relay2 = 4; // Fan
// Server setup
WiFiServer server(80);
void setup() {
// Start serial communication
Serial.begin(115200);
// Initialize DHT sensor
dht.begin();
// Initialize relay pins as output
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
while (!client.available()) {
delay(1);
}
// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
// Match the request
if (request.indexOf("/relay1/on") != -1) {
digitalWrite(relay1, HIGH);
}
if (request.indexOf("/relay1/off") != -1) {
digitalWrite(relay1, LOW);
}
if (request.indexOf("/relay2/on") != -1) {
digitalWrite(relay2, HIGH);
}
if (request.indexOf("/relay2/off") != -1) {
digitalWrite(relay2, LOW);
}
// Prepare the response
String response = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
response += "<!DOCTYPE HTML>\r\n<html>\r\n";
response += "<h1>Home Automation Control</h1>";
response += "<p>Relay 1 (Light): <a href=\"/relay1/on\">ON</a> <a href=\"/relay1/off\">OFF</a></p>";
response += "<p>Relay 2 (Fan): <a href=\"/relay2/on\">ON</a> <a href=\"/relay2/off\">OFF</a></p>";
response += "</html>\n";
// Send the response to the client
client.print(response);
delay(1);
Serial.println("Client disconnected");
}
Explanation: