Having smart home devices can make life more convenient and efficient. One simple way to get started with home automation is by building your own smart light switch using an Arduino microcontroller board. With just a few common electronic components, you can make a voice-activated or app-controlled light switch in about 10 minutes.

What You Will Need

To build this simple DIY smart light switch, you will need:

Step-by-Step Instructions

Follow these steps to build your own smart light switch using an Arduino:

1. Connect the relay module

2. Connect the light bulb

3. Load the Arduino program

// Smart Light Switch Demo

int relayPin = 12; //control pin for relay module

void setup() {

pinMode(relayPin, OUTPUT);


void loop() {

digitalWrite(relayPin, HIGH); //turn light ON


digitalWrite(relayPin, LOW); //turn light OFF



4. Control wirelessly via WiFi (optional)


WiFi Smart Light Switch

Turns relay on and off wirelessly

using a webpage button or smartphone app



const char* ssid = "yourNetworkName"; // SSID of local network

const char* password = "yourWifiPassword"; // WiFi password

WiFiServer server(80); // Set web server port number to 80

const int relayPin = 12; // Set relay control pin

int relayState = LOW; // State of relay

void setup() {


pinMode(relayPin, OUTPUT);

digitalWrite(relayPin, relayState);

// Connect to WiFi



Serial.print("Connecting to ");


WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {





Serial.println("WiFi connected");

Serial.println("IP address: ");


server.begin(); // Start the web server


void loop(){

WiFiClient client = server.available(); // Check for client connections

if (client) { // If a client connects

String request = client.readStringUntil('\r'); // Read request


client.flush(); // Clear input buffer

if (request.indexOf("/RELAYON") != -1) {

  digitalWrite(relayPin, HIGH); // Turn relay ON

  relayState = HIGH;


if (request.indexOf("/RELAYOFF") != -1) {

  digitalWrite(relayPin, LOW); // Turn relay OFF

  relayState = LOW;


// Return response to client

client.println("HTTP/1.1 200 OK");

client.println("Content-Type: text/html");

client.println(""); //  do not forget this one

client.println("<!DOCTYPE HTML>");


client.print("Relay is now: ");

if(relayState==HIGH) {


} else {




client.println("<a href=\"/RELAYON\"\"><button>Turn On </button></a>");

client.println("<a href=\"/RELAYOFF\"\"><button>Turn Off </button></a><br />");


delay(1); // Delay 1 msec to allow web page to load

client.stop(); // Close connection


That's it! In just 10 minutes you now have a fully functioning DIY WiFi-enabled smart light switch using Arduino. You can expand on this project by adding home automation software, voice control, multiple relays to control more devices, and more. The possibilities are endless!

Going Further with Your Smart Light Switch

Looking to take your new smart switch to the next level? Here are some ideas:

By combining an Arduino board, a few electronic components, and your own creativity, you can build an inexpensive yet powerful smart light switch to bring automation and convenience to your home lighting.