UNITED INSTITUTE OF TECHNOLOGY
(An Autonomous Institution)
(Approved by AICTE | Affiliated to Anna University |
Accredited by NAAC with A+ Grade | Certified by ISO 9001:2015)
Periyanaickenpalayam, Coimbatore – 641020
Exp: 4 Interfacing Arduino to Bluetooth Module
Date:
Aim:
To design the hardware and software to interface HC-05 Wireless Bluetooth module with the
Arduino UNO Development board and perform data communication
Components Required:
Arduino UNO Board, HC-05 Bluetooth module, USB data cable, 12V DC Power adapter and
jumper wires.
Hardware Details:
HC-05 is a Bluetooth device used for wireless communication with Bluetooth enabled devices
(like smartphone). It communicates with microcontrollers using serial communication (USART).
Default settings of HC-05 Bluetooth module can be changed using certain AT [Link]
HC-05 Bluetooth module has 3.3 V level for RX/TX and microcontroller can detect 3.3 V level,
so, there is no need to shift TX voltage level of HC-05 module. But we need to shift the transmit
voltage level from microcontroller to RX of HC-05 module. The Pin details of the Bluetooth
module is given below.
UNITED INSTITUTE OF TECHNOLOGY
(An Autonomous Institution)
(Approved by AICTE | Affiliated to Anna University |
Accredited by NAAC with A+ Grade | Certified by ISO 9001:2015)
Periyanaickenpalayam, Coimbatore – 641020
Connecting Arduino UNO to Bluetooth Module:
The Arduino UNO development board is interfaced to the Bluetooth
module using UART Interface. AT commands are used to perform communication with the
Bluetooth module.
Send Message using Bluetooth HC-05 With Arduino
Here, we will transmit data from Smartphone via Bluetooth to the Arduino Uno and display it on
Serial Monitor of [Link] and install a Bluetooth terminal application on your phone and
use it to connect to the HC-05 Bluetooth [Link] is sent from the Smartphone using
the Bluetooth terminal application.
Software for Master Transmission
/*Code to control an LED via bluetooth through a phone app.
Project by MukeshArvindh. Code by MukeshArvindh.*/
/*If you are going to copy and paste the code, then do not forget
to delete the void setup() and void loop() function from the
sketch you are using before doing so,as the functions already
exist in this sketch. Copy-pasting the comments will not
cause any changes in the outcome or code.*/
UNITED INSTITUTE OF TECHNOLOGY
(An Autonomous Institution)
(Approved by AICTE | Affiliated to Anna University |
Accredited by NAAC with A+ Grade | Certified by ISO 9001:2015)
Periyanaickenpalayam, Coimbatore – 641020
/*Note:This code has been compiled and checked multiple times, and has
proven to be accurate. The product also works as intended.*/
//Bluetooth uses serial communication. So, we use many serial functions
//in this sketch.
const int LED = 5;
/*Declaring that there is an LED on pin 5 of the arduino board. We use
const as we will not change this. You don't have to name it LED. You
can even put your name instead.*/
char switchstate;
/*declaring that there is a variable called switchstate, which will
hold a character value. This is due to programming of the app, which
will send a text value to arduino. If we use 'int' instead of
'char' the code will not work properly.*/
void setup() {//Here the code only runs once.
[Link](9600);
/*To start serial communication at a rate of 9600 bits per second. This
is the default rate anyways.*/
pinMode(LED, OUTPUT);
//Declaring that the LED is an output.
}
void loop() {//This code repeats. This is our main code.
while([Link]()>0){
//code to be executed only when [Link]()>0
/*[Link]>0 is to check if there is any reading from the
HC-05 Bluetooth module.*/
switchstate = [Link]();
/*The character we had declared earlier is now being assigned a value-
UNITED INSTITUTE OF TECHNOLOGY
(An Autonomous Institution)
(Approved by AICTE | Affiliated to Anna University |
Accredited by NAAC with A+ Grade | Certified by ISO 9001:2015)
Periyanaickenpalayam, Coimbatore – 641020
the value of whatever [Link]() is.*/
//[Link]() is to read the value coming from app.
[Link](switchstate);
//This will print the value onto the Serial monitor.
[Link]("\
");
//This moves to the next line after every new line printed.
delay(15);
/*Gives a break of 15 milliseconds. Delay is for human eye, and for
speed of some computers, as some will crash at high speeds.*/
if(switchstate == '1'){//Checking if the value from app is '1'
digitalWrite(5, HIGH);
//If it is, write the component on pin 5(LED) high.
}
else if(switchstate == '0'){//Else, if the vaue from app is '0',
digitalWrite(5, LOW);//Write the component on pin 5(LED) low.
}
}
}
Result:
The necessary hardware to interface HC05 Bluetooth module to the Arduino UNO board is
constructed and the software to communicate between the bluetooth module and the Bluetooth in
mobile phone is written and executed and its output is verified.