Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
In today's world, smart home technology is becoming increasingly popular. One of the simplest and most impactful projects you can undertake is creating a smart home lighting system using Arduino. This project allows you to control your home's lighting remotely, automate lighting schedules, and even integrate with voice assistants. This article will guide you through the process of building a smart home lighting system, detailing the components you'll need, providing step-by-step instructions, and sharing the necessary code to get your system up and running.
Project: The objective of this project is to create a smart home lighting system that can be controlled via a smartphone app or a web interface. The functionalities include turning lights on and off, dimming lights, and setting automated lighting schedules. This project will use an Arduino board, a relay module, and a few other components to control a standard home light bulb. The system will be connected to a Wi-Fi network, allowing for remote control and automation.
Components List:
Examples:
// Include necessary libraries
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
// Define pin connections
const int relayPin = 5; // D1 on ESP8266
// Wi-Fi credentials
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
// Create a web server on port 80
ESP8266WebServer server(80);
// Function to handle the root URL
void handleRoot() {
String html = "<html><body><h1>Smart Home Lighting System</h1>";
html += "<button onclick=\"location.href='/on'\">Turn On</button>";
html += "<button onclick=\"location.href='/off'\">Turn Off</button>";
html += "</body></html>";
server.send(200, "text/html", html);
}
// Function to turn the light on
void handleOn() {
digitalWrite(relayPin, LOW); // Relay active low
server.send(200, "text/html", "<html><body><h1>Light is ON</h1></body></html>");
}
// Function to turn the light off
void handleOff() {
digitalWrite(relayPin, HIGH); // Relay active low
server.send(200, "text/html", "<html><body><h1>Light is OFF</h1></body></html>");
}
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Set relay pin as output
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH); // Ensure relay is off
// 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.on("/", handleRoot);
server.on("/on", handleOn);
server.on("/off", handleOff);
server.begin();
Serial.println("HTTP server started");
}
void loop() {
// Handle client requests
server.handleClient();
}
Explanation:
your_SSID
and your_PASSWORD
with your actual Wi-Fi network credentials.ESP8266WebServer
object is created to handle HTTP requests. Functions are defined to handle the root URL, turning the light on, and turning the light off.