Bluetooth & AppInventor (1)

 

Hello, today we're gonna explain ho to create an app with Appinventor and how to communicate it with Arduino . We connect bluetooth module to Arduino like we told you at  last post with mobile's bluetooth trought a simple app with Appinventor.

First we create a little program for Arduino, only to send an order via Bluetooth and do something easy with Arduino board, for example switch LED on/off .

We will use the next program : 

 

#include 

#define txPin 3 // definimos txpin en que pin de arduino se encuentra
#define rxPin 2 // definimos rxpin en que pin de arduino se encuentra 

SoftwareSerial bluetooth(rxPin, txPin); // el puerto nuevo de comunicacion se llamar bluetooth

char NOMBRE[10]  = "TEST1";  // asignamos un nombre a nuestro modulo bluetooth para cuando lo veamos en linea 
char BPS         = '4';           // 1=1200 , 2=2400, 3=4800, 4=9600, 5=19200, 6=38400, 7=57600, 8=115200
char PASS[10]    = "1234";   // password para realizar la conexion. Sino funciona 0000
 
char INBYTE;
int  LED = 13; // LED on pin 13 // hacemos que el led 13 de Arduino integrado nos sirva de prueba

void setup() {
  Serial.begin(9600); // velocidad de la comunicacion entre arduino y ordenador 
 Serial.println("Estoy preparado"); //mensaje de comprobacion
   pinMode(LED, OUTPUT);
  bluetooth.flush();            // Borramos el buffer del serial para evitar errores
  pinMode(rxPin, INPUT);     // Configuramos los pines del bluetooth 
  pinMode(txPin, OUTPUT);
  bluetooth.begin(9600);  // marcamos la velocidad del puerto bluetooth 

}
 
void loop()
{
  while (!bluetooth.available());   // mientras el puerto este disponible ejecuta el programa
  INBYTE = bluetooth.read();        // lee la comunicacion bluetooth
  if( INBYTE == '2' ) 
    {
      digitalWrite(LED, LOW);  // si pulsas el numero 3 escribe en el led apagado
      bluetooth.println("Has presionado 2"); //muestra en el ordenador que tecla se ha pulsado
    }
  if( INBYTE == '1' ) 
  {
    digitalWrite(LED, HIGH); // si pulsas el numero 4 escribe led encendido
    bluetooth.println("Has presionado 1");
  }
  delay(50);
  
}
 
The line "if INBYTE ==…. then …" told us what happend when you push 1 or 2 on keyboard. If you push 1 on app button then switch ON LED and when you push 2 on app button then switch OFF LED. 

(Download program)

Now e have finished the program, let's go to create the app on Appinventor. We create a new project and we drag and drop two buttons, one dor switch ON and switch OFF.

Now we change the name of the buttons (optional) 

We arrange the buttons horitzontaly

We add a "list pick" to create the "bluetooth connect button". The button will change the color when bluetooth is active (that's it because we need a list pick instead a simple button)

We add bluetooth to screen 

After that we work with Block Appinventor (top right) and we start to program our app.

This is the bluetooth block . We could see that we check the bluetooth connection first and if is correct the bluetooth change to blue color. 

The two last blocks are create to send the character "1" and "2" to switch ON or OFF our LED in the Arduino board. As you can see we can send whatever character you want, then you could add more functions to send at arduino board. 

After these steps we create a QR code  , we download the app to mobile 

When we open th app we push "conexión" and we could see the MAC of bluetooth module. Then we connect (maybe you have to use the password 1234 or 1111 ). The red led on bluetooth module stops blinking and then is connect correctly.

We test the buttons ON and OFF and we could see how it switch ON or OFF LED

 

See you in the next article

English

Comments

Thanks for finally writing about > Add new comment
| gerdsLAB chwilówki bez bik</a>

Thank you for another wonderful post. The place
else may anyone get that kind of information in such a
perfect method of writing? I've a presentation subsequent
week, and I am on the look for such info.

my web site ... chwilówki kredyty - http://zhushaowei.com/index.php?title=How_To_Use_spend_Day_financial_Loa....

Nice post. I was checking continuously this blog and I'm
impressed! Extremely helpful information specially the
last part :) I care for such info a lot. I
was looking for this particular information for a very long time.
Thank you and good luck.

creditos rapidos online sin aval - http://www.speedtree.com/forum/showthread.php?3500-The-art-of-landscapin...(botanically-correct-plant-modeling)/page2
http://gpar.org/member/1153844
http://gothreformschool.blogspot.com/
http://glink.jp/xoops/html/userinfo.php?uid=1141263

This paragraph is genuinely a pleasant one it helps new the web viewers, who are wishing
in favor of blogging.

Feel free to surf to my web-site cialis cena - http://wiki.heaventohell.org/index.php?title=Penis_overall_Health_Hygiene.

Awesome! Its really amazing post, I have got much clear idea about from
this piece of writing.

Here is my weblog pożyczki chwilówki - http://www.wpego.com/bbs/home.php?mod=space&uid=451953&do=profile&from=s...

Helpful information. Lucky me I discovered your web site unintentionally, and I am shocked why this coincidence didn't happened in advance!

I bookmarked it.

My blog post; Shoe Lifts - http://www.deelsonheels.com/$1799__Silicone_Shoe_Lifts__Free_Delivery/p133745_317467.aspx

Pages

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.