For this project, you will require three main components

We are going to connect a bulb and fan to the automation system we are going to build. We will use a smartphone to control the devices via Bluetooth.

The circuit diagram is as follows:

 Circuit Diagram - Arduino Home Automation

The appliance to be connected should be connected on the Normally closed (NC) and GND (or COM) port of the relay. Ensure, the appliance is connected in the order given below:

Home Automation Experiment Connection Diagram

The code required is written below:


#include <SoftwareSerial.h> //Software Serial Library

SoftwareSerial EEBlue(10, 11); // RX | TX

int relayPin1 = 5;

int relayPin2 = 6;

String command;


void setup()



  EEBlue.begin(9600);  //Default Baud for comm, it may be different for your Module.

  Serial.println("The bluetooth gates are open.\n Connect to HC-05 from any other bluetooth device with 1234 as pairing key!.");

  pinMode(relayPin1, OUTPUT);

  pinMode(relayPin2, OUTPUT);

  digitalWrite(relayPin1, HIGH);  //Relay Pins are active LOW

  digitalWrite(relayPin2, HIGH);



void loop()



  // Feed any data from bluetooth to Terminal.

  if (EEBlue.available()){


    String command = EEBlue.readStringUntil("\r\n");



    if (command.indexOf("ON1") >= 0) { //Appliance 1

      digitalWrite(relayPin1, LOW);

      Serial.println("Turning ON Relay 1");



    if (command.indexOf("OFF1") >= 0) {

      digitalWrite(relayPin1, HIGH);

      Serial.println("Turning OFF Relay 1");



    if (command.indexOf("OFF2") >= 0) {

      digitalWrite(relayPin2, HIGH);

      Serial.println("Turning OFF Relay 2");



    if (command.indexOf("ON2") >= 0) {

      digitalWrite(relayPin2, LOW);

      Serial.println("Turning ON Relay 2");



  // Feed all data from terminal to bluetooth

  if (Serial.available())



As alluded to before, this project can easily be implemented on any home appliances or devices you wish to control. You can also modify the code to turn On/Off certain devices at certain times of the day. The possibilities are endless. So, get started and start automating your home!

Leave a comment

Please note, comments must be approved before they are published