Random Nerd Tutorials
Shares

Android App – RGB LED with Arduino and Bluetooth

Shares

In this project you’re going to build an Android app to control the color of an RGB LED with a smartphone via bluetooth.

You’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.

If you’re not familiar with RGB LEDs, read the following post: How do RGB LEDs work?

Download Android Apps for Arduino with MIT App Inventor 2

Parts Required

Here’s a complete list of the parts required for this project:

Additionally, you also need a smartphone with bluetooth.

Creating the Android App

The Android App will be created using a free web application called MIT App Inventor. MIT App Inventor is a great place to get started with Android development, because it allows you to build simple apps with drag-n-drop.

You need a Google account to sign up for MIT App Inventor and here’s the login page: http://ai2.appinventor.mit.edu.

After login in go to Projects >Import project (.aia) from my computer and upload the .aia file. Click here to download the .aia file.

import

After uploading the .aia file. You’ll see the application on the MIT App Inventor Software.

Designer

With MIT App Inventor you have 2 main sections: designer and blocks.

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:

The app looks different in the software and in your smartphone. This is the how the app looks in our smartphone:

Blocks

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):

Installing the App

To install the app in your smartphone, go to the Build tab.build

  • You can either generate a QR code that you can scan with your smartphone and automatically install the app in your smartphone.
  • Or you can download the .apk file, connect your smartphone to your computer and move the .apk file to the phone.

Simply follow the installation wizard to install the App and it’s done!

Code

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.

Note: before uploading the code, make sure you have the TX and RX pins disconnected from the bluetooth module!

Schematics

Follow the schematic diagram in the following figure to wire your circuit.

Note: If you’re using an RGB LED common cathode, you need to connect the longer lead to GND.

Important: Here’s the bluetooth module connections to the Arduino:

  1. Bluetooth module TX connects to Arduino RX
  2. Bluetooth module RX connects to Arduino TX

Here’s how your circuit should look:

Launching the App

If you haven’t generated the .apk file in a previous step, you can click here to download the .apk file (which is the Android App installation file). Move that file to your smartphone and open it. Follow the installation wizard to install the app.

Turn on your smartphone’s Bluetooth.

screenshot_2016-10-09-15-14-52-copy

Make sure you pair your smartphone with the bluetooth module – search for paired devices in your smartphone’s bluetooth settings.

Then, open the newly installed app. Tap on the Connect bluetooth button to connect via bluetooth to the arduino bluetooth module.

Select your Bluetooth module (it should be named linvor).

Now, it’s ready to use!

Demonstration

Here’s your app in action. Move the sliders and click on CHANGE COLOR to set your RGB LED color to the selected color.


Troubleshooting

1.  I can’t upload code to my Arduino board.

Check if you have the TX and RX cables from the bluetooth module disconnected.

When you’re 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.

 2. I can’t find my bluetooth module device.

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’s often called: linvor, HC-06, HC-04, HC-05 …). Pair with it. If it asks for a password, it’s 1234.

3. The app doesn’t interact with the Arduino.

If your Android app is connected to your bluetooth module, it should display the “Connected” message (as shown below). Otherwise, press the “Connect Bluetooth” to establish a bluetooth communication.

Double-check your bluetooth module connections:

  1. Bluetooth module TX connects to Arduino RX
  2. Bluetooth module RX connects to Arduino TX

4. My bluetooth module is asking for a password.

If your bluetooth module asks for a password, type 1234.

Wrapping up

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.

Now, feel free to change how the app looks and give it more functionalities.

If you like this project, make sure you check our latest course: Android Apps for Arduino with MIT App Inventor 2.

Thanks for reading,

Rui andSara

Recommended Resources

Home Automation using ESP8266 »
Build IoT projects and home automation gadgets with the ESP8266 Wi-Fi module.

Build a Home Automation System »
Learn how to build a automation system using open-source hardware and software from scratch.

Arduino Step-by-Step Projects »
Build 25 cool Arduino projects with our couse even with no prior experience!

Leave a Comment:

Add Your Reply

⏰ Early Black Friday 2017 Special ⏰
Download all our courses up to 35% off