{"id":36908,"date":"2017-05-04T06:32:11","date_gmt":"2017-05-04T06:32:11","guid":{"rendered":"http:\/\/randomnerdtutorials.com\/?p=36908"},"modified":"2019-04-02T10:23:29","modified_gmt":"2019-04-02T10:23:29","slug":"android-app-rgb-led-with-arduino-and-bluetooth","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/android-app-rgb-led-with-arduino-and-bluetooth\/","title":{"rendered":"Android App &#8211; RGB LED with Arduino and Bluetooth"},"content":{"rendered":"<p>In this project you&#8217;re going to build an Android app to control the color of an RGB LED with a smartphone via Bluetooth.<!--more--><\/p>\n<p>You&#8217;re going to build the Android app using a free web based software called MIT App Inventor 2. This is a great project to learn how to interface the Arduino with a smartphone.<\/p>\n<p><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-36946\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/RGB-LED-App-GIF.gif?resize=480%2C270&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"480\" height=\"270\" \/><\/p>\n<p>If you&#8217;re not familiar with RGB LEDs, read\u00a0the following post:\u00a0<a href=\"https:\/\/randomnerdtutorials.com\/electronics-basics-how-do-rgb-leds-work\/\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>How do RGB LEDs work?<\/strong><\/a><\/p>\n<p><strong><a href=\"https:\/\/randomnerdtutorials.com\/android-apps-for-arduino-with-mit-app-inventor-2\/\" target=\"_blank\" rel=\"noopener noreferrer\">Download Android Apps for Arduino with MIT App Inventor 2<\/a><\/strong><\/p>\n<h2>Parts Required<\/h2>\n<p>Here&#8217;s a complete list of the parts required for this project:<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter size-full wp-image-36943\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/parts.jpg?resize=700%2C474&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"700\" height=\"474\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/parts.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/parts.jpg?resize=150%2C102&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/parts.jpg?resize=300%2C203&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/parts.jpg?resize=80%2C54&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/parts.jpg?resize=220%2C149&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/parts.jpg?resize=148%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 148w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/parts.jpg?resize=222%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 222w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/parts.jpg?resize=351%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 351w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/parts.jpg?resize=613%2C415&amp;quality=100&amp;strip=all&amp;ssl=1 613w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<ul>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/compatible-arduino-uno-r3-board\/\" target=\"_blank\" rel=\"noopener noreferrer\">Arduino UNO<\/a>\u00a0\u2013 read\u00a0<a href=\"https:\/\/makeradvisor.com\/best-arduino-starter-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">Best Arduino Starter Kits<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/bluetooth-module-hc-06\/\" target=\"_blank\" rel=\"noopener noreferrer\">Bluetooth module HC-04 or HC-05 or HC-06\u00a0<\/a><\/li>\n<li>RGB LED (common anode)<\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">3 x 220Ohm resistor\u00a0<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noopener noreferrer\">Breadboard<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noopener noreferrer\">Jumper wires<\/a><\/li>\n<\/ul>\n<p>Additionally, you also need a smartphone with bluetooth.<\/p>\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n<h2>Creating the Android App<\/h2>\n<p>The Android App will be created\u00a0using a free web application\u00a0called\u00a0<a href=\"http:\/\/appinventor.mit.edu\/explore\/\" target=\"_blank\" rel=\"noopener noreferrer\">MIT App Inventor<\/a>. MIT App Inventor is a great place to get started\u00a0with Android development, because it allows you to build simple apps with drag-n-drop.<\/p>\n<p>You need a Google account to sign up for MIT App Inventor and here\u2019s the login page: <a href=\"http:\/\/ai2.appinventor.mit.edu\/\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/ai2.appinventor.mit.edu<\/a>.<\/p>\n<p>After login in go to\u00a0<strong>Projects &gt;Import project (.aia) from my computer<\/strong> and upload the .aia file.<strong> <a href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/blob\/master\/Projects\/MIT-App-Inventor\/Control_RGB_LED.aia?raw=true\" target=\"_blank\" rel=\"noopener noreferrer\">Click here to download the .aia file.<\/a><\/strong><\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i0.wp.com\/rntlab.com\/wp-content\/uploads\/2016\/10\/import.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"import\" \/><\/p>\n<p>After <a href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/blob\/master\/Projects\/MIT-App-Inventor\/Control_RGB_LED.aia?raw=true\" target=\"_blank\" rel=\"noopener noreferrer\">uploading the .aia file<\/a>. You&#8217;ll see the application on the MIT App Inventor Software.<\/p>\n<h3>Designer<\/h3>\n<p>With MIT App Inventor you have 2 main sections: <strong>designer<\/strong> and <strong>blocks<\/strong>.<\/p>\n<p>The designer is what gives you the ability to add buttons, add text, add screens and edit the overall app look. Int the App Inventor software the app looks like this:<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter size-full wp-image-36909\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/designer.png?resize=1200%2C524&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"1200\" height=\"524\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/designer.png?w=1344&amp;quality=100&amp;strip=all&amp;ssl=1 1344w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/designer.png?resize=150%2C66&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/designer.png?resize=300%2C131&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/designer.png?resize=768%2C335&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/designer.png?resize=1024%2C447&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/designer.png?resize=80%2C35&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/designer.png?resize=220%2C96&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/designer.png?resize=229%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 229w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/designer.png?resize=280%2C122&amp;quality=100&amp;strip=all&amp;ssl=1 280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/designer.png?resize=510%2C223&amp;quality=100&amp;strip=all&amp;ssl=1 510w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/designer.png?resize=750%2C328&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/designer.png?resize=975%2C426&amp;quality=100&amp;strip=all&amp;ssl=1 975w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/designer.png?resize=1190%2C520&amp;quality=100&amp;strip=all&amp;ssl=1 1190w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<p>The app looks different in the software and in your smartphone. This is the how the app looks in our smartphone:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-36910\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47.png?resize=259%2C461&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"259\" height=\"461\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47.png?w=480&amp;quality=100&amp;strip=all&amp;ssl=1 480w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47.png?resize=84%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 84w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47.png?resize=169%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 169w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47.png?resize=45%2C80&amp;quality=100&amp;strip=all&amp;ssl=1 45w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47.png?resize=124%2C220&amp;quality=100&amp;strip=all&amp;ssl=1 124w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47.png?resize=56%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 56w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47.png?resize=134%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 134w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47.png?resize=233%2C415&amp;quality=100&amp;strip=all&amp;ssl=1 233w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47.png?resize=274%2C487&amp;quality=100&amp;strip=all&amp;ssl=1 274w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47.png?resize=334%2C595&amp;quality=100&amp;strip=all&amp;ssl=1 334w\" sizes=\"(max-width: 259px) 100vw, 259px\" \/><\/p>\n<h3>Blocks<\/h3>\n<p>Then, you have the blocks section. The blocks sections is what allows to create custom functionality for your app, so when you press the buttons it actually does something with that information. These are the blocks for this app (click on the image to zoom):<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/blocks.png?quality=100&#038;strip=all&#038;ssl=1\" target=\"_blank\" rel=\"noopener noreferrer\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-36911 size-full\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/blocks.png?resize=1055%2C457&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"1055\" height=\"457\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/blocks.png?w=1055&amp;quality=100&amp;strip=all&amp;ssl=1 1055w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/blocks.png?resize=150%2C65&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/blocks.png?resize=300%2C130&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/blocks.png?resize=768%2C333&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/blocks.png?resize=1024%2C444&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/blocks.png?resize=80%2C35&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/blocks.png?resize=220%2C95&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/blocks.png?resize=231%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 231w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/blocks.png?resize=280%2C121&amp;quality=100&amp;strip=all&amp;ssl=1 280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/blocks.png?resize=510%2C221&amp;quality=100&amp;strip=all&amp;ssl=1 510w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/blocks.png?resize=750%2C325&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/blocks.png?resize=975%2C422&amp;quality=100&amp;strip=all&amp;ssl=1 975w\" sizes=\"(max-width: 1055px) 100vw, 1055px\" \/><\/a><\/p>\n<h3>Installing the App<\/h3>\n<p>To install the app in your smartphone, go to the <strong>Build<\/strong> tab.<img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4957\" src=\"https:\/\/i0.wp.com\/rntlab.com\/wp-content\/uploads\/2016\/10\/build.png?resize=416%2C122&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"build\" width=\"416\" height=\"122\" \/><\/p>\n<ul>\n<li>You can either generate a QR\u00a0code\u00a0that you can scan with your smartphone and automatically install the app in your smartphone.<\/li>\n<li>Or you <a href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/blob\/master\/Projects\/MIT-App-Inventor\/Control_RGB_LED.apk?raw=true\" target=\"_blank\" rel=\"noopener noreferrer\">can download the <em>.apk<\/em> file<\/a>, connect your smartphone to your computer and move the <em>.apk<\/em> file to the phone.<\/li>\n<\/ul>\n<p>Simply follow the installation wizard to install the App and it\u2019s done!<\/p>\n<h2>Code<\/h2>\n<p>Download or copy the following code to your Arduino IDE, and upload it to your Arduino board. Make sure you have the right Board and COM port selected.<\/p>\n<p><strong><span style=\"color: #ff0000;\">Note<\/span>: before uploading the code, make sure you have the TX and RX pins disconnected from the bluetooth module!<\/strong><\/p>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n * Rui Santos \n * Complete Project Details http:\/\/randomnerdtutorials.com\n *\/\n\n#define max_char 12\nchar message[max_char];    \/\/ stores you message\nchar r_char;               \/\/ reads each character\nbyte index = 0;            \/\/ defines the position into your array\nint i;\n\nint redPin = 11;     \/\/ Red RGB pin -&gt; D11\nint greenPin = 10;   \/\/ Green RGB pin -&gt; D10\nint bluePin = 9;     \/\/ Blue RGB pin -&gt; D9\n\nint redValue = 255;     \/\/ Red RGB pin -&gt; D11\nint greenValue = 255;   \/\/ Green RGB pin -&gt; D10\nint blueValue = 255;     \/\/ Blue RGB pin -&gt; D9\n\nString redTempValue;     \/\/ Red RGB pin -&gt; D11\nString greenTempValue;   \/\/ Green RGB pin -&gt; D10\nString blueTempValue;     \/\/ Blue RGB pin -&gt; D9\n\nint flag = 0;\nchar currentColor;  \n\nvoid setup() {\n  pinMode(redPin,OUTPUT);\n  pinMode(bluePin,OUTPUT);\n  pinMode(greenPin, OUTPUT);\n  \/\/ initialize serial communication at 9600 bits per second:\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  \/\/while is reading the message \n  while(Serial.available() &gt; 0){\n    flag = 0;\n    \/\/the message can have up to 12 characters \n    if(index &lt; (max_char-1)){         \n      r_char = Serial.read();      \/\/ Reads a character\n      message[index] = r_char;     \/\/ Stores the character in message array\n      if(r_char=='R'){\n         currentColor = 'R';\n         redTempValue = &quot;&quot;;\n      }\n      else if(r_char=='G'){\n         currentColor = 'G';\n         greenTempValue = &quot;&quot;;\n      }\n      else if(r_char=='B'){\n         currentColor = 'B';\n         blueTempValue = &quot;&quot;;\n      }\n      if(currentColor == 'R' &amp;&amp; r_char!='R'){\n         redTempValue += r_char;\n      }\n      else if(currentColor == 'G' &amp;&amp; r_char!='G'){\n         greenTempValue += r_char;\n      }\n      else if(currentColor == 'B' &amp;&amp; r_char!='B'){\n         blueTempValue += r_char;\n      }\n      index++;                     \/\/ Increment position\n      message[index] = '\\0';       \/\/ Delete the last position\n   }\n   \n }\n \n if(flag == 0){\n   analogWrite(redPin, 255-redTempValue.toInt());\n   analogWrite(greenPin, 255-greenTempValue.toInt());\n   analogWrite(bluePin, 255-blueTempValue.toInt());\n   \/*Serial.print('R');\n   Serial.println(redTempValue);\n   Serial.print('G');\n   Serial.println(greenTempValue);\n   Serial.print('B');\n   Serial.println(blueTempValue);\n   Serial.print(&quot;MESSAGE &quot;);*\/\n   Serial.println(message);\n   flag=1;\n       for(i=0; i&lt;12; i++){\n      message[i] = '\\0';\n    } \n    \/\/resests the index\n    index=0;  \n }\n\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/MIT-App-Inventor\/Control_RGB_LED.ino\" target=\"_blank\">View raw code<\/a><\/p>\n<h2>Schematics<\/h2>\n<p>Follow the schematic diagram in the following figure to wire your circuit.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-36918\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/rgb_led_controller.png?resize=404%2C529&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"404\" height=\"529\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/rgb_led_controller.png?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/rgb_led_controller.png?resize=115%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 115w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/rgb_led_controller.png?resize=230%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 230w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/rgb_led_controller.png?resize=61%2C80&amp;quality=100&amp;strip=all&amp;ssl=1 61w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/rgb_led_controller.png?resize=168%2C220&amp;quality=100&amp;strip=all&amp;ssl=1 168w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/rgb_led_controller.png?resize=77%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 77w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/rgb_led_controller.png?resize=182%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 182w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/rgb_led_controller.png?resize=317%2C415&amp;quality=100&amp;strip=all&amp;ssl=1 317w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/rgb_led_controller.png?resize=373%2C487&amp;quality=100&amp;strip=all&amp;ssl=1 373w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/rgb_led_controller.png?resize=455%2C595&amp;quality=100&amp;strip=all&amp;ssl=1 455w\" sizes=\"(max-width: 404px) 100vw, 404px\" \/><\/p>\n<p><strong>Note:<\/strong> If you\u2019re using an RGB LED common cathode, you need to connect the longer lead to GND.<\/p>\n<p><strong>Important<\/strong>: Here&#8217;s the bluetooth module connections to the Arduino:<\/p>\n<ol>\n<li>Bluetooth module <strong>TX<\/strong> connects to Arduino <strong>RX<\/strong><\/li>\n<li>Bluetooth module <strong>RX<\/strong> connects to Arduino <strong>TX<\/strong><\/li>\n<\/ol>\n<p>Here&#8217;s how your circuit should look:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-36942\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/circuit.jpg?resize=700%2C394&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"700\" height=\"394\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/circuit.jpg?w=700&amp;quality=100&amp;strip=all&amp;ssl=1 700w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/circuit.jpg?resize=150%2C84&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/circuit.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/circuit.jpg?resize=80%2C45&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/circuit.jpg?resize=220%2C124&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/circuit.jpg?resize=178%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 178w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/circuit.jpg?resize=266%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 266w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/circuit.jpg?resize=423%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 423w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<h2>Launching the App<\/h2>\n<p>If you haven\u2019t generated the .apk file in a previous step, you can\u00a0<a href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/blob\/master\/Projects\/MIT-App-Inventor\/Control_RGB_LED.apk?raw=true\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>click <\/strong><strong>here<\/strong><strong> to download the .apk file<\/strong><\/a> (which is the Android App installation file).\u00a0Move that file to your smartphone and open it. Follow the installation wizard to install the app.<\/p>\n<p>Turn on your smartphone\u2019s Bluetooth.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i0.wp.com\/rntlab.com\/wp-content\/uploads\/2016\/10\/Screenshot_2016-10-09-15-14-52-Copy.png?resize=284%2C505&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"screenshot_2016-10-09-15-14-52-copy\" width=\"284\" height=\"505\" \/><\/p>\n<p>Make sure you pair your smartphone with the bluetooth module &#8211; search for paired devices in your smartphone&#8217;s bluetooth settings.<\/p>\n<p>Then, open the newly installed app. Tap on the\u00a0<strong>Connect bluetooth\u00a0<\/strong>button to connect via bluetooth to the arduino bluetooth module.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-36919\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47-Copy.png?resize=286%2C509&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"286\" height=\"509\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47-Copy.png?w=480&amp;quality=100&amp;strip=all&amp;ssl=1 480w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47-Copy.png?resize=84%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 84w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47-Copy.png?resize=169%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 169w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47-Copy.png?resize=45%2C80&amp;quality=100&amp;strip=all&amp;ssl=1 45w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47-Copy.png?resize=124%2C220&amp;quality=100&amp;strip=all&amp;ssl=1 124w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47-Copy.png?resize=56%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 56w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47-Copy.png?resize=134%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 134w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47-Copy.png?resize=233%2C415&amp;quality=100&amp;strip=all&amp;ssl=1 233w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47-Copy.png?resize=274%2C487&amp;quality=100&amp;strip=all&amp;ssl=1 274w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/Screenshot_2017-04-23-10-05-47-Copy.png?resize=334%2C595&amp;quality=100&amp;strip=all&amp;ssl=1 334w\" sizes=\"(max-width: 286px) 100vw, 286px\" \/><\/p>\n<p>Select your Bluetooth module (it should be named linvor).<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-36920\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/linvor.png?resize=390%2C86&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"390\" height=\"86\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/linvor.png?w=390&amp;quality=100&amp;strip=all&amp;ssl=1 390w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/linvor.png?resize=150%2C33&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/linvor.png?resize=300%2C66&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/linvor.png?resize=80%2C18&amp;quality=100&amp;strip=all&amp;ssl=1 80w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/linvor.png?resize=220%2C49&amp;quality=100&amp;strip=all&amp;ssl=1 220w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/linvor.png?resize=250%2C55&amp;quality=100&amp;strip=all&amp;ssl=1 250w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/linvor.png?resize=280%2C62&amp;quality=100&amp;strip=all&amp;ssl=1 280w\" sizes=\"(max-width: 390px) 100vw, 390px\" \/><\/p>\n<p>Now, it&#8217;s ready to use!<\/p>\n<h2>Demonstration<\/h2>\n<p>Here&#8217;s your app in action. Move the sliders and click on\u00a0<strong>CHANGE COLOR<\/strong> to set your RGB LED color to the selected color.<\/p>\n<p style=\"text-align:center\"><iframe width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/vu8fxEi8NcY?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<h2>Troubleshooting<\/h2>\n<p><strong>1. \u00a0I can&#8217;t upload code to my Arduino board.<\/strong><\/p>\n<p>Check if you have the<strong> TX and RX cables<\/strong> from the bluetooth module\u00a0<strong>disconnected<\/strong>.<\/p>\n<p>When you\u2019re uploading code to your Arduino you should disconnect the TX and RX cables from the bluetooth module. These pins are needed for serial communication between the Arduino and your computer.<\/p>\n<p><strong>\u00a02. I can&#8217;t find my bluetooth module device.<\/strong><\/p>\n<p>Make sure you have paired your smartphone with your bluetooth module. Go to your bluetooth settings and search for the available devices. Your bluetooth module device should appear (it\u2019s often called: linvor, HC-06, HC-04, HC-05 &#8230;). Pair with it. If it asks for a password, it\u2019s 1234.<\/p>\n<p><strong>3. The app doesn&#8217;t interact with the Arduino.<\/strong><\/p>\n<p>If your Android app is connected to your bluetooth module, it should display the \u201c<strong>Connected<\/strong>\u201d message (as shown below). Otherwise, press the \u201cConnect Bluetooth\u201d to establish a bluetooth communication.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-36932\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/connect-bluetooth.png?resize=210%2C76&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"210\" height=\"76\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/connect-bluetooth.png?w=210&amp;quality=100&amp;strip=all&amp;ssl=1 210w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/connect-bluetooth.png?resize=150%2C54&amp;quality=100&amp;strip=all&amp;ssl=1 150w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/connect-bluetooth.png?resize=80%2C29&amp;quality=100&amp;strip=all&amp;ssl=1 80w\" sizes=\"(max-width: 210px) 100vw, 210px\" \/><\/p>\n<p><strong>Double-check your bluetooth module connections:<\/strong><\/p>\n<ol>\n<li>Bluetooth module <strong>TX<\/strong> connects to Arduino <strong>RX<\/strong><\/li>\n<li>Bluetooth module <strong>RX<\/strong> connects to Arduino <strong>TX<\/strong><\/li>\n<\/ol>\n<p><strong>4. My bluetooth module is asking for a password.<\/strong><\/p>\n<p>If your bluetooth module asks for a password, type\u00a0<strong>1234<\/strong>.<\/p>\n<h2>Wrapping up<\/h2>\n<p>In this project you learned how to control the color of an RGB LED with an Android App built with the MIT App Inventor 2 software.<\/p>\n<p>Now, feel free to change how the app looks and give it more functionalities.<\/p>\n<p><strong>If you like this project, make sure you check our latest course: <a href=\"https:\/\/randomnerdtutorials.com\/android-apps-for-arduino-with-mit-app-inventor-2\/\" target=\"_blank\" rel=\"noopener noreferrer\">Android Apps for Arduino with MIT App Inventor 2<\/a>.<\/strong><\/p>\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this project you&#8217;re going to build an Android app to control the color of an RGB LED with a smartphone via Bluetooth.<\/p>\n","protected":false},"author":1,"featured_media":36946,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[308,271,234,267,291,264],"tags":[],"class_list":["post-36908","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-mit","category-android","category-android-app","category-arduino-project","category-bluetooth","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/04\/RGB-LED-App-GIF.gif?fit=480%2C270&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/36908","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=36908"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/36908\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/36946"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=36908"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=36908"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=36908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}