Bluetooth based appliance control system using Arduino

Still on the home automation series, in this DIY project, am going to teach you how to build a Bluetooth based appliance control system using Arduino. With the appliance control system, you can control (turn ON or OFF) up to four different home or office appliances using your Android phones.

Required Components

Arduino UNO x1Buy here
JDY31 or HC-05 or HC-06 Bluetooth module x1Buy here
4 Channels Relay Module x1Buy here
AC – DC (220v-5v) module x1Buy here
Solder-less Prototype board and wiresBuy here

The schematic diagram

Bluetooth based appliance control system using Arduino - circuit

The Bluetooth module

The system uses an SPP Bluetooth module, JDY-31. Any equivalent Bluetooth modules working on the same protocol such as the HC-05 and HC-06 Bluetooth modules will also work.

The Bluetooth module has 4 pins, marked Vcc, GND, TXD and RXD. VCC and GND connects to positive and negative respectively. The module sends data through the TXD and receives through the RXD. The Bluetooth module TXD is connected to the Arduino RX pin 0 and the RXD connected to the Arduino TX pin 1.

The TXD and RXD logic pins of the Bluetooth module can only handle 3.3v while Arduino logic pins handles 5v. That means Arduino TX pin 1 will be sending 5v signal to the Bluetooth module’s RXD pin. Hence, to avoid damaging the Bluetooth module, we connected the line between the Arduino TX pin 1 and the Bluetooth module’s RXD pin through a voltage divider made of 1k and 2k resistors. The line between the Bluetooth TXD and the Arduino RX pin 0 can be connected directly as the Bluetooth module is sending 3v which the Arduino can handle.

The 4 Channel Relay module

A 4-channels 5v relay is used in the circuit to switch 4 different appliances ON or OFF. The relays are capable of driving 250v/10A AC load. The Module has 6 pins marked GND, IN1, IN2, IN3, IN4 and VCC. GND and Vcc are the power supply source of the module. IN1 through IN4 are the signal pins. 

The relay module used in this project is an Active LOW. Which means the relay will be energized when a LOW signal is sent to any of the Signal pins of the module,

Each signal pin of the module, IN1, IN2, IN3 and IN4 corresponds to one channel of the relay, hence, each time any of the 4 signal pins received a LOW signal from the Arduino, the corresponding relay is switched ON, which will then turn ON the appliance connected to that channel. Signal pin IN1, IN2, IN3 and IN4 of the relay is connected to the Arduino digital pin 3, 4, 5 and 6 respectively. The Vcc is connected to the 5v pin on the Arduino and GND to any of the GND on the Arduino.

Power Supply Module

220v-5v isolated power supply module is used to power the Arduino board, relay module and the PIR sensor. Positive (+) and negative (-) of the power supply module connects to 5v/ GND of the Arduino board. Life (L) and neutral (N) connects to AC mains.

The Android App

The Android app for the system is designed using MIT App inventor. This is a WYSWYG App development platform that makes designing Android Applications easy by providing an intuitive and Drag-and-drop concept. You can download the Android app for this project on the Download section below or follow HERE to learn how to design your own Android App using the MIT App Inventor.

The sketch (Code)

/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Project: How to control home appliances using smart phone, Bluetooth and Arduino (DIYN BLUETOOTH SWITCH)
Copyright (C) 2020 Obiako Izuchukwu, 
For: Do It Yourself Nigeria
Blog: https://diymall.com.ng/diy-projects/
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/

int appliance_1 = 3;
int appliance_2 = 4;
int appliance_3 = 5;
int appliance_4 = 6;
char command;

void setup() { // put your setup code here, to run once:
  Serial.begin(9600);   //set seria comm baud rate
  //Initialize various pins (3-6) as output
  pinMode(appliance_1,OUTPUT); 
  pinMode(appliance_2,OUTPUT); 
  pinMode(appliance_3,OUTPUT); 
  pinMode(appliance_4,OUTPUT);
} 

void loop() { // put your main code here, to run repeatedly:
  if(Serial.available()){      
    command = Serial.read();
    processCommand(command); 
  }
}

void processCommand(char command){
  switch(command){
    case 'A': //code for switch 1 turned on      
      digitalWrite(appliance_1,LOW);
      break;
    case 'a': //code for switch 1 turned off
      digitalWrite(appliance_1,HIGH);
      break;        
    case 'B': //code for switch 2 turned on
      digitalWrite(appliance_2, LOW);
      break;
     case 'b': //code for switch 2 turned off
      digitalWrite(appliance_2,HIGH);
      break;
    case 'C': //code for switch 3 turned on
      digitalWrite(appliance_3,LOW);
      break;
    case 'c': //code for switch 3 turned off
      digitalWrite(appliance_3,HIGH);
      break;        
    case 'D': //code for switch 4 turned on
      digitalWrite(appliance_4,LOW);
      break;
    case 'd': //code for switch 4 turned off
      digitalWrite(appliance_4,HIGH);
      break;
  }  
}

How we did it

First we declared 4 integer variables, appliance_1 – appliance_4 and assigned the Arduino pins 3-6 to the variables respectively. This represents the Arduino pins where the relay module IN1 – IN4 will be connected. Also we declared another char variable to store the command received by the Arduino from the Bluetooth module.

In the setup method, we set and begin the serial communication.

The Arduino pins 3-6 are initialized as OUTPUT pins through their initially assigned variable.

In the loop, we check if the serial communication is available, and then read it to the variable “command”. Then we call the processCommand() method and pass it the command variable.

The using a switch structure, the processCommand() method compares the value of the command and switches a corresponding relay LOW or HIGH.

Remember: we are using an ACTIVE-LOW relay so, for example, if the value received from the Bluetooth module via the serial communication is “A”, which in our case represents Appliance 1 ON, we set pin 3 of the Arduino to LOW and if the received value is “a” which represents Appliance 1 OFF, we set the Arduino pin 3 to HIGH.

NOTE: When uploading the sketch (code) to your Arduino, you may have to disconnect the Bluetooth module TXD and RXD pins from the Arduino. Because Arduino also uses those pins during this process.

Where to use the Bluetooth based appliance control system

Of course the Bluetooth-based appliance control system can be used to at home as a home automation system to switch ON/OFF up to 4 different appliances within the capability of the relays. The system can as well be used at offices where the user may want to smartly control appliances using his or her android based mobile phones.

Watch it work

Downloads

The Bluetooth Switch Android App

Arduino Sketch