Jump to content

IPDL - 9: Web-Based Home Automation Using Arduino Uno and Bluetooth

From cognifront

IPDL - 9: Bluetooth-Based Home Automation Using Arduino Uno and HC-05

Objective

To control a relay-based electrical appliance using an Arduino Uno and an HC-05 Bluetooth module through a Bluetooth-enabled smartphone.

Required Components

  • Arduino Uno
  • HC-05 Bluetooth module
  • Single-channel relay module
  • AC bulb with suitable bulb holder
  • 3-pin socket provided with the relay module
  • Suitable insulated electrical wire
  • Smartphone with a Bluetooth terminal/control application
  • Jumper wires

Circuit Diagram

Board Connections

Pin Connections

Component Component Pin Arduino Uno Connection
HC-05 TXD Digital Pin 10 (BT_RX)
RXD Digital Pin 11 (BT_TX)
VCC 5V
GND GND
Single-Channel Relay IN Digital Pin 7
VCC 5V
GND GND

Important: The HC-05 RX input is a 3.3 V logic input. For a production-safe connection, use an appropriate voltage divider or logic-level shifter between Arduino Digital Pin 11 and HC-05 RXD.

Note: The relay module used in this experiment is active LOW. Therefore:

  • `LOW` on Digital Pin 7 → Relay ON
  • `HIGH` on Digital Pin 7 → Relay OFF

Connecting the Bulb to the 3-Pin Socket

The relay can be used to control an AC bulb or other suitable electrical appliance. A 3-pin socket is provided with the setup for connecting the appliance.

WARNING: AC MAINS HAZARD

AC mains voltage can cause serious electric shock, injury, fire, or death. The mains wiring must be carried out only by a qualified person or under appropriate laboratory supervision. Always disconnect the mains supply before making or changing any wiring.

Bluetooth Setup

The HC-05 provides wireless serial communication between the Arduino Uno and a smartphone.

  1. Turn ON Bluetooth on the smartphone.
  2. Search for nearby Bluetooth devices.
  3. Select HC-05.
  4. When prompted for a PIN, enter:
1234
  1. After successful pairing, open a Bluetooth serial terminal or Bluetooth control application.
  2. Connect the application to the paired HC-05 module.

The smartphone can now send commands to the Arduino through the HC-05.

Working Principle

The HC-05 communicates with the Arduino Uno using serial communication through the SoftwareSerial library.

The HC-05 is connected to Arduino Digital Pins 10 and 11.

  • Digital Pin 10 is used as the Arduino's Bluetooth receive pin.
  • Digital Pin 11 is used as the Arduino's Bluetooth transmit pin.
  • Digital Pin 7 controls the relay module.

Commands received from the smartphone are collected by the Arduino and processed when a newline or carriage-return character is received.

The received command is:

  1. Trimmed to remove unwanted spaces.
  2. Converted to uppercase.
  3. Compared with the predefined commands.
  4. Used to control the relay.

This allows commands to be sent in different combinations of uppercase and lowercase letters.

For example:

ON
on
On
oN

All of the above are interpreted as the ON command.

Similarly:

OFF
off
Off
oFf

are all interpreted as the OFF command.

Bluetooth Commands

Command Relay Action Appliance
ON Relay Activated Bulb ON
OFF Relay Deactivated Bulb OFF

Note: The commands are case-insensitive. Commands such as `ON`, `on`, `On` and `oN` are treated identically.

Experiment Code

// © 2026, Cognifront. Member of The IoT Kits Family.

// Experiment: Bluetooth Home Automation using Arduino Uno
// HC-05 + Relay

#include <SoftwareSerial.h>

// HC-05
#define BT_RX 10   // Arduino receives from HC-05 TX
#define BT_TX 11   // Arduino sends to HC-05 RX

// Relay
#define RELAY_PIN 7

SoftwareSerial BT(BT_RX, BT_TX);

String command = "";

