Ex 8
Ex 8
Ex 8
Aim:
To interface Bluetooth with Arduino / Raspberry Pi and write a program to send sensor data
to smart phone using Bluetooth.
Apparatus:
o Arduino Uno board
o Arduino cable
o LED
o HC-05 Bluetooth Module
o Jumper cables
o Smart phone
Description:
o HC-05 is a Bluetooth module which is designed for wireless communication. This module
can be used in a master or slave configuration.
Pin Description
Bluetooth serial modules allow all serial enabled devices to communicate with each
other using Bluetooth.
It has 6 pins,
1. Key/EN: It is used to bring Bluetooth module in AT commands mode. If Key/EN
pin is set to high, then this module will work in command mode. Otherwise by
default it is in data mode. The default baud rate of HC-05 in command mode is
38400bps and 9600 in data mode.
HC-05 module has two modes,
1. Data mode: Exchange of data between devices.
2. Command mode: It uses AT commands which are used to change setting of HC-
05. To send these commands to module serial (USART) port is used.
2. VCC: Connect 5 V or 3.3 V to this Pin.
3. GND: Ground Pin of module.
4. XD: Transmit Serial data (wirelessly received data by Bluetooth module transmitted
out serially on TXD pin)
5. RXD: Receive data serially (received data will be transmitted wirelessly by
Bluetooth module).
6. State: It tells whether module is connected or not.
HC-05 module Information
HC-05 has red LED which indicates connection status, whether the Bluetooth is
connected or not. Before connecting to HC-05 module this red LED blinks continuously in
a periodic manner. When it gets connected to any other Bluetooth device, its blinking slows
down to two seconds. This module works on 3.3 V. We can connect 5V supply voltage as
well since the module has on board 5 to 3.3 V regulator. As HC-05 Bluetooth module has
3.3 V level for RX/TX and microcontroller can detect 3.3 V level, so, no need to shift
transmit level of HC-05 module. But we need to shift the transmit voltage level from
microcontroller to RX of HC-05 module.
Circuit Diagram:
Program:
char input_data;
String inputString="";
void loop()
{
if(Serial.available()){
while(Serial.available())
{
char inChar = (char)Serial.read(); //read the input
inputString += inChar; //make a string of the characters coming on serial
}
Serial.println(inputString);
while (Serial.available() > 0)
{ input_data = Serial.read() ; } // clear the serial buffer
if(inputString == "a"){ //in case of 'a' turn the LED on
digitalWrite(13, HIGH);
}else if(inputString == "b"){ //incase of 'b' turn the LED off
digitalWrite(13, LOW);
}
inputString = "";
}
} Procedure: