Yarana Iot Guru
Published © MIT

🏠 Smart Home Control: Automate 16 Relays with ESP32

Control 16 home appliances using ESP32 with Wi-Fi β€” automate lights, fans, and devices easily! Tutorial by YaranaIoT Guru

BeginnerShowcase (no instructions)8 hours5
🏠 Smart Home Control: Automate 16 Relays with ESP32

Things used in this project

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

πŸ’» ESP32 Sample Code

C/C++
This code allows testing of 16 relays with Wi-Fi control (or MQTT integration for cloud apps):
#include <WiFi.h>
#include <PubSubClient.h> // For MQTT control (optional)

const char* ssid = "YourWiFi";
const char* password = "YourPassword";

int relays[16] = {2, 4, 5, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26};

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nConnected to WiFi!");
  
  for (int i = 0; i < 16; i++) {
    pinMode(relays[i], OUTPUT);
    digitalWrite(relays[i], LOW); // Start OFF
  }
}

void loop() {
  // Example: toggle all relays one by one
  for (int i = 0; i < 16; i++) {
    digitalWrite(relays[i], HIGH);
    delay(500);
    digitalWrite(relays[i], LOW);
    delay(500);
  }
}

Credits

Yarana Iot Guru
15 projects β€’ 0 followers
Yarana Iot Guru Yarana IoT Guru: Arduino, ESP32, GSM, NodeMCU & more. Projects, Tutorials & App Development. Innovate with us!
Thanks to YaranaIoT Guru.

Comments