Introduction: Use Bluetooth 4.0 HC-08 Module to Control Addressable LEDs - an Arduino Uno Tutorial
Have you delved into communication modules yet with Arduino? Bluetooth opens up a world of possibility for your Arduino projects and using the internet of things. Here we'll start with a baby step and learn how to control addressable LEDs with a smartphone app using an HC08 Bluetooth module. Afterwards, you'll be familiar with a smartphone app you can use to control other modules with Bluetooth.
What you'll need for this tutorial:
-Android application to control the ring (I used Serial Bluetooth Terminal for this tutorial)
The benefits of using BLE
The HC-08 module uses BLE (Bluetooth Low Energy) protocol. The main difference between Bluetooth and BLE is power consumption. Bluetooth consumes more power than BLE but can handle a lot of data. BLE is more appropriate for quickly transferring small amounts of data between nearby devices. BLE is less power-hungry, so the devices running this protocol can operate for years with a small battery; perfect for IoT!
Step 1: Connect Your Modules
Here's what you need to connect:
HC-08 > Arduino Uno
TXD > RXD
RXD > TXD
GND > GND
3V3 > 3V3
LED Ring > Arduino Uno
DIN > Pin 6
GND > GND
VCC > 5V
Step 2: Set Up Your Software
- Download Arduino IDE if you haven't already at www.arduino.cc/en/Main/Software)
- Install the NeoPixel library
Download the Adafruit NeoPixel Library
as a .zip file (https://github.com/adafruit/Adafruit_NeoPixel)
In the Arduino IDE, go to Sketch > Include Library > Add .zip library
Import the Adafruit NeoPixel Library
Choose the file that you just downloaded. You should see that the library was added successfully.
- We use Serial Bluetooth Terminal downloaded from the Google Play Store
Step 3: Upload the Code
Connect your Arduino Uno to the computer and verify you have the correct board and port selected under the Tools tab.
Download this example code.
NOTE: When you upload your code, don’t connect the Arduino RX pin. If it is connected during upload, the code won’t work. After uploading you must reconnect it for the LED to work.
The code is arranged into cases, add or remove as many as you’d like. Designate them with text you can input into your Bluetooth app. The cases in our code are separated with Uppercase letters. When you type a case into the app, it will change the LED’s color to its corresponding code in the IDE.
For example, if you type ‘A’ into your app, your LED should change to Green (0, 255, 0)
You can change the LED lights by adjusting the RGB values in the parenthesis. RGB values range from 0 to 255.
How-to adjust individual LED lights
You can do this by copying the code highlighted in boxes in the picture above (this code appears near the bottom of the example code) and replacing the ‘colorSet(strip.Color’…. code in the cases with it. ‘i’ will be the LED you want to change. ‘c’ will be the color code. You will have to add back in strip.Color( into the ‘c’ value spot along with the RGB code.
strip.setPixelColor(3,strip.Color(255, 127, 0));
This will turn the 3rd LED an Orange hue.
In this example code, we’ve provided you with an example case with different LED colors for individual LEDs. Now you can easily change individual LEDs.
Step 4: Connect to Your App and Run the Code
Run the code! Make sure you keep the RX disconnected during upload.
Now, open your app and go to Bluetooth Devices to find your module. Once connected, click on the connection icon up near the trash bin icon, and type in a case name, in our example code, we use cases A-E, and watch the LED light up!
Now you have experience using a Bluetooth application and using addressable RGB LED lights, so you can incorporate both into your projects. Go further and play with timing and delay functions. Enjoy!