Ex 4
Ex 4
OBJECTIVE:
To understand about the interfacing Arduino to Bluetooth module.
REQUIRED COMPONENTS:
● Arduino UNO
● HC-05 Bluetooth Module
● LED
● Jumper Wires
● Bread Board
● Android App – Arduino Bluetooth Controller
● Arduino IDE
● USB cable for uploading code into Arduino UNO
BACKGROUND THEORY:
Bluetooth Module (HC-05)
The Bluetooth module is a device which is used for short range wireless communication
to the respective connected device. This module uses serial port protocol for the wireless
communication and comes with two configurations that are master and slave. In the
master mode the module searches for the other devices to connect and can connect to
the other devices. However, in the slave mode the module cannot connect to the devices
by itself. In short the master more the device controls other devices and in slave mode
the device is being controlled by some other device. To change the master slave
configuration, it is possible to use the AT commands of the Bluetooth module. Moreover,
to use the AT mode it is possible to set the baud rate of 38400 and for serial
communication use the baud rate of 9600.
● Operating Voltage: 4 V to 6V (have internal 3.3V regulator).
● Operating Current: 30mA
● Integrated antenna and an edge connector.
● Range about 10 meters.
● Configurable in both master and slave modes.
● Pins: STATE, RXD, TXD, GND, VCC, KEY/ENABLE
HC-05 Bluetooth Module.
Pin Out
● STATE: State pin indicates whether the module is connected or paired with a
device. When the module is not connected, this pin will be in LOW state and the
on-board LED will be flashing fast. But when the module is paired or connected to
a device, the state pin will be in HIGH state and the on-board LED will be flashing
with a delay.
● RXD: This is a UART RX pin. This pin is used to send AT commands when the
module is in command mode. And it is used to send data to the connected device
when the module is in data mode.
● TXD: This is a UART TX pin. This pin is used to push out responses to AT
command when the module is in command mode. And it is used to push out data
sent by the connected device when the module is in data mode.
● GND: Power supply -ive.
● VCC: Power supply +ive.
● EN/KEY: This input is used to switch between command and data mode. If this pin
is set HIGH, the module will be in command mode. Similarly, if this pin is set LOW,
the module will be in data mode.
Circuit Diagram
Interfacing HC-05 Bluetooth Module with Arduino Uno.
Description
● RXD pin of HC-05 Bluetooth – TXD pin of Arduino Uno
● TXD pin of HC-05 Bluetooth – RXD pin of Arduino Uno
● GND pin of HC-05 Bluetooth – GND pin of Arduino Uno
● VCC pin of HC-05 Bluetooth – 5V output pin of Arduino Uno
● Positive pin of LED – Pin 13 of Arduino Uno
● Negative pin of LED – GND pin of Arduino Uno
Arduino Bluetooth Controller
Installed Arduino Bluetooth app from Google Play Store. This app will act as a Bluetooth
remote controller for Arduino. It is very easy to use this app. Open the app and connect
to the HC-05 device. Then select the option as switch mode. Now it is possible to control
the LED using the app.
CODING:
char data = 0; //Variable for storing received data
void setup()
{
Serial.begin(9600); //Sets the data rate in bits per second (baud) for serial data
transmission
pinMode(13, OUTPUT); //Sets digital pin 13 as output pin
}
void loop()
{
if(Serial.available() > 0) // Send data only while receiving data:
{
data = Serial.read(); //Read the incoming data and store it into variable data
Serial.print(data); //Print Value inside data in Serial monitor
Serial.print("\n"); //New line
if(data == '1') //Checks whether value of data is equal to 1
digitalWrite(13, HIGH); //If value is 1 then LED turns ON
else if(data == '0') //Checks whether value of data is equal to 0
digitalWrite(13, LOW); //If value is 0 then LED turns OFF
}
}
Working of Bluetooth Module (HC-05)
● Initialize the serial port (UART) with the default baud rate of HC-05 Bluetooth
module.
● Initialize Pin 13 as output pin.
● In the loop() it is possible to keep checking if any data is available to read from the
serial port.
● If data is available to read, store it to the variable named “data”.
● If the data read is ‘1’ then the LED is turned ON, else the LED will be turned OFF.
CONCLUSION:
Thus the study of the interfacing Arduino to Bluetooth module is completed.