Heaven’s light is our guide
Rajshahi University of Engineering & Technology
MTE 3103
Microcontroller and Interfacing
Prepared By:
Md. Sakib Hassan Chowdhury
Lecturer,
Department of Mechatronics Engineering,
Rajshahi University of Engineering & Technology.
1
Outlines
• Introduction to HC – 05 Bluetooth Module
• Default settings, specifications and Applications of HC – 05 Bluetooth Module.
• Pin Configuration of HC – 05 Bluetooth Module.
• HC – 05 Bluetooth Module working Principle.
• Interfacing Atmega32 with HC – 05 Bluetooth Module; circuit diagram with AVR code.
MTE 3103: Microcontroller and Interfacing 2
HC-05 Bluetooth Module
HC-05 Bluetooth Module:
• HC-05 is a Bluetooth device used for wireless
communication. It works on serial communication
(USART).
• It is a 6 pin module.
• The device can be used in 2 modes; data mode and
command mode.
• The data mode is used for data transfer between devices
whereas command mode is used for changing the settings of
the Bluetooth module.
MTE 3103: Microcontroller and Interfacing 3
HC-05 Bluetooth Module
HC-05 Technical Specifications: HC-05 Default Settings:
• Serial Bluetooth module for Arduino and other • Default Bluetooth Name: “HC-05”
microcontrollers • Default Password: 1234 or 0000
• Operating Voltage: 4V to 6V (Typically +5V) • Default Communication: Slave
• Operating Current: 30mA • Default Mode: Data Mode
• Range: <100m • Data Mode Baud Rate: 9600, 8, N, 1
• Works with Serial communication (USART) and TTL • Command Mode Baud Rate: 38400, 8, N, 1
compatible • Default firmware: LINVOR
• Follows IEEE 802.15.1 standardized protocol Applications
• Uses Frequency-Hopping Spread spectrum (FHSS) 1. Wireless communication between two microcontrollers
• Can operate in Master, Slave or Master/Slave mode 2. Communicate with Laptop, Desktops and mobile phones
• Can be easily interfaced with Laptop or Mobile phones with 3. Data Logging application
Bluetooth 4. Consumer applications
• Supported baud rate: 5. Wireless Robots
9600,19200,38400,57600,115200,230400,460800. 6. Home Automation
Baud Rate vs Bit Rate?
MTE 3103: Microcontroller and Interfacing 4
HC-05 Bluetooth Module Pin Configuration
Pin Pin Description
Number Name
1 Enable / This pin is used to toggle between Data Mode (set low) and AT command mode (set high). By default it
Key is in Data mode
2 Vcc Powers the module. Connect to +5V Supply voltage
3 Ground Ground pin of module, connect to system ground.
4 TX – Transmits Serial Data. Everything received via Bluetooth will be given out by this pin as serial data.
Transmit
ter
5 RX – Receive Serial Data. Every serial data given to this pin will be broadcasted via Bluetooth
Receiver
6 State The state pin is connected to on board LED, it can be used as a feedback to check if Bluetooth is
working properly.
7 LED Indicates the status of Module
• Blink once in 2 sec: Module has entered Command Mode
• Repeated Blinking: Waiting for connection in Data Mode
• Blink twice in 1 sec: Connection successful in Data Mode
8 Button Used to control the Key/Enable pin to toggle between Data and command Mode
MTE 3103: Microcontroller and Interfacing 5
HC-05 Bluetooth Module Working Principle
How to Use the HC-05 Bluetooth module
• The HC-05 has two operating modes, one is the Data mode in which it can send and receive data from other Bluetooth
devices and the other is the AT Command mode where the default device settings can be changed. We can operate the device
in either of these two modes by using the key pin as explained in the pin description.
• It is very easy to pair the HC-05 module with microcontrollers because it operates using the Serial Port Protocol (SPP).
Simply power the module with +5V and connect the Rx pin of the module to the Tx of MCU and Tx pin of module to Rx of
MCU as shown in the figure below
• During power up the key pin can be grounded to enter into Command mode, if left free it will by default enter into the data
mode. As soon as the module is powered you should be able to discover the Bluetooth device as “HC-05” then connect with it
using the default password 1234 and start communicating with it. The name password and other default parameters can be
changed.
MTE 3103: Microcontroller and Interfacing 6
Interfacing Atmega32 with Bluetooth Module
Example
In this application, when 1 is sent from the smartphone, LED will Turn ON and if 2 is sent LED will
get Turned OFF. If received data is other than 1 or 2, it will return a message to mobile that select the
proper option.
Programming steps
1. Initialize ATmega16/ATmega32 USART communication.
2. Receive data from the HC-05 Bluetooth module.
3. Check whether it is ‘1’ or ‘2’ and take respective controlling action on the LED.
MTE 3103: Microcontroller and Interfacing 7
Interfacing Atmega32 with Bluetooth Module
Circuit Diagram:
MTE 3103: Microcontroller and Interfacing 8
Interfacing Atmega32 with Bluetooth Module
AVR Program: #include <avr/io.h>
#include "USART_RS232_H_file.h" /* include USART library */
#define LED PORTB /* connected LED on PORT pin */
int main(void)
{
char Data_in;
DDRB = 0xff; /* make PORT as output port */
USART_Init(9600); /* initialize USART with 9600 baud rate */
LED = 0;
while(1)
{
Data_in = USART_RxChar(); /* receive data from Bluetooth device*/
if(Data_in =='1')
{
LED |= (1<<PB0); /* Turn ON LED */
USART_SendString("LED_ON");/* send status of LED i.e. LED ON */
}
else if(Data_in =='2')
{
LED &= ~(1<<PB0); /* Turn OFF LED */
USART_SendString("LED_OFF"); /* send status of LED i.e. LED OFF */
}
else
USART_SendString("Select proper option"); /* send message for selecting proper option */
}
MTE 3103: Microcontroller and Interfacing 9
Interfacing ATmega32 with Different Sensors
To Be Continued…..
MTE 3103: Microcontroller and Interfacing 10
MTE 3103: Microcontroller and Interfacing 11