Introduction: Controlling an RGB LED With the HC-06 Bluetooth Module Using Android OS(Arduino)
This tutorial will explain the process of connecting an HC-06 Bluetooth Module to an Arduino and controlling the color of an RGB LED using the ArduDroid app on the Android Operating System. This setup will most likely also work with the HC-05 Bluetooth Modules.
Step 1: Materials & Components
2. RGB LED
3. HC-06 Bluetooth Module
4. 3 x 560 ohm resistors
5. 2.2k resistor
6. 1k resistor
7. Arduino Shield I/O pin breakout(Completely Optional) - Just breaks out the pins to the breadboard
Step 2: Adding the RGB LED
1. Insert the LED into the breadboard. Pay attention to which lead is longest as this is the common cathode and will be connected directly to a 5v rail.
2. Add the 3 x 560 ohm resistors to the breadboard coming from each of the other leads.
3. Connect the common cathode(longest lead) to the 5v rail of the breadboard or Arduino.
4. Add a jumper wire from each of the 560 ohm resistors to 3 PWM I/O ports of the Arduino. I used 9, 10, and 11 but any 3 PWM ports will work. It will make it easier when using the app later if the three you choose are consecutive. You will see why.
Step 3: Adding the HC-06 Bluetooth Module to the Breadboard
For the purposes of this tutorial we can ignore the State and EN ports. We will only need the 4 middle ports with break away headers labeled GND, TXD, RXD, and VCC.
1. Insert the HC-06 Bluetooth Module into the breadboard.
2. Connect the Vcc from the Bluetooth Module directly to the 5v rail. The module can tolerate any voltage between 3.6v and 6v as labeled on the back.
3. Connect GND from the module to a GND rail.
4. After a bit of research it seems that the TX from the module can be connected directly to the RX(Digital port 0) of the Arduino
5. Connecting the Module's RX to the Arduino's TX(Digital Port 1) is where this process gets kinda tricky. These bluetooth modules use 3.3v logic level which is incompatible with the 5v logic used by the Arduino. Therefore trying to connect the module's RX directly the Arduino's TX may result in a fried module. To step the voltage down from 5v to 3.3v a voltage divider is necessary. If you do not posses the correct voltage divider you can simply create one using two resistors. This will be explained in the next step.
Step 4: Creating the Voltage Divider
The required voltage of Module's RX is 3.3v therefore the 5v coming from the Arduino's TX(digital Pin 1) must be stepped down to protect the module. To do this we create a voltage divider using two resistors. There are many combinations of resistors that can step the 5v down to around 3.3. volts. It will not be exact, but as long as it is close the module will work fine.
The equation for figuring out the required resistors is as follows, Vout = Vin * R2/R1+R2. If you are not big on math you can use the voltage divider resistor calculator graciously provided by the folks over at Sparkfun.com. https://learn.sparkfun.com/tutorials/voltage-divid...
1. The resistor values used here are 2.2k and 1k. On the other end of the equation these values equals out to around 3.44v. This deviation from the necessary 3.3v doesn't seem to have any detremintal effects on how the module functions. Connect the resistors as shown in the picture above.
2. Connect the leg of the 2.2k resistor that is by itself directly to GND.
3. Connect the leg of the 1k resistor that is by itself to the TX(digital pin1) of the Arduino.
4. Finally Connect the RX from the Bluetooth Module to the middle of the two resistors. This completes the Wiring process.
Step 5: Coding the Arduino
Full credit for the Arduino code and Application goes to their creator Hazim Bitar. Amazing work. You can find the code and also a separate configuration for using the HC-05 Bluetooth Module here: http://www.techbitar.com/ardudroid-simple-bluetoot...
1. Copy the Code into the Arduino IDE
2. Use the Verify button to ensure that everything copied correctly.
3. Double-check the code matches your hardware configuration.
4. Note: You must unplug the bluetooth module's RX and TX lines from the Arduino before uploading the code as it will interfere and the code will not be uploaded properly.
5. Once the code is uploaded, unplug the power from the Arduino, re-insert the bluetooth module, and reconnect the power.
6. The Bluetooth Module will blink for around 10 seconds while looking for a connection.
Step 6: Downloading the APP/Getting Connected
The Application used is the ArduDroid app. It gives you control over the entire PWM range from 0-255 via sliding bars and enables ON/OFF(1 or 0) commands for each I/O port. It was created by Hazim Bitar, is free, and can be found here:
1. Download the App
2. When the Bluetooth Module is plugged in for the first 10 seconds it will blink and search for a connection.
3. Enable bluetooth on your Android device and search for available devices.
4. Select HC-06 from the device list and type the default pin "1234" into the dialogue box.
5. Once the device is connected find the slide bars that correspond to the number pins you used for the leads of the RGB LED. Sliding these bars should change the PWM value of the pin and thus change the color. You can also use the Button's within the app to turn the digital pins On&Off. Once you change a value on the app the LED should turn on and start responding to commands.
We have a be nice policy.
Please be positive and constructive.