सोमवार, १२ जून, २०१७

Arduino Bluetooth HC-05 Interfacing

                                            
                      Arduino Bluetooth HC-05 Interfacing 

Arduino bluetooth hc05 module interfacing and controlling it from a smartphone (android) is a great idea. After learning this interface a bluetooth module operates at Scientific and Medical (ISM) 2.4GHz short-range radio frequency band. Bluetooth uses frequency-hopping spread spectrum This type of bluetooth has a range around 30 meters.
There is a different bluetooth module in the market for hobby and embedded system development. We are using HC 05 bluetooth module in this tutorial.

In this tutorial, we interface bluetooth module to the arduino and one LED at digital pin 13. An android device will be paired to HC-05, and by some android app we switch ON and OFF the led.

Description

The hc-05 bluetooth module has six pins Vcc, GND, RX, TX, Key and State. By default, this is a slave device.
Hc 05 bluetooth



But if you want to send something from this module then we need to change it from the main mode. If we are connecting HC 05 with the Android phone we just use it in Slave Mode. The default transfer rate will be 9600 baud rate. The HC-05 module has a factory set pin "1234" which is used for pairing to the phone.




Bluetooth hc05 pinout










Hardware Required

  • Arduino Uno
  • Bluetooth Module HC 05
  • LED
  • Resistor 220 ohm
  • Breadboard

Arduino Bluetooth Connection

Arduino and bluetooth hc05 serial connection is made. For This project, They Should Knov  Arduino serial communication .

Bluetooth connection with arduino


13. Arduino already has a led at pin 13 But we are going to understand here

Arduino Android Bluetooth App

There is a different arduino android bluetooth app for controlling the arduino from the android. We have used  Bluetooth Controller App  developed by FineApps because we are using a long time and it's very easy to understand. You can configure this application

Arduino Bluetooth App

You can easily see that all the buttons are empty and we can edit according to the project.

Arduino Bluetooth Controller AppSo press button "SET KEYS"
A new window will open:
Key Name:  Led ON and Led OFF => This is button Text
Key Value:  => A and B respectively, this key value sends via bluetooth of android to HC-05 module Now press OK.

Arduino Bluetooth Controller App

Now connect the bluetooth module as shown above and then supply it. Pair the HC-05 device with the mobile It is just like we pair the other mobiles. The passkey is "1234". Once you've got the bluetooth controller app pressing the button "SCAN".

Arduino Bluetooth Controller App

And its Done! Now we write some code to arduino that ON and OFF the LED by accepting 'A' for "ON" and "B" for "OFF".

Arduino Bluetooth HC-05 Code

By this bluetooth programming, we can create different arduino bluetooth projects.
Here the function  Serial.available() is used to monitor the incoming character 'A' and 'B'. This function will be true if it gets anything from the serial port. Once it gets some value it checks whether it is coming from the Led ON or LED OFF button and according to take decision.

/ * In this program, a user controls the Led by ON and OFF the button.
Each switch has a key value so the arduino can identify based on the key.
Button Key Value
Led ON 'A'
Led OFF 'B'
* /
Int  ledPin  =  13 ;                  // LED connected to digital pin 13 
char  read_bt ;

Void  setup ( )  { 
  pinMode ( ledPin ,  OUTPUT ) ;       // the digital pin us Output Sets 
  serial . Begin ( 9600 ) ;      // opens serial port, sets data rate to 9600 bps 
}

Void  loop ( )  {  
  If  ( serial . Available ( )  >  0 )  { 
  were // read incoming byte: 
  Reed_bt  =  Serial . Read ( ) ; 
  If ( read_bt == 'A' ) 
   digitalWrite ( ledPin ,  HIGH ) ;    // sets the LED on

   If ( read_bt == 'B' ) 
   digitalWrite ( ledPin ,  LOW ) ;     // sets the LED off 
  } 
}

0 टिप्पणी(ण्या):

टिप्पणी पोस्ट करा