APPLIANCE CONTROL USING BLUETOOTH and ARDUINO

In this example we will take command from user through Bluetooth app and control our appliance here led which is connected on arduino pin number. Arduino pin number is set as output so we are control arduino pins according to the user input. Let’s have a look at appliance control using Bluetooth and Arduino

APPLIANCE CONTROL USING BLUETOOTH ARDUINO CODE

Here we are using LED as our appliance

int led = 4;

void setup() {
  // To start UART (serial communication) bus
  Serial.begin(9600);

  // Transmitting  a string from MCU to HC05
  Serial.println("Connection established successfully:");

  // Initialize the LED pin as an output
  pinMode(led, OUTPUT);
}

void loop() {
  // To check if data is available on Serial port
  if (Serial.available() > 0) {

    // To read a data from HC05 via serial communication protocol
    char data = Serial.read() ;

    // If data is capital case 'A' then turn On led and print a message "led is on"
    if (data == 'A') {
      digitalWrite (led, HIGH);
      Serial.println("led is on");
    }
    // If data is small case 'a' then turn Off led and print a message "led is off"
    else if (data == 'a') {
      digitalWrite (led, LOW);
      Serial.println("led is off");
    }
    else {
      Serial.println("Wrong Input");
    }
  }

}

CIRCUIT DIAGRAM

Home Automation using Bluetooth

S.N.

Arduino

HC-05

1.       

+ 5V

+ 5V

2.       

GND

GND

3.       

Rx

Tx

4.       

Tx

Rx

S.N.

Arduino

LED

1.       

4

Anode

2.       

GND

Cathode

 

APPLIANCE CONTROL USING BLUETOOTH ARDUINO CODE EXPLANATION

1. Let’s take a quick look at the code to see how it works. Declared a global variable to assign a output port pin number 4 among digital pins of MCU (ATMEGA328 P-PU).

int led = 4;

2. In this structure namely void setup(), serial communication is initialized by setting a baud rate of 9600 bits per second using begin() built-in function.

After that, Serial.println() built-in function is used to print user defined message (“Connection established successfully: “) is displayed on your phone’s application after successful connection made. At the end in this structure pinMode () built-in function is included to initialize digital pin as an OUTPUT to which 5V based peripheral will be interfaced.

void setup() {
  // To start UART (serial communication) bus
  Serial.begin(9600);

  // Transmitting  a string from MCU to HC05
  Serial.println("Connection established successfully:");

  // Initialize the LED pin as an output
  pinMode(led, OUTPUT);
}

3. In void loop structure read() built-in function is used to receive data from user, which is stored in UART register and fetch by Arduino, bit by bit from UART register.

Received data is stored in the user defined variable “data” of char data type.

In this structure conditional statement is used. If received data is matched with ASCII code of A which is enclosed in single quotation then output will become high and provide 5 volt and 20 mA current and display message “device is on” on mobile phone. If condition is not satisfied it will check else if condition, if satisfied then set output pin low and display a message “device is off” on mobile phone app and if input is neither ‘A’ nor ‘a’ it will display message “Wrong Input”, if and only if HC05 is successfully paired and connected with user phone.

void loop() {
  // To check if data is available on Serial port
  if (Serial.available() > 0) {

    // To read a data from HC05 via serial communication protocol
    char data = Serial.read() ;

    // If data is capital case 'A' then turn On led and print a message "led is on"
    if (data == 'A') {
      digitalWrite (led, HIGH);
      Serial.println("led is on");
    }
    // If data is small case 'a' then turn Off led and print a message "led is off"
    else if (data == 'a') {
      digitalWrite (led, LOW);
      Serial.println("led is off");
    }
    else {
      Serial.println("Wrong Input");
    }
  }

}

// with the help of this program you can design advance project to solve many problems. You can implement home automation, for that 5 volt operated relay is connected at output pin.  

OUTPUT

When user sends capital case “A” from the app it will turn ON the led and gives a message led is on and when user sends small case “a” it will turn OFF the led and gives message led is off.

output bluetooth appliance control

 

Leave a Reply

avatar
  Subscribe  
Notify of

Arduino Tutorials with Basic Electronics: CONTENT

Translate »