Project Overview & Target Board Variant
If you are researching how to make a home automation system with Arduino, the biggest hurdle is usually networking. Classic boards like the Uno R3 require bulky, unreliable ESP-01 WiFi shields. For this build, the code and wiring specifically target the Arduino Uno R4 WiFi. This variant pairs a Renesas RA4M1 microcontroller with an ESP32-S3 module natively on the board, giving you native 2.4GHz WiFi and hardware-level IoT cloud connectivity without sacrificing the standard Uno pinout.
Hardware Spec Sheet & Pin Mapping
Before cutting wires, verify you have the exact components listed below. Substituting a 12V relay module for a 5V one is the most common reason this build fails on the bench.
| Component | Exact Variant / Specification | Est. Price (2026) |
|---|---|---|
| Microcontroller | Arduino Uno R4 WiFi (ABX00087) | $27.50 |
| Relay Module | 4-Channel 5V Relay (Songle SRD-05VDC-SL-C, Active LOW, Optocoupler isolated) | $6.00 |
| Logic Wiring | 22 AWG Solid Core Hookup Wire | $5.00 |
| Mains Wiring | 12 AWG THHN (Stranded) for 120V/240V AC loads | $4.00 |
| Power Supply | USB-C PD Wall Adapter (5V / 2A minimum) | $10.00 |
Pin Mapping Table
| Arduino Uno R4 WiFi Pin | Relay Module Pin | Function |
|---|---|---|
| 5V | VCC | Relay coil power (Do NOT use 3.3V) |
| GND | GND | Common ground reference |
| D4 | IN1 | Relay 1 Control (Light 1) |
| D5 | IN2 | Relay 2 Control (Light 2) |
| D6 | IN3 | Relay 3 Control (Fan) |
| D7 | IN4 | Relay 4 Control (Outlet) |
Step-by-Step Wiring & Assembly
- Logic Connections: Connect the 22 AWG jumper wires from the Uno R4 WiFi digital pins (D4-D7) to the IN1-IN4 pins on the relay module.
- Power the Relay Coils: Connect the Uno's 5V pin to the relay module's VCC, and GND to GND. Note: The optocouplers on the relay module require 5V logic to trigger reliably. The Uno R4 WiFi operates at 5V on these digital pins, so no logic level shifters are needed.
- Bench Test (Low Voltage): Before touching mains voltage, upload the code below and connect a 12V DC LED strip to the relay's Normally Open (NO) and Common (COM) terminals to verify the logic triggers correctly.
- Mains Hot Wire Routing: Using 12 AWG THHN wire, cut the Hot (Black) wire of your appliance's power cord. Route the source side into the relay's COM terminal, and the load side into the NO terminal.
- Neutral and Ground: Wire the Neutral (White) and Ground (Bare/Green) wires directly to each other using a wire nut or Wago connector. Never switch the neutral or ground through a relay.
- Enclosure: Mount the Uno and relay module in a ventilated, non-conductive project box. Ensure no stray 12 AWG wire strands are near the low-voltage logic pins.
Complete Arduino IoT Cloud Code
This code targets the ArduinoIoTCloud library. Unlike web-editor tutorials that hide configuration in a generated thingProperties.h file, this sketch uses manual property binding so you can compile it directly in the standard Arduino IDE or VS Code.
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
// --- CREDENTIALS & DEVICE CONFIG ---
const char DEVICE_LOGIN_NAME[] = "your-arduino-device-id";
const char SSID[] = "your-wifi-ssid";
const char PASS[] = "your-wifi-password";
const char DEVICE_KEY[] = "your-secret-device-key";
// --- PIN DEFINITIONS ---
const int RELAY_1_PIN = 4;
const int RELAY_2_PIN = 5;
const int RELAY_3_PIN = 6;
const int RELAY_4_PIN = 7;
// --- CLOUD VARIABLES ---
bool cloudLight1;
bool cloudLight2;
bool cloudFan;
bool cloudOutlet;
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
void initProperties() {
ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
ArduinoCloud.addProperty(cloudLight1, READWRITE, ON_CHANGE, onLight1Change);
ArduinoCloud.addProperty(cloudLight2, READWRITE, ON_CHANGE, onLight2Change);
ArduinoCloud.addProperty(cloudFan, READWRITE, ON_CHANGE, onFanChange);
ArduinoCloud.addProperty(cloudOutlet, READWRITE, ON_CHANGE, onOutletChange);
}
void setup() {
Serial.begin(9600);
while (!Serial) { delay(100); }
// Initialize Relay Pins (Active LOW: HIGH = OFF, LOW = ON)
pinMode(RELAY_1_PIN, OUTPUT);
pinMode(RELAY_2_PIN, OUTPUT);
pinMode(RELAY_3_PIN, OUTPUT);
pinMode(RELAY_4_PIN, OUTPUT);
digitalWrite(RELAY_1_PIN, HIGH);
digitalWrite(RELAY_2_PIN, HIGH);
digitalWrite(RELAY_3_PIN, HIGH);
digitalWrite(RELAY_4_PIN, HIGH);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Add local sensor polling or watchdog timers here
}
// --- CALLBACK FUNCTIONS ---
void onLight1Change() {
digitalWrite(RELAY_1_PIN, cloudLight1 ? LOW : HIGH);
}
void onLight2Change() {
digitalWrite(RELAY_2_PIN, cloudLight2 ? LOW : HIGH);
}
void onFanChange() {
digitalWrite(RELAY_3_PIN, cloudFan ? LOW : HIGH);
}
void onOutletChange() {
digitalWrite(RELAY_4_PIN, cloudOutlet ? LOW : HIGH);
}
Debugging: First Three Things to Check When It Fails
When your home automation system fails, do not immediately rewrite the code. Hardware and provisioning mismatches cause 90% of IoT failures. Here are the first three things to check, ranked by likelihood.
1. Error: "ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect"
The Symptom: The serial monitor prints Connection to 'ArduinoIoTCloudTCP' failed or loops on could not connect to iot.arduino.cc.
The Fix: This is almost never a code syntax error. It means the board cannot authenticate with the MQTT broker.
- Verify your
DEVICE_LOGIN_NAMEmatches the Device ID in the Arduino Cloud dashboard exactly (it is case-sensitive). - Ensure your
DEVICE_KEYis the Secret Key generated during device provisioning. You cannot retrieve this key after creation; if you lost it, you must delete and re-provision the device. - Check that your WiFi network is strictly 2.4GHz. The ESP32-S3 on the R4 WiFi will silently fail to associate with a 5GHz-only or WPA3-Enterprise network.
2. Symptom: Relay Clicks, but the Appliance Doesn't Turn On
The Cause: You wired the mains load to the Normally Closed (NC) terminal instead of Normally Open (NO), or the 12 AWG wire isn't seated fully in the relay's screw terminal.
The Fix: De-energize the circuit. Use a multimeter in continuity mode. With the relay OFF (logic HIGH), COM and NC should beep. With the relay ON (logic LOW), COM and NO should beep. Move your load wire to the NO terminal. Tighten the screw terminal until the wire cannot be pulled out by hand.
3. Symptom: Board Resets or USB Disconnects When Relay Engages
The Cause: Power supply brownout. Each relay coil on a standard 4-channel module draws roughly 70mA. Engaging all four relays simultaneously pulls ~280mA just for the coils, plus the ESP32-S3 WiFi transmission spikes (up to 350mA). A standard PC USB port limits at 500mA, causing the voltage to drop below the RA4M1's brownout threshold.
The Fix: Power the Uno R4 WiFi using a dedicated USB-C wall adapter rated for at least 5V / 2A. Do not rely on laptop USB ports for permanent installations.
Extending or Simplifying the Build
Depending on your exact use case, you may need to scale this architecture up or down.
ArduinoIoTCloud library. Instead, use the WiFiServer library to host a local HTML page on the ESP32-S3's IP address. This removes internet dependency but means you can only control the relays when connected to your home LAN.
How to Extend (High-Power Loads): The Songle SRD-05VDC-SL-C relays are rated for 10A at 120V AC. If you are controlling a window AC unit, a well pump, or a water heater that draws 15A+, do not use these relays directly. The contacts will weld shut and fail in the closed position. Instead, use the Arduino relay module to switch the 120V coil of a definite purpose contactor (like a 30A Eaton C25BNF230), and route the heavy appliance load through the contactor's high-current terminals.
Frequently Asked Questions
Can I make a home automation system with Arduino without WiFi?
Yes. If you want to avoid WiFi and cloud dependencies entirely, you can build a localized RF (Radio Frequency) or IR (Infrared) system. By adding a 433MHz RF transmitter/receiver pair (like the SYN115 and SYN480R modules) to an Arduino Uno R3, you can trigger relays using physical remote controls. Alternatively, you can use an Ethernet Shield (W5500) for hardwired LAN control, which is vastly more reliable than WiFi for permanent in-wall installations.
How much does it cost to build an Arduino home automation system?
A basic 4-channel Arduino home automation system costs between $45 and $55 USD for the core electronics (Uno R4 WiFi, relay module, power supply, and wire). However, if you factor in enclosures, 12 AWG THHN wire, Wago connectors, and a flush-mount wall box for a permanent installation, expect the total hardware cost to reach $80 to $100 per node. For multi-room setups, the cost per room drops significantly if you use a single Arduino Mega 2560 with an 8-channel or 16-channel relay board.
Is Arduino or ESP32 better for home automation in 2026?
For standalone, multi-room nodes where cost is the primary driver, the raw ESP32-WROOM-32 dev board is better because it costs under $6. However, if you are learning how to make a home automation system with Arduino and value ease of use, the Arduino Uno R4 WiFi is superior. It offers the robust 5V logic levels required to drive relay modules without logic shifters, standard shield compatibility, and native integration with the Arduino IoT Cloud dashboard, saving hours of MQTT configuration.
How do I control high-power appliances like an AC unit with Arduino?
You must use a contactor or a heavy-duty solid-state relay (SSR). Standard PCB relay modules are rated for 10A resistive loads, but motors and compressors have high inrush currents (Locked Rotor Amps) that can exceed 30A for a fraction of a second. Use your Arduino to trigger a 5V or 12V intermediate relay, which then switches the coil of a 30A or 40A HVAC-rated contactor. Always ensure the appliance circuit is protected by a correctly sized breaker and a GFCI where required by local code.






