Maker Portal

View Original

4-Pin RGB LED Control Using iOS BLExAR App, HM-10 Bluetooth Module, and Arduino

See this content in the original post

BLExAR iOS Bluetooth App - Control your Arduino board using Bluetooth Low Energy


See this content in the original post

An RGB LED, as stated earlier, has four pins instead of two. The 4-pin RGB LED can be seen against a standard LED in Figure 1. The RGB LED is the first component used in this tutorial, along with an Arduino Uno board, a CC2541 Bluetooth module (HM-10 or AT-09), and a few resistors. The BLExAR app has pulse width modulation (PWM) capabilities, which will allow us to alter the emitted light color and brightness based on intervals from 0-255 for each color. Since we are using an RGB LED, we have red, blue, and green hues which allow us to create a 24-bit color light emitting diode (assuming each color responds to the PWM resolution of the Arduino). In order to use this PWM method, we must ensure that we are using the correct LED - a cathode-common RGB LED. This means that the longest leg of the LED must be the common (ground) pin. This will allow us to vary the voltage (via PWM) of each RGB color using the Arduino board and BLExAR app.

The full part list is shown below, purchasable from Amazon:

Figure 1: RGB LED (right) vs. Regular LED (left)

See this content in the original post

See this content in the original post

As stated above, we need to use PWM to vary the brightness of each color pin of the LED. Therefore, we must choose PWM-enabled pins on the Arduino board. On the Uno, pins 3,5,6,9,10 and 11 are PWM controllable. To make things simple, I chose pins 9,10,11, but any of the PWM enabled pins are usable and controllable via the BLExAR app.

The wiring diagram below outlines the process for wiring the RGB LED and a CC2541 (HM-10, AT-09, JDY-08, etc.) Bluetooth module to the Arduino Uno board.


See this content in the original post

The code required for control of an Arduino board needs specific identifiers that tell the board when to start and end a specific command. The code also interprets the signals sent by the BLExAR app to determine whether to control an analog or digital signal. Furthermore, the control code also deciphers whether to control a pin as PWM or just a standard on or off. All of the commands and interpretations are handled by the app (on the iOS side) and the code below (Arduino side).

See this content in the original post

See this content in the original post

The video below demonstrates control of an Arduino Uno board using an iPhone X. The brightness and color of an RGB LED are changed using simple on-off switches as well as PWM sliders that range from 0-255 (8-bit).

See this content in the original post

The next video below shows the varying brightness of the RGB LED for each color.

See this content in the original post

See this content in the original post

In this tutorial, I introduced the idea of RGB LEDs and how to control them using an iOS device and the BLExAR app. RGB LEDs are 4-pin LEDs that can produce over 16.7 million different colors by varying the voltage sent to each of its three individual color pins (red, green, blue). The BLExAR app allows the iOS user to send a series of commands to a Bluetooth-enabled Arduino board that allows the user to control its pins via digital on and off values and even pulse width modulation (PWM) values.

The PWM methods afforded by the BLExAR app demonstrate the effects of fading an LED and how, through changing the effective voltage sent to an LED, we can create a 24-bit color LED. This type of 24-bit color combination is the basis for most liquid crystal displays (LCD) that are used in modern displays like computer screens, TVs, and smartphones.

From this point, the BLExAR app can be used to control other PWM components such as fans, heaters, or pumps. The BLExAR app was created specifically as an integrated tool that allows users to control their Arduino board at a low cost, with minimal coding or experience needed. The possibilities from here, using both digital control and PWM are endless!


See More in BLExAR and Arduino:

See this gallery in the original post