There are several reasons why developers like to use Bluetooth in IoT projects. It is cheap, wireless, automatic and seamlessly connects with smartphones, tablets, PCs and even gaming controllers.
You can easily connect an Arduino board with a Bluetooth app on your smartphone. Alternatively, you can connect it with a Bluetooth dongle on your PC using a sketch on Arduino software. In this article we discuss simple ways to work both these techniques.
What Do You Need?
The following components are needed in this project.
- Board: Arduino Uno
- Breadboard: for conjunction of Uno with Bluetooth module
- Power supply: from a PC’s USB connection or external AC/DC adapter or battery
- Wires: 4 to 6 wires
- Bluetooth control app: we will use BlueControl – Arduino + JY-MCU
- Bluetooth module: wireless Bluetooth RF Transceiver Module for HC-05 or HC-06; we will use 4-pin modules in this case, not 6.
Connecting with Mobile App
The following is a simple procedure to control a Bluetooth device on a smartphone. First, you need to arrange the wires so that they connect with each other across a breadboard as shown in the diagram.
The Vcc of Bluetooth module goes to the 5V connection in Uno. Similarly, the ground goes to the ground, The Tx, or transmit pin, goes to Rx in Uno or pin number 0. The Rx of Bluetooth goes to Tx of Uno or pin number 1.
Ideally, the 5V voltage may be too high for the Bluetooth component, so you might further need a couple of 10 ohm resistors to divide the voltage.
As soon as you connect the power supply, the Bluetooth LED should start blinking. This means there is no Bluetooth pairing at the moment. You need to create one to have better control over the device/project.
To affect the pairing, we need to first download BlueControl, the Bluetooth-controlling app discussed earlier.
In the next step, you must allow your smartphone to turn Bluetooth on.
Select HC-06 as your paired Bluetooth module to be controlled by the app.
Using the app itself, you can now turn the Bluetooth LED on or off as necessary.
Connecting with PC/Mac
To connect the Bluetooth module with PC/Mac, you must connect the USB cable to Uno’s power supply unit, then simply open the Arduino software and ensure the connection is available.
In the next step, you need to load the Bluetooth control program onto the Arduino board. A tech blogger, Dotslashnotes, has shared the code to be used at this link.
After copy-pasting the 128-line code, you have to upload the program in the Arduino software. This code has two buttons to turn the Bluetoooth LED ON or OFF.
Of course, the above code is just one of the ways to do it.
DISCLAIMER: I haven’t tried it myself, but the code does look elegantly simple.
If this doesn’t work for you, then you need to find a code online which will support your PC/Mac connectivity. Arduino Forum is one of the best places to look for help and support on this and many other Arduino topics.
Have you worked with Bluetooth in Arduino or any other IoT projects? We’d love to hear your experience in the comments below.
Image credit: Rajib Ghosh
Get the best of IoT Tech Trends delivered right to your inbox!