Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

Building a Smart Home Lighting System with Arduino

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:

  • Arduino Uno (1)
  • Relay Module (1)
  • ESP8266 Wi-Fi Module (1)
  • Light Bulb (1)
  • Bulb Holder (1)
  • Jumper Wires (10)
  • Breadboard (1)
  • 10kΩ Resistor (1)
  • NPN Transistor (1)
  • Diode (1)
  • Power Supply (1)

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:

  1. Libraries and Pin Definitions: The code begins by including the necessary libraries for Wi-Fi and web server functionalities. It defines the pin connected to the relay module.
  2. Wi-Fi Credentials: Replace your_SSID and your_PASSWORD with your actual Wi-Fi network credentials.
  3. Web Server Setup: The 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.
  4. Setup Function: Initializes the serial communication, sets the relay pin as an output, connects to the Wi-Fi network, and starts the web server.
  5. Loop Function: Continuously handles incoming client requests.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.