The aim of this first project was to know the basic things of how did arduino and app inventor work together, using an HC-05.
Here's the list of components I used:
And here is the scheme of the circuit, made with fritzing:
Below you have the code I used on the Arduino:
#include< SoftwareSerial.>
SoftwareSerial BT(10,11);
void setup() {
// put your setup code here, to run once:
BT.begin(9600);
Serial.begin(9600);
pinMode(12,OUTPUT);
}
char dato;
void loop() {
// put your main code here, to run repeatedly:
if(BT.available())
{
dato=(BT.read());
Serial.println(dato);
if (dato=='A'){
digitalWrite(12,HIGH);
}
if (dato=='B'){
digitalWrite(12,LOW);
}
}
}
And here you have the blocks and design of the app inventor:
Scan to get the app:
This code is quite simple. By using it, you are ordering the arduino to turn on the LED if it recieves an A and to turn of the LED if it recieves a B. The letters are send by the app, as it is on the code:
The aim of this first project was to know the a bit more of how did arduino and app inventor work together, using an HC-05, and also making something a bit more complex to transfer it into some future projects
Here's the list of components I used:
And here is the scheme of the circuit, made with fritzing:
Below you have the code I used on the Arduino:
#include
int btTx = 10;
int btRx = 11;
SoftwareSerial bluetooth(btTx, btRx);
void setup()
{
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(9,OUTPUT);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(9,LOW);
Serial.begin(9600);
bluetooth.begin(9600);
}
void loop()
{
if(bluetooth.available()>=2 )
{
int color1 = bluetooth.read();
Serial.println(color1);
int color2 = bluetooth.read();
Serial.println(color2);
int color = (color2 *256) + color1;
Serial.println(color);
if (color >=1000 && color <1255){
int red= color;
red = map(red,1000,1255,0,255);
red = constrain(red,0,255);
//red=255-red;
analogWrite(9,red);
Serial.println("red:");
Serial.println(red);
delay(2);
}
if (color >=2000 && color <2255){
int green= color;
green = map(green,2000,2255,0,255);
green = constrain(green,0,255);
//green=255-green;
analogWrite(6,green);
Serial.println("green:");
Serial.println(green);
delay(2);
}
if (color >=3000 && color <3255){
int blue= color;
blue = map(blue,3000,3255,0,255);
blue = constrain(blue,0,255);
//blue=255-blue;
analogWrite(5,blue);
Serial.println("blue:");
Serial.println(blue);
delay(2);
}
}
}
And here you have the blocks and design of the app inventor:
Scan to get the app:
The app sends numbers between 1000-1225/2000-2225/3000-3225, dependig if the color selected is green, red or blue. This information is recieved by the arduino, which turns on or off on color or another