Introduction: Use Bluetooth 4.0 HC-08 Module to Control Addressable LEDs - an Arduino Uno Tutorial

Picture of 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:

Hardware:

-Arduino UNO

-LED RING 16 X 5050 RGB WS2812

-Dupont wires

-Male Headers

-HC-08 Bluetooth module


Software:

-Arduino IDE

-Example code

-NeoPixel Library

-Android application to control the ring (I used Serial Bluetooth Terminal for this tutorial)


Tools:

-Soldering iron


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

Picture of 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

  1. Download Arduino IDE if you haven't already at www.arduino.cc/en/Main/Software)
  2. Install the NeoPixel library
    1. Download the Adafruit NeoPixel Library
      as a .zip file (https://github.com/adafruit/Adafruit_NeoPixel)

    2. In the Arduino IDE, go to Sketch > Include Library > Add .zip library

    3. Import the Adafruit NeoPixel Library

    4. Choose the file that you just downloaded. You should see that the library was added successfully.

  3. Download the Bluetooth application on your smartphone. You can use many Bluetooth applications to control the HC-08 module. However, not all are compatible with BLE protocol, so if you want to use a different app check its compatibility first.
    1. We use Serial Bluetooth Terminal downloaded from the Google Play Store

Step 3: Upload the Code

Picture of 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.

Code explanation

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.

Example:

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

Picture of 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!

Comments

About This Instructable

986views

32favorites

License:

Bio: We're a group of fun-loving, electronic DIY'ers with Smart-Prototyping.com. We hope to share useful guides and tutorials as well as the cool ... More »
More by Alex_chu:Use Bluetooth 4.0 HC-08 Module to Control Addressable LEDs - an Arduino Uno TutorialHow-To Get Started With Addressable RGB LEDsGY-68 BMP180 Barometric Pressure Breakout Board Tutorial With Arduino Uno
Add instructable to: