How to Build a DIY Arduino Home Automation System

DIY Electronics
Date:June 4, 2026
Topic:
How to Build a DIY Arduino Home Automation System
2 min read

How to Build a DIY Arduino Home Automation System

Imagine flipping a light switch with your voice, setting the thermostat from your phone, and never worrying about a forgotten appliance again. All it takes is an Arduino, a few sensors, and a dash of curiosity.

What You’ll Need

ComponentQtyTypical Cost
Arduino Uno (or Nano)1$22
Relay Module (5V)2$8
DHT22 Temperature/Humidity Sensor1$5
HC‑SR04 Ultrasonic Sensor1$3
Breadboard & Jumper Wires1$7
ESP8266 Wi‑Fi Module1$6
Power Supply (5V 2A)1$10
ℹ️
NoteAll parts are available on major electronics retailers; consider buying a starter kit to save on shipping.

Step‑by‑Step Wiring

  1. Mount the Arduino on the breadboard and connect the 5V and GND rails.
  2. Wire each relay’s IN pin to digital pins D2 and D3; connect the relay COM to the appliance’s live wire and NO to the appliance’s neutral.
  3. Attach the DHT22 data pin to D4 and power it with 3.3V.
  4. Hook the HC‑SR04 trig to D5 and echo to D6.
  5. Plug the ESP8266 TX/RX to D7/D8 (use a voltage divider for TX).
cpp
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <DHT.h>
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup(){Serial.begin(115200); dht.begin();}
void loop(){float t=dht.readTemperature(); float h=dht.readHumidity(); Serial.println(String(t)+","+String(h)); delay(5000);}
"

The best projects start simple—once you see the lights respond, you’ll want to add more sensors.

Alex Rivera, Maker Community

Programming the Logic

Upload the sketch below. It reads temperature/humidity, detects motion with the ultrasonic sensor, and exposes a JSON endpoint over Wi‑Fi. Your phone or Home Assistant can call /control?relay=1&state=on to toggle lights.

cpp
#include <ESP8266WebServer.h>
ESP8266WebServer server(80);
void handleControl(){int r=server.arg("relay").toInt();int s=server.arg("state").toInt();digitalWrite(r+1, s==1?LOW:HIGH);server.send(200,"text/plain","OK");}
void setup(){pinMode(2,OUTPUT);pinMode(3,OUTPUT);digitalWrite(2,HIGH);digitalWrite(3,HIGH);WiFi.begin("SSID","PASS");while(WiFi.status()!=WL_CONNECTED)delay(500);server.on("/control",handleControl);server.begin();}
void loop(){server.handleClient();}


💡
TipSecure your relays behind a non‑conductive enclosure to avoid accidental shorts.

Testing & Expanding

  • Open a browser at http://arduino-ip/control?relay=1&state=1 and watch the lamp turn on.
  • Add more relays for fans, door locks, or garden irrigation.
  • Integrate MQTT for real‑time home‑assistant control.
"

Automation is just a habit you program into your home.

Mia Chen, IoT Enthusiast

Take Action

Grab the components, follow the wiring diagram, and fire up the code. Within an hour you’ll have a functional smart switch. Then, iterate: add voice commands, schedule routines, or build a dashboard. The only limit is your imagination.

Share𝕏 Twitterin LinkedInin Whatsapp