void setup() {

  Serial.begin(9600);
  BT.begin(9600);

  pinMode(RELAY_PIN, OUTPUT);

  // Active LOW relay: start OFF
  digitalWrite(RELAY_PIN, HIGH);

  Serial.println("Bluetooth Home Automation Ready");

  BT.println("Home Automation Ready");
  BT.println("Send ON or OFF");
}

void loop() {

  // Read Bluetooth data
  while (BT.available()) {

    char c = BT.read();

    if (c == '\n' || c == '\r') {

      if (command.length() > 0) {
        processCommand(command);
        command = "";
      }

    } else {

      command += c;
    }
  }
}

void processCommand(String cmd) {

  // Remove unwanted spaces
  cmd.trim();

  // Convert entire command to UPPERCASE
  cmd.toUpperCase();

  Serial.print("Received Command: ");
  Serial.println(cmd);

  // RELAY ON
  if (cmd == "ON") {

    // Active LOW relay
    digitalWrite(RELAY_PIN, LOW);

    BT.println("RELAY ON");
    Serial.println("Relay ON");
  }

  // RELAY OFF
  else if (cmd == "OFF") {

    digitalWrite(RELAY_PIN, HIGH);

    BT.println("RELAY OFF");
    Serial.println("Relay OFF");
  }

  // INVALID COMMAND
  else {

    BT.println("Invalid Command");
    BT.println("Use ON or OFF");

    Serial.println("Invalid Command");
  }
}

Testing the System

After uploading the program:

  1. Connect the HC-05 Bluetooth module and relay module to the Arduino according to the connection table.
  2. Make sure the relay control circuit is correctly connected.
  3. Connect the bulb to the 3-pin socket.
  4. Ensure that the AC mains wiring has been checked by a qualified person or laboratory supervisor.
  5. Power the Arduino Uno.
  6. Turn ON Bluetooth on the smartphone.
  7. Search for and pair with HC-05.
  8. Enter the pairing PIN 1234 if requested.
  9. Open a Bluetooth terminal/control application.
  10. Connect the application to HC-05.
  11. Send the command ON.
  12. Observe that the relay activates and the connected bulb turns ON.
  13. Send the command OFF.
  14. Observe that the relay deactivates and the connected bulb turns OFF.
  15. Try different command cases such as on, On, oN, off, Off and oFf.

The corresponding relay status message will be displayed in the Bluetooth application.

Observation

  • Sending ON activates the relay and displays `RELAY ON`.
  • Sending OFF deactivates the relay and displays `RELAY OFF`.
  • Sending on, On or oN also activates the relay.
  • Sending off, Off or oFf also deactivates the relay.
  • An unrecognized command displays `Invalid Command`.
  • The relay starts in the OFF state when the Arduino is powered.
  • When the relay is activated, the connected bulb turns ON.
  • When the relay is deactivated, the connected bulb turns OFF.
  • The commands and responses are communicated wirelessly between the smartphone and Arduino through the HC-05.

Result

The relay-controlled bulb was successfully operated wirelessly using an Arduino Uno and HC-05 Bluetooth module. The system responded correctly to ON and OFF commands sent from the smartphone.

Conclusion

This experiment demonstrates Bluetooth-based home automation using Arduino Uno and the HC-05 Bluetooth module.

The HC-05 provides wireless serial communication between a smartphone and Arduino Uno. The Arduino processes commands received from the smartphone and controls an active-LOW relay. The relay can then be used to control a suitable electrical appliance such as an AC bulb.

The experiment demonstrates the basic concept of wireless appliance control without requiring an Internet connection.

Safety Note: The Arduino and HC-05 operate at low voltage, while an AC bulb may operate at hazardous mains voltage. Mains wiring must be performed only by a qualified person or under appropriate laboratory supervision. Always disconnect mains power before modifying the wiring.

Note: This implementation is technically Bluetooth-based home automation rather than Internet- or web-based automation. It does not require an Internet connection.