Introduction: Arduino Led/Strips RGB Bluetooth (Arduino + App Inventor)
In this tutorial i will show how to use App Inventor and connect it with arduino using bluetooth
Step 1: What You Need and Schematic
Well this is the list as usuall nothing change if you here for script just scroll it
- Connection internet
- Android Phone (of course)
- Sign up it's free (not promotion) App Inventor
- Arduino + Bluetooth module
- LED/Strip RGB
- Resistor 100/200/330
Step 2: Arduino Code Declaration and Setup
First declare the variables, number port, etc. (Replace " with < )
#include "SoftwareSerial.h" #include "Wire.h" SoftwareSerial BT(10,11);
I'm using port 7 and 8 as RX TX, remember if you want connect the bluetooth module make sure pin RX module connect to pin TX.
int LED_RED = 3; int LED_GREEN = 5; int LED_BLUE = 6; String data = ""; String data_Previous = "255.255.255"; String ON = "LON"; String OFF = "LOFF"; boolean state = false;
the next script is to make sure the pin of RGB LED/Stips goes to pin PWM
void setup() { pinMode (LED_RED, OUTPUT); pinMode (LED_GREEN, pinMode (LED_BLUE, OUTPUT); Serial.begin(9600); BT.begin(9600); data.reserve(30); }
As you can see i named the port for bluetooth as BT so declare it like Serial as usual, make sure the boudrate is same as the configuration on the module (default is 9600).
Step 3: Arduino Code (Main Code)
INSIDE VOID LOOP
while(BT.available()) { char ReadChar = (char)BT.read(); Serial.println("Connected"); if(ReadChar == '+') { state = true; } else { data += ReadChar; } }
The script for checking the bluetooth module is connecte or not, if connected it will receive data and save it to ReadChar.
if (state) { Serial.print("data:"); Serial.print(data); Serial.print(" Predata:"); Serial.print(data_Previous); if (data==ON) { data = data_Previous; Data_LED(); } else if (data==OFF) { data = "0.0.0"; Data_LED(); } else { Data_LED(); data_Previous = data; } data = ""; state = false; }
this is the last section of void loop, the if state to make sure the data is complete if no didn't running the inside it.
FUNCTION DATA LED
int seperator1 = data.indexOf('-'); int seperator2 = data.indexOf('-', seperator1+1); int seperator3 = data.indexOf('-', seperator2+1);
this part it's the main code, because recieve one string it must know where the separator located. It's not posible the values of RGB under 50, using indexOf it will find the number of char we search with this we can know which number to starting the substring function.
String R = data.substring(0, seperator1); String G = data.substring(seperator1+1, seperator2); String B = data.substring(seperator2+1, seperator3);
After get the posisition of each values, the subString function will palce each of number to each variables, seperator increase to make sure didn't read the value before it.
Step 4: App Inventor
This service will make beginner (like me) more easier to make android app just need logic, be patient and internet
First make simple GUI
Start planing or imaging the layout, there two version that i made the black is the first and white is second
2nd open MIT APP or click here
- Is this step click Create apps! on the rigth corner
- Start new project
- Type the name
- Begin design
If you use my source click Projects and chose import aia
Introduction
On this service you need a logic because for each content have their own color and explanation just search if don't understand, it's not hard if you familiar with script/coding.
The main was the color wheel and bluetooth client, here the explanation
COLOR WHEEL
- Color wheel get the value by detect the finger where it touch
- Cursor will follow the finger remember the cursor sometimes didn't perfected allign with the target
- Cursor will get the value X and Y and
- This value will used by function of getBackgroundPixelColour, basicly like color picker on the other apps
- There are 3 values (Red,Green,Blue) each of value seperate by number of list (start from 1)
- That's it the simple way to make color wheel
BLUETOOTH
- After got the value and send it by adding - for each character and add + in the end using funcion of join
- Send it to serial
Step 5: Concluesion
Sorry for my bad english, i was testing and found the problem with my RGB LED (The red diode wont to bright event i use 100R). I'll make the RGB Strip if a have, i trying the 3trd version my plane to make more features like party light, custom party light and improve somethings.
If it really works if not corrects me too. Happy Coding ^^
This is all file from my project