Introduction: Arduino Controlling Led With HC-06 Bluetooth Module
Hello everybody, this is my first official tutorial on Instructable.com, I'm very excited about my first project!
Today I will show you How to connect Arduino and Bluetooth module. Arduino will communicate with the HC-06 Bluetooth Module Board using Serial communication. (this tutorial also works no HC-05)
The Bluetooth module we will use today is HC-06 which is well-known and cheap. (I got mine for 2$ from aliexpress)
Our app is still in testing process, so we encourage you to send an email to: email@example.com if you have any technical problems or you experienced some troubles. Thank you a lot for understanding!
What is HC-06?
The HC-06 is a class 2 slave Bluetooth module designed for transparent
wireless serial communication. Once it's paired to a master Bluetooth device such as PC, smartphones or tablet, its operation becomes transparent to the user. All data received through the serial input is immediately transmitted over the air. When the module receives wireless data, it is sent out through the serial interface exactly at where it is received. No user code specific to the Bluetooth module is needed at all in the user microcontroller program.
We will also use Serial communication for today's project. For Arduino, it is by default RX and TX pins (D0, D1)
For more information visit: https://www.arduino.cc/reference/en/language/functions/communication/serial/
After reading this instructable you will be able to:
1) Connect Arduino Board with any Android phone by Bluetooth and send/receive data.
2) Build a project and read values from sensors wirelessly
3) Build a Home Automation or wirelessly controlled robot.
Step 1: Parts and Components
We will need these parts:
- 1x Arduino Board (I will be using Arduino UNO)
- 1x Bluetooth Module HC-06 or HC-05
- 1x Led of any color (I used blue 5mm)
- 1x 220Ω Resistor
- Breadboard and jumpers
- (Optional) 9V Battery
Step 2: Connections and Schematic
The circuit is very simple and small, so there are only a few connections to be made.
All the important connections and schematic is shown in the picture above.
Connect the negative end of Led to GND with a 220Ω resistor and the positive end to Digital Pin 2.
Step 3: Arduino Code and Serial Communication
Upload the following sketch to the Arduino using a USB cable.
Don't forget to disconnect HC-06 module before uploading the sketch!
HC-06's Pins (RX and TX) are using Arduino Uno's pins for communication with computer. This particular board has only one hardware Serial pins and connecting something to it while uploading a sketch will create conflict. Download
- First, we declared a const (constant, which can't be changed later on) Integer for Led, which is on pin 2
- In setup() we started Serial communication with 9600 baud rate and set up the led as an OUTPUT
- In loop(), every time the program repeats we read Serial with Serial.read() and we store as a single character in a variable called "c"
- We add multiple if/else statements to check whether the "c" is an 'a' or 'b'
- If the char is 'a' we turn the led on, if the char is 'b' we turn the led off
- We added a small delay for readings
Now we are ready for the final step!
Step 4: Connect Arduino to Android Device
Now download the following app: Smart Bluetooth - Arduino Bluetooth Serial ⚡
Smart Bluetooth is an app that allows you to use your phone to communicate
with your Bluetooth module or board, with the easiest and simplest way. It opens door to unlimited ways to control your DIY projects. Smart Bluetooth offers many different ways how to send data to your module.
Smart Bluetooth has the following features:
- Fast connection to your module
- Send and receive data from your module
- Control receiver’s digital and PWM pins
- Dark and Light theme
- Different control layouts for different purposes
- Modern and responsive UI
- Customizable buttons and switches
- Implement your DIY RC Car project with a beautiful gamepad
- Easily control your RGB Led strips with sliders
- Automatically turns off Bluetooth when closed to save battery life
- Command line (terminal)
In this tutorial, we are using the first TAB with big led, just sufficient enough to send two characters.
In these following pictures I will show you how to use the app. I will show you how to search for nearby devices, how to pair with the module we are using, and how to set up the data sent from the app. If you feel confused, pause and go back to previous steps until you get it working. However, if you still have problems let me know firstname.lastname@example.org, I will respond within 24h hours :)
- Open the app, slide through the intro, hit SEARCH button and search for nearby devices
- When your device is found, select it by clicking on it
- Select prefered theme (dark or light) and hold the button you selected
- Wait for the connection, if it fails, try to reconnect
- After successful connection, tap on the big led in the first tab (led) and check the LED connected to your Arduino if it blinks
- If everything works and you want to edit the data sent to Arduino, unlock more features and support me, purchase premium, I will be very happy :)
That should be it.
Don't forget to rate and leave a nice feedback. Thanks and see you at next tutorial :)
Please support my Robotic Arm project here: