In this tutorial let us learn How to interface HC-05 Bluetooth Module with AVR ATmega8 microcontroller. We will establish communication between Android mobile and Atmega8 through Bluetooth module which takes place through UART serial communication protocol. In this project we will control a LED using Bluetooth of our smartphone.
- AVR Atmega8
- HC-05 Bluetooth module
- USBASP programmer
- 10-pin FRC cable
- Jumper wires
We will use CodeVisionAVR software for writing our code and SinaProg software for uploading our code to Atmega8 using USBASP programmer.
You can download these softwares from the given links:
CodeVisionAVR : http://www.hpinfotech.ro/cvavr_download.html
Bluetooth Module HC-06:
Bluetooth can operate in the following two modes:
- Command Mode
- Operating Mode
In Command Mode we will be able to configure the Bluetooth properties like the name of the Bluetooth signal, its password, the operating baud rate etc. The Operating Mode is the one in which we will be able to send and receive data between the PIC Microcontroller and the Bluetooth module. Hence in this tutorial we will be toying only with the Operating Mode. The Command mode will be left to the default settings. The Device name will be HC-05 (I am using HC-06) and the password will be 0000 or 1234 and most importantly the default baud rate for all Bluetooth modules will be 9600.
The module works on 5V supply and the signal pins operate on 3.3V, hence a 3.3V regulator is present in the module itself. Hence we need not worry about it. Out of the six pins only four will be used in the Operating mode. The pin connection table is shown below
Pin on HC-05/HC-06
Pin name on MCU
Pin number in PIC
Check our other projects to learn more about Bluetooth module HC-05 with other microcontrollers:
- Bluetooth Controlled Toy Car using Arduino
- Bluetooth Controlled Home Automation System using 8051
- Controlling Raspberry Pi GPIO using Android App over Bluetooth
- Smart Phone Controlled FM Radio using Arduino and Processing
- Mobile Phone Controlled Robot Car using G-Sensor and Arduino
Creating the Project for Atmega 8 using CodeVision:
After installing these softwares follow the below steps to create project and writing code:
Step 1. Open CodeVision Click on File -> New -> Project. Confirmation Dialogue box will appear. Click On Yes
Step 2. CodeWizard will open. Click on first option i.e. AT90, and click OK.
Step 3. Choose your microcontroller chip, here we will take Atmega8 as shown.
Step 4. Click on Ports. In our project, we will be using Port C4 and C5 for led interfacing. So, make Bit 4 and bit 5 as output by clicking on it. As shown below:
Step 5. We will use USART for Rx and Tx. So, click on USART option and click on Receiver option and leave rest as it is.
Step 6. Click on Program -> Generate, Save and Exit. Now, more than half of our work is completed
Step 7. Make a New folder on desktop so, that our files remains in folder otherwise it we will be scattered on whole desktop window. Name your folder as you want and I suggest use the same name to save program files.
We will be having three dialogues box one after other to save files.
Do the same with other two dialogue boxes which will appear after you save the first.
Now, your workspace looking like this.
Our most of the work is completed with the help of the Wizard. Now, we have to write only few lines of code to interface the bluetooth module and control the LED.