Android control color RGB LED using HC-05 Bluetooth module with Arduino (Part II)

 Android control color RGB LED using HC-05 Bluetooth with Arduino(Part II)

You probably have seen my first part of Arduino hardware setup tutorial. If you haven't please visit here: My previous Arduino (Part I tutorial).

After few weeks of struggling with MIT App Inventor 2, I finally completed my second generation of Color LED Controller V2.0 App.

Basically, 2nd generation of Android APP shows a color RGB wheel on the display and you might pick any color on the display to wirelessly change the RGB color accordingly. With glide/drag capability built in the App, you may glide your finger through the color wheel to see RGB LED changes color gradually.

For the Arduino part, all the code stays the same. Yes, I haven't modified a single line of code in the Arduino.

Please watch the video below to see how it works! :)

Here are the App coding screenshot for your reference:

0) Sorry blog readers....here are the two missing global variable blocks.... :-)

1) App Inventor 2 screen initialisation code.

2) Android to HC-05 Bluetooth connection code.

3) The button to turn on/off LED

4) Code for touch on the color wheel to change LED color

 5) Code for Glide/Drag finger across the color wheel to see the color change accordingly

6) Here is the code for RGB color code split and then send to Arduino to change RGB LED color through Bluetooth.

How RGB Color Code was Processed:==*==*==*====*====*====*====*====*====*====*====*====*====*====*==
In App Inventor, the color code string after [Split Color] will be something like "(255 255 255 255)". What I need in Arduino is only R, G B, so I have to remove last 255.

*** The last 255 is a string in color code and it will be 255 all the time***

For easier string processing, I replace " "(space) with a "." (dot).
Then, I send each color code string to Arduino as "255.255.255)"

In side Arduino, I could split R, G, and B easily with the "."(dot) and use ending ")"(parenthesis) to check if the color code is complete or not.

After you put all these codes into MIT App Inventor 2, you should able to build the code on your PC/Mac to generate an Android .APK to place on your Android phone to test it out with Arduino.

Please do not ask me to post the original code here for you to download. If I do so, no one would download my App from Android Play Store! ;)

If you don't want to create this App yourself, please Download this App here!

Happy coding!!



Part II - Android HC-05 藍芽連線控制彩色 RGB LED

你們可能已經讀過我上一次的Arduino硬體設定和下載了第一代APP。如果還沒看過,可參閱我上一個教學 Android 藍芽連線控制彩色 LED

經過幾個禮拜的努力,我終於完成我第二代的 LED 遙控 APP 了。

基本上第二代的設計是一個可以任君挑選顏色RGB調色盤。你可以點選你想要的顏色或是用手指滑過螢幕上的任一個顏色,應用程式會透過藍芽把顏色代碼送變 Arduino 來改變 RGB LED 燈泡的顏色。

Arduino 程式碼的部分是維持跟之前一樣,一行程式碼都不用更改就能使用了。


MIT App Inventor 的程式代碼如下:

1) App Inventor 2 Screen1 初始化設定:

2) Android 連結到 Arduino + HC-05 藍芽模組程式碼:

3) 這組程式碼是用來開關 RGB LED

4) 這組程式碼是用來回應點選的顏色並改變 LED 顏色

 5) 這組程式碼是用來控制滑過螢幕並即時改變其顏色

6) 這組程式碼是用來把顏色編碼成 RGB 代號並且把這組編碼顏色代號以藍芽送到Arduino該LED依照代碼變色。

只要按照以上程式碼輸入MIT App Inventor 2後,你就應該可以做成一個APK檔案。
Sorry, 我不會把原始檔整會貼在這裡,所以請你動手做做看吧!!

如果不想動手做,那請從 Play Store 下載吧