Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-Controlled Relay with Bluetooth for Smart Home Automation

View and Edit Project In Cirkit DesignerImage of ESP32-Controlled Relay with Bluetooth for Smart Home Automation

Circuit Documentation

Summary

This circuit is designed to control a series of LEDs and a fan using an ESP32 Wroom Dev Kit microcontroller. The ESP32 is programmed to communicate via Bluetooth, allowing for wireless control of the connected devices. The circuit includes a 4-channel relay module to switch higher loads that the ESP32 cannot directly drive. The LEDs are connected through resistors to limit the current, and the fan is powered by a 5V supply. The ESP32 controls the relay module, which in turn controls the power to the LEDs and the fan.

Component List

Relay 4 Channel 5v

LED: Two Pin (red)

Fan

ESP 32 Wroom Dev Kit

Resistor

Wiring Details

Relay 4 Channel 5v

LED: Two Pin (red)

Fan

ESP 32 Wroom Dev Kit

Resistor

Documented Code

#include <BluetoothSerial.h>

BluetoothSerial ESP_BT;

int lamp1 = 16;  // GPIO for Lamp 1
int lamp2 = 17;  // GPIO for Lamp 2
int lamp3 = 18;  // GPIO for Lamp 3
int fan = 27;    // GPIO for Fan

void setup() {
  Serial.begin(9600);
  ESP_BT.begin("ESP32_Control");  // Bluetooth device name

  // Set pins as OUTPUT
  pinMode(lamp1, OUTPUT);
  pinMode(lamp2, OUTPUT);
  pinMode(lamp3, OUTPUT);
  pinMode(fan, OUTPUT);
}

void loop() {
  if (ESP_BT.available()) {
    char command = ESP_BT.read();
    switch (command) {
      case '1': digitalWrite(lamp1, HIGH); break; // Turn on Lamp 1
      case '2': digitalWrite(lamp1, LOW); break;  // Turn off Lamp 1
      case '3': digitalWrite(lamp2, HIGH); break; // Turn on Lamp 2
      case '4': digitalWrite(lamp2, LOW); break;  // Turn off Lamp 2
      case '5': digitalWrite(lamp3, HIGH); break; // Turn on Lamp 3
      case '6': digitalWrite(lamp3, LOW); break;  // Turn off Lamp 3
      case '7': digitalWrite(fan, HIGH); break;   // Turn on Fan
      case '8': digitalWrite(fan, LOW); break;    // Turn off Fan
    }
  }
}

This code snippet is responsible for setting up the ESP32's Bluetooth functionality and configuring the GPIO pins to control the relay module. The loop function listens for incoming Bluetooth commands and toggles the corresponding GPIO pins to control the LEDs and the fan.