Bluetooth for Arduino in 10 Minutes
If you ever have the desire to add some wireless connectivity to your Arduino projects, then this post will guide you on how to add a Bluetooth capability to your Arduino project by using a HC05 Bluetooth module.
HC05 is an affordable Bluetooth module and one of the simplest method to add a Bluetooth capability to an Arduino board.
With Bluetooth capability, your Arduino project can send and receive data and messages from nearby Bluetooth devices. It makes your Arduino project becomes a remote device that can be controlled by other device such as an Android smartphone.
Before we proceed further, there are some disclaimer : I am using a clone Arduino board and HC05 module of unknown Chinese manufacturers. Since the quality may vary between manufacturers, the tutorial below may or may not work for you.
HC05 Specifications
Let’s talk a bit about the HC05 module. This module is a Bluetooth module that gives an Arduino board a capability to transmit and receive data via Bluetooth connection to other Bluetooth devices e.g. smartphones or other Arduino boards connects to HC05 modules.
For those who are super technical geeks, these are the detail specifications:
- Typical -80dBm sensitivity
- Up to +4dBm RF transmit power
- Low Power 1.8V Operation,1.8 to 3.6V I/O
- PIO control
- UART interface with programmable baud rate
- Integrated antenna
- Edge connector
- Default Baud rate: 38400, Data bits:8, Stop bit:1, Supported baud rate: 9600,19200,38400,57600,115200,230400,460800.
- Given a rising pulse in PIO0, the device will be disconnected.
- Status instruction port PIO1: low-disconnected, high-connected;
- PIO10 and PIO11 can be connected to red and blue led separately. When master and slave are paired, red and blue led blinks 1time/2s in the interval, while disconnected only blue led blinks 2times/s.
- Auto-connect to the last device on power as default.
- Permit the pairing device to connect as default.
- Auto-pairing PINCODE:”0000” as default
- Auto-reconnect in 30 min when disconnected as a result of beyond the range of connection.
You can find the complete specifications in this website
Components
This tutorial requires only very few components :
- Arduino Uno or Mega ADK (work on both boards with no difference in pin connections)
- 1 HC05 module
- Some male to female jumper cables
- Laptop with Arduino IDE installed in it. The IDE can be downloaded from Arduino website
- Connection cable from laptop to Arduino board to upload source code to board
- LED (already built into the Arduino board)
Pinout and Connections
We start with the hardware part. Using jumper cables, connect the HC05 module to the Arduino board using the diagram below as reference :
This is the connection that works for me. However, I found some references that mention that the +5V terminal in the HC05 module should be connected to a 5V pin on the Arduino board. This connection does not work for me, so you should experiment a bit to find which one works for you.
Next, you need to power the Arduino board by connecting it to a laptop (using the USB cable) or other external power supply. When you see the LED on the HC05 module is blinking, then you are on the right track.
Arduino Code
For the software side, open a new sketch on Arduino IDE then copy and paste this code:
Once it is pasted, save the sketch and click compile. The code is very simple and minimum, so there shouldn’t be any error at this stage. Next, click the upload button to write the code to the Arduino board. If there is an error, usually it’s because of improper connection between the board and your laptop. Please ensure that the board is properly recognized by Arduino IDE.
Note: remove +5V HC05 connection from the board before uploading the code then reconnect it after the upload.
When everything is correct, you should see the built-in LED is blinking.
The First Bluetooth Data Transmission
At this point, the board is already transmitting data via the Bluetooth module. However, for the time being, there is no other Bluetooth device paired and connected to the Arduino board to receive the data that we transmit. So the only way is to make sure that the board is transmitting is by looking at the serial monitor on Arduino IDE.
Open the serial monitor in Arduino IDE, then adjust the baud rate to 9600 baud (the same baud rate we specify in the code). If everything is correct, you should see this screen :
Checkpoints
Make sure the followings are completed:
- LED on HC05 module is blinking
- LED on Arduino board is blinking
- Serial monitor shows a transmission message
What’s Next?
We can receive and display the Bluetooth message by pairing another Bluetooth capable device to the Arduino board. In this case, we can use an Android smartphone. But to do that we need to use a Bluetooth connection app. Udemy offers a course that will teach you how to create an Android Bluetooth app that can talk with your Arduino project.
This will open some new exciting possibilities.