Showing posts with label Bluetooth. Show all posts
Showing posts with label Bluetooth. Show all posts

2026/08/31

多年前寫的Android App又被 Google 要求升級了!

 幾乎每隔幾年, Google Play store 都會要求更新 Android SDK 的版本. 今年要求更新到 API Level 36.



這款 Color LED Controller App 是我和我兒子多年前開發的. 主要功能是透過藍牙連線來控制 RGB LED. 目前在 Google Play 上獲得 5.0 星評分,下載次數超過 10 萬次。

用途:搭配 Arduino 或相容模組,讓手機能直接控制 LED 顏色與亮度。



特色:

支援多種 Android 裝置

簡單直覺的操作介面

適合 Maker、學生或喜歡 DIY 燈光效果的使用者

版本更新:目前已更新至 v3.4,符合 Google 最新 Android API Level 要求。

如果你有興趣的話, 我的部落格裡有完整的免費的軟硬體教學+程式碼完全公開~ 😊


硬體教學:

https://stonez56.blogspot.com/2014/09/arduino-android-led.html

手機 App 教學:

https://stonez56.blogspot.com/2015/02/arduino-project-android-control-color.html


2021/07/11

Android control color RGB LED (Revised for ESP32)

ESP32 Source code on the bottom of this article! 

See the original complete project tutorial here: Android RGB LED Arduino Controller




In September 2014, I created this project with Arduino Mini Pro Mini and Android APP loved by so many readers!  There are more than 100,000 App downloads by now!  Since then, quite of few readers asked me how to change the sketch to be used on ESP32 with built-in Bluetooth.  Here it is!! 😀


Be aware that LED PWM pins used on ESP32 were completely different, since Arduino Mini Pro and ESP32 have different architectures. 

For ESP32, I used following pins:

  • Pin 13 = Red
  • Pin 12 = Green
  • Pin 14 = Blue
Caution: ESP32 does not allow to use pin 6, 7, 8, 9, 10, 11 or it will crash and reboot. I tried...😂


Also, there is no analogWrite() function in ESP32, so I need to change analogWrite() to ledcWrite() with 
  • Channel definition for PWM
    • R channel = 0
    • G channel = 1
    • B channel = 2
  • Setup PWM frequency: 5000
  • Setup PWM resolution: 8 (8bit = 255 colors)
Then I need to setup LED with:
  • ledcSetup( channel, frequency, resolution)
And then attach LED pins to channel
  • ledcAttachPin(Pin, channel)
Then write to LED pins with
  • ledcWrite( channel, value for resolution(0~255));


END

2015/09/13

Android control RGB LED using HC-05 Bluetooth module with Arduino (Part III) - Make A Night Lamp

It's been a while since I wrote the RGB LED tutorial on my blog. Not sure if you have done yours.

If you would like to learn the whole project from the scratch, please visit these two tutorial first.
- Tutorial 1
- Tutorial 2

Recently, I have found a night lamp laying around and we were not used it anymore. I thought, umm.. it might be a good idea to DIY RGB LED into this lamp. Let's get started!

This is what the lamp looks like below. It's powered up by a 9V/300mAh adapter. Since Arduino Mini Pro only take 5V or 3.3V, I had to replace a 5V/500mAh adapter from older 2G phones to use with this night lamp.
After I opened the light lamp, there was tiny PCB, few wires, and a very small lightbulb under the transparent cover. I removed most of stuff inside to make room for my Arduino board.














Since this is a night lamp, there is no need to let this lamp too bright. I decided to use 6 RGB LED to be the light source.  Please refer to my RGB LED tutorial 1 to see the how to wire up.
After soldered the LEDs, resistors, and wires, I cut down extra LED legs to ensure they could fit into the lamp.

There were only few things to solder on Arduino Mini Pro pins with RGB LED and signal wires.

HC-05 Bluetooth Module wiring as follow:

  • TX connect to Arduino Pin 11(RX)
  • RX connect to Arduino Pin 12(TX)
  • Remember to connect TX on the HC-05 to RX on the Arduino and RX on the HC-05 to TX on the Arduino, so Arduino can receive data correctly.
  • VCC connect to 5V power
  • GND connect to Ground
All parts were soldered together; including Arduino, wires, RGB LED.














Then, I attached HC-05 Bluetooh module on the the Arduino Mini Pro. 



** Remember to test it the whole thing to make sure it's working before you continue.**
I also cut the porto board in half to save more space below.














Look at the picture where I circled, I needed to keep the original connector to connect to Arduino Mini Pro, so the power plug can be inserted correctly into the lamp plug.















Here is the original PCB module come with the lamp. I just removed the connector with a plier instead of desoldering it.  Believe me, I did try to desolder the connector from the PCB and it was really difficult for me, even with a tiny tool that sucked the soldering away from PCB.


There is a battery compartment under this night lamp. So I decided to put HC-05 Bluetooth module into this compartment to save space.  By doing this, I had to insert 4 wires to go through the tiny hole in the center that was originally holding the light bulb. Since the thickness of the compartment door is quite thin, I could see the HC-05 Bluetooth LED indicator to see if it's connected or not! :)
** Fast flash: Not connected.
** Flash twice per 2 seconds: Connected.


After removed the light bulb, I was trying to find the perfect spot to place PCB and Arduino Mini Pro.  By the way...I almost forgot to solder the connector back to the power wires.

Now, it's time to put all components inside the lamp. I decided to use hot glue to place the PCB with RGB LED on the center and inserted Arduino Mini Pro next to the screw column.
Secure the connector with the original screws and a lot glue to keep them in place using a hot glue gun.
More hot glue to ensure the PCB and connector to fix and secure.


Power it up! Cool, it's working now! I modified Arduino programming a little bit to set my PCB to light up with Blue color as soon as it powered up.

Finally, I placed the cover back and tighten two screws and it's done!  This is my 2nd projects that really worked!

Now, I set next beside my children's bed to let him enjoy this magic night lamp and he loved it! :)

See the working video below:


END


Part III - Android HC-05 藍芽連線控制彩色 RGB LED: DIY 以手機控製夜燈

自從我把製作手機用藍芽搖控 RGB LED 彩色貼到部落格上,也有一段時間了。不知道你是否也依著步驟,DIY了你自己的呢?

如果你想要從頭開始的話呢,你可以先瀏覽前面兩篇來照著做,不會很困難的!
- Arduino + BT + RGB LED 教學 1
- Arduino + BT + RGB LED 教學 2

最近,發現有一個股東會贈品的小夜燈放在角落沾著灰塵,也很久沒使用了。心裡想著,那就把之前的東西塞到這個小夜燈裡,讓它可以像一個正常的夜燈使用,又可以用手機改變頻色,小朋友應該很喜歡!

我手上小夜燈看來如下圖,它是以一個 9V/300mA 變壓器來供電。不過Arduino Mini Pro 只能用 3.3V or 5V, 所以我找了一個早期2G手機用不到的5V/500mA 變壓器才取代。
打開小夜燈的上蓋,裡面的空間還算多,只有一片小小PCB, 幾條線和一個小燈泡。
看來要塞進去這個project全部的零件不是問題。














反正是個小夜燈,用不著太亮,所以我只用了6個RGB LED並聯在一起。
連接方法請參考 RGB LED 教學 1
把 LED, 電阻, 電線焊好後,再把過長的 LED 腳剪斷就行了。

為了方便參考, 這裡是連接的方法,唯一不同的是把 6 個 RGB LED 並聯就行了。

HC-05 Bluetooth Module wiring as follow:

  • TX connect to Arduino Pin 11(RX)
  • RX connect to Arduino Pin 12(TX)
  • Remember to connect TX on the HC-05 to RX on the Arduino and RX on the HC-05 to TX on the Arduino, so Arduino can receive data correctly.
  • VCC connect to 5V power
  • GND connect to Ground
接著把線路和 Arduino Mini Pro 焊上。














接下來,把 HC-05 籃芽模組也一起焊上。


** 別忘了先試試整個電路板都運作正常 **
洞洞板還蠻大一片的,所以把它剪一半掉以節省空間。














底下圈起來的是原先小夜燈用的連結座,我要把這個連結座拆下來,這樣搭配 5V/500mA的變壓器使用剛剛好。















這個是小夜燈上面拆下來的PCB,其實我要的只是那個連結器,其它用不到了。我試過用空空吸錫的小工具把連結器解銲下來。天啊,還真的不容易啦...那位高手再教一下吧!


小夜燈底下有個裝電池的空間(如下圖)。我把藍芽模組 HC-05 經由裝燈泡的洞穿過去,這樣可以節省一些空間。電池座的塑膠門剛好又非常的薄,所以可以這裡看到 HC-05 藍芽連接的燈號。
** 快速閃爍: Not connected.
** 每兩秒閃二之: Connected.


PCB, Arduino 放置的方式如下圖,PCB放在中間,而 Arduino Mini Pro 放在螺絲座的旁邊。

接下來把剛剛接下來的連結座給焊上去。
把連接器旁邊的小螺絲鎖緊,再用很多的熱熔膠把它們固定。
用更多的熱熔膠把 PCB+LED 固定在夜燈正中間。


插上電源試試! 把前面的教學程式稍作修改,該每次接上電源後,讓它點亮藍色的。

最後,把外蓋蓋回去,鎖上螺絲就完成了!這是我做 Arduino 以來的第二個作品可以用在生活中!

現在,我把這個小夜燈放在小孩的房間裡,讓他使用這個可以隨時心情改變顏色!

這是實際運作的影片!

完!

2015/02/15

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! :)
https://www.youtube.com/watch?v=YrEV-Lf-Cxs





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

Stonez


--------------------------------------------------------------------------------------------------------------------

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


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

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

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

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

請先看一下底下影片的示範:
https://www.youtube.com/watch?v=YrEV-Lf-Cxs






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 下載吧

Stonez