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

ESP8266 and HC-05 Bluetooth-Based Home Automation System with 4-Channel Relay Control

View and Edit Project In Cirkit DesignerImage of ESP8266 and HC-05 Bluetooth-Based Home Automation System with 4-Channel Relay Control

Circuit Documentation

Summary

This circuit is a Bluetooth-based Home Automation System that allows control of a 4-channel relay module using an ESP8266 NodeMCU and an HC-05 Bluetooth module. The relays can be controlled via Bluetooth commands or by pressing the connected pushbuttons. The system also includes pilot lamps to indicate the status of the relays.

Component List

  1. 4 Channel Relay Module

    • Description: A module with four relays that can be controlled individually.
    • Pins: N.O. 4, COM 4, N.C. 4, N.O. 3, COM 3, N.C. 3, N.O. 2, COM 2, N.C. 2, N.O. 1, COM 1, N.C. 1, Pin 13, Pin 14, Pin 15, Pin 16, Pin 17, Pin 18, Pin 19, Pin 20, Pin 21, Pin 22, Pin 23, Pin 24, VCC+, VCC- (GND), IN 1, IN 2, IN 3, IN 4
  2. ESP8266 NodeMCU

    • Description: A microcontroller with built-in Wi-Fi capabilities.
    • Pins: D0, D1, D2, D3, D4, 3V3, GND, D5, D6, D7, D8, RX, TX, A0, RSV, SD3, SD2, SD1, CMD, SD0, CLK, EN, RST, VIN
  3. Pushbutton

    • Description: A simple pushbutton switch.
    • Pins: Pin 3 (out), Pin 4 (out), Pin 1 (in), Pin 2 (in)
  4. Pilot Lamp Blue

    • Description: A blue pilot lamp used for indication.
    • Pins: x1, x2
  5. HC-05 Bluetooth Module

    • Description: A Bluetooth module for wireless communication.
    • Pins: Key, VCC, TXD, RXD, State, GND
  6. Power 220V

    • Description: A 220V power source.
    • Pins: hot wire, neutral wire
  7. 240V Power Source

    • Description: A 240V power source.
    • Pins: Live, Neutral
  8. Resistor

    • Description: A resistor with a resistance of 200 Ohms.
    • Pins: pin1, pin2
  9. LED: Two Pin (Red)

    • Description: A red LED.
    • Pins: cathode, anode
  10. LM340T5 7805

    • Description: A voltage regulator.
    • Pins: Vout, Vin, GND

Wiring Details

4 Channel Relay Module

ESP8266 NodeMCU

Pushbutton

Pilot Lamp Blue

HC-05 Bluetooth Module

Power 220V

240V Power Source

Resistor

LED: Two Pin (Red)

LM340T5 7805

Code Documentation

/*
 * Bluetooth-based Home Automation System
 * This code allows control of a 4-channel relay module using an ESP8266 NodeMCU
 * and an HC-05 Bluetooth module. The relays can be controlled via Bluetooth
 * commands or by pressing the connected pushbuttons.
 */

#include <SoftwareSerial.h>

// Pin definitions
#define RELAY1_PIN D2
#define RELAY2_PIN D1
#define RELAY3_PIN D5
#define RELAY4_PIN D6
#define BUTTON1_PIN D3
#define BUTTON2_PIN D4
#define BUTTON3_PIN D7
#define BUTTON4_PIN D8

// Bluetooth module pins
#define BT_RX_PIN RX
#define BT_TX_PIN TX

SoftwareSerial BTSerial(BT_RX_PIN, BT_TX_PIN); // RX, TX

void setup() {
  // Initialize serial communication
  Serial.begin(9600);
  BTSerial.begin(9600);

  // Initialize relay pins as outputs
  pinMode(RELAY1_PIN, OUTPUT);
  pinMode(RELAY2_PIN, OUTPUT);
  pinMode(RELAY3_PIN, OUTPUT);
  pinMode(RELAY4_PIN, OUTPUT);

  // Initialize button pins as inputs
  pinMode(BUTTON1_PIN, INPUT);
  pinMode(BUTTON2_PIN, INPUT);
  pinMode(BUTTON3_PIN, INPUT);
  pinMode(BUTTON4_PIN, INPUT);

  // Turn off all relays initially