The main idea consist in connecting an Android device to a bluetooth client with the intention of controlling it. This micro-app is the beginning of a Six Servomotor Controller application that will be used to control Armdudroid.
This application could be interesting to start a bluetooth connection with any microcontroller and control it, for example, you can connect it to Arduino and switch ON a light sending a byte, or you could move a servomotor sending the exact position, or whatever! So thinking about it, this is the conclusion:
It is worth!
APP Inventor or AI is a powerful and so easy-to-use tool for creating Android applications with lot of features and in no time. It is an application originally provided by Google, and now maintained by the Massachusetts Institute of Technology (MIT).
While creating an AI application two different parts are developed; the screen objects and the blocks. On the Screen there are the following objects:
- The ActivityStarter as_TurnONBT has this code in the Action textbox: android.bluetooth.adapter.action.REQUEST_ENABLE
- The ActivityStarter as_Pairdevice has android.intent.action.MAIN in Action textbox, com.android.settings.Settings$BluetoothSettingsActivity in ActivityClass textbox and com.android.settings in ActivityPackage.
- All elements are full width and Enabled.
Some tips are:
- Use always screen arrangements for any part of the application. You never now when will you want to hide the pack of items.
- Rename any element or object with its class before, like the Button1 to bt_Connection. They will be organized in the Blocks Editor.
- Set to full with any element. If they are fixed width probably there would be devices not able to open the application or to show all the content.
- Use buttons as labels, they look cooler. Sometime it is necessary to show an ON/OFF label or Connect/Disconnect or labels which change properties, but labels in APP inventor are not stylized so using a button will be better.
Now the blocks:
- Bluetooth enabling if disabled.
- Bluetooth pairing if not devices paired.
- Auto-connection when initialized if a paired device is available and bluetooth is enabled.
- Notifiers to warn the user some issues.
- ON/OFF label to show the status.
Download APP Inventor Bluetooth Connection source by clicking below:
Now SIMPLER but with THE SAME FEATURES!
DOWNLOAD .AIA SOURCE CLICKING BELOW:
Jun 25, 2013 @ 10:46:29
I wanted to use your code which looks great and exactly what i needed. But i am getting a error as soon as the screen loads. the error is
Invalid text operation
Segment: Start (1) + length (17) – 1 exceeds text length (0)
Any idea how to resolve this. I have changed nothing on the code. your help is really appreciated.
Apr 03, 2015 @ 17:12:46
Je suis sur un projet sur app inventor2 qui doit afficher la masse d’un objet sur un pèse lettre ,pour l’instant j’arrive a me connecter en bluetooth et a afficher des bits sur mon application mais je ne vois toujours pas la masse de l’objet pouvez vous m’aidez
Jun 25, 2013 @ 12:39:21
Yes, I know the problem. Sorry for the error, it was my fault.
The error is in the first block of the screen1.initialize blocks, the “MACaddress” block. It should only work if LENGTH-db_MACdatabase.GetValue-ChosenMAC > 0
Your APP doesn’t have a saved MAC address so it is trying to connect to a non valid device. If it doesn’t close and you choose a valid device only once, the error will disappear.
In some minutes I am going to upload the correct source.
Thanks for contacting! 🙂 Cheers!
Jul 09, 2014 @ 09:48:53
My objective is turn ON and Turn OFF LED via app inventor bluetooth block. I tried from youtube example, other chat example, also ardino LED example. but none of them working fine. I am getting same error like 507: Is the device is turned on or 515: unable to connect the device. I need know my mistakes. Here i am using firefly bluetooth from sparkfun and atmega micro controller. OS win7, app inventor beta. but error is same.
Need your valuable feed back to solve this error.
San Diego mobile application
Jul 04, 2013 @ 04:37:16
Hi there very cool blog!! Guy .. Beautiful .. Amazing .. I’ll bookmark your blog and take the feeds additionally?I am glad to find a lot of helpful info here in the put up, we want develop more techniques in this regard, thanks for sharing. . . . . .
Six Servo Controller Android APP | WHTK
Aug 15, 2013 @ 19:22:38
[…] APP uses the Bluetooth Connection I explained in my other post. This is powerful and simple to use. Easily you can Switch your […]
Oct 02, 2013 @ 08:58:09
can you send me the image of bloks for an app:
simple app with three buttons
button 1 will enable bluetooth
button 2 ill display paired bluetooth devices on the phone
button 3 will disconnet and disable buetooth
and also you can add a lable which will display the name of the conected device.
you can mail me the image on: email@example.com
you can also mail me the app
Nov 20, 2013 @ 08:13:38
Is it possible to restrict the user to share the app using blue tooth?
Nov 21, 2013 @ 01:22:24
Hi Sri Hari!
What do you mean? I don’t understand your question
Nov 21, 2013 @ 06:08:54
hello, it’s a cool sharing of information, i learned many ideas about Bluetooth connection. can you please help me with my problem i am using your block in my Bluetooth connection but i can’t make the blocks that will automatically notify if the Bluetooth are not connected anymore because the Bluetooth that that your connect with is not enabled anymore. PLEASE HELP ME with my problem thank you so much .. 🙂
Dec 10, 2013 @ 12:39:42
Hi Carmina! Sorry for my delay answering, I didn’t see your comment!
You have to use a timer, and every X second check if Bluetooth is connected … and If it is not connected use an alert to warn about it!
Is this info useful or you still have problems?
Thanks for contacting
Dec 22, 2013 @ 16:03:17
This is the best and most complete source file about anroid + bluetooth. Thanks a lot.
Hehe… in any way I am trying to avoid the bluetooh’s PIN be requested. I use a HC-06 and Samsung Galaxy S Duos. The HC is paired but after connection by APP Inventor, the PIN is requested…
Any idea? Can you help me?
Thanks again and… cheers.
Dec 22, 2013 @ 17:46:18
Thanks for your comment! And for visiting my web!
Are you sure that the device is already paired? This case is so strange, normaly it connect automaticly. Is the password right? normaly it is 1234. If you insert it only once, it shouldn’t ask for it anymore. Could it be a safety config of your device?
Cheers!! Happy christmas!!
Jun 21, 2014 @ 14:44:14
I have the same problem.
Samsung Galaxy S Duos.
Any solutions ?
Dec 23, 2013 @ 00:21:59
Yes, I am sure de device is paired before start the programm. I did about ten App Inventor programs (choosing device from list, specifying de address etc) and in all the cases, the PIN (1234) is required.
I have found one in google store which works as I want, but it is not built in AI. In any way, I will keep working and if I find a solution, I will share here.
Jan 02, 2014 @ 16:52:17
dear sir ,
unable to download the code here
Download APP Inventor Bluetooth Connection source by clicking below: —> this has no download
thanks in advance for reply..
Jan 02, 2014 @ 16:55:29
You have to Like it on FB or tweet it to reveal the Download Link. It works :)! Thanks for contacting!
Jan 02, 2014 @ 17:02:49
correction to my previous comment
thanks sir i got the code and downloaded it
will let you know if i will feel some problem with it. i will test it tomorrow
thanks again for your nice effort here..
Jan 04, 2014 @ 13:52:54
i tried your code, but am getting an error 507……..
Jan 19, 2014 @ 20:16:52
Hi, how can i get the .aia file in order to import your project in mit app inventor 2 ?
Jan 19, 2014 @ 20:19:44
Hi, how can i get the .aia in in order to be able to import your code in my mit app inventor2 ?
Jan 19, 2014 @ 23:19:06
You just have to like it or share it and the content will be revealed!
If you are on a Tablet you can click on “Like or tweet this page…” and the download starts.
Thanks for contacting!
Jan 20, 2014 @ 07:24:15
Sorry to bother again, actually my issue is to import the project in my MIT APP Inventor 2 environnment.
I had already download the zip file.
I can uncompress it. I can see two folder “SRC” and “Youngandroidproject”
But i can’t see any .aia file ?
is the good solution to import in the App Inventor 2 :
select “project” “import project” ?
help help (THANKS)
Jan 20, 2014 @ 11:59:59
Sorry to bother again.
I ‘ve downloaded the file. I can extract 2 folder “SRC” and “youngandroid..” folders
I can’t find any .aia files .
In my App Inventor 2, i click on “Project” “import a .aia file” but there is not .aia file in the zip file.
My question is how to import your project in my App inventor2 ?
Thanks for your help
Jan 20, 2014 @ 12:26:22
I have been reading and for now you can only use this source on App Inventor 1. You can got into it –> http://appinventor.mit.edu/explore/classic.html <-- here They say that a convert tool (Ai1 to Ai2) will be released in few months. For now, you can't import this project to AI2. I will develop an AI2 version, but if you are in a hurry, look at the Blocks-Photo and copy this blocks into your project. More info about AI1 to AI2 here https://groups.google.com/forum/#!topic/app-inventor-open-source-dev/0uOe-d6dksw
Feb 27, 2014 @ 07:38:28
Any update on AI2 version? 🙂
Jan 20, 2014 @ 19:16:21
Hello, Thanks now i have your code on my Ai1.
Last question ,since i haven’t receive yet my arduino.
Do you know if it is possible to create a bluetooth android program and test it on my windows computer ?
i mean trying to send data from android and check if that data are receive on my windows computer (maybe with hyperterminal) ?
when i try to connect the android program to my computer, i get the error “Error 507:Unable to connect. Is the device is turn on ?”
Do you know why i get this message ?
Feb 11, 2014 @ 20:48:05
hola, queria saber si con un manos libres bluetooth, podia activar algun proceso en el celular mediante algun comando en app inventor
Mar 05, 2014 @ 03:03:24
I have some questions about the startactivity…
If you didn’t give it an action, it can’t work but, where i can found the istruction to give to him?
The ActivityStarter as_TurnONBT has this code in the Action textbox: android.bluetooth.adapter.action.REQUEST_ENABLE
I want the code to insert into Action textbox for disable bluetooth.
Where i can found them?
Sorry for my english and THANKS!
Mar 13, 2014 @ 18:37:21
Hi Marcello! Sorry for my delay answering! You can find all this actions in “App inventor activitystarter” on Google Play! Use this app, it is fantastic!
Mar 13, 2014 @ 18:20:54
I have a question.
the bluetooth shields function as module bluetooth or I have to use other conexion
Sorry for my english I’am mexican
Mar 13, 2014 @ 18:38:55
Hola Brenda! Hablo español también.
Cualquier módulo bluetooth funciona con esta aplicación. Si el shield tiene integrado bluetooth funcinonara igual :). Próximamente la desarrollaré para APP Inventor 2. Un saludo!
(I will develope an AI2 app inventor bluetooth app soon!)
Mar 20, 2014 @ 21:56:33
Hi Whatakuai, I used your code in a college electronics project (hope you don’t mind!!) and I was wondering if you have instructions as to how it works. Its just I am relatively new to AI and I don’t want to hand it up without some understanding as to how it works, of course I will be acknowledging and referencing your work in the report. Thank you
Mar 23, 2014 @ 13:13:25
i want to get multiple data from arduino using bluetooth connection..how to do that..? thanks
Apr 06, 2014 @ 20:09:58
Hi! It is an amazing blog. very complete.
I did the project, and it worked perfectly, but i get an error in the pair device button, when i press the button, it appear the follow error message: Error 601: no corresponding activity was found. Which could be the reason?
Apr 06, 2014 @ 20:19:42
Thank you very much for your comment!
The error in pair device button could be because of an ActivityStarter with an error inside it fields.
If you open http://beta.appinventor.mit.edu and you upload the project, you can modify the ActivityStarter fields joined with this button. It should work, but probably new androids have different commands or whatever! I have to update this post with an App Inventor 2 (AI2) version, probably I will update it “soon”.
There is an App in Play Store called App inv activitystarter or sth like that, which tells you the ActivityStarter Fields you have to fill in App Inventor depending on the activity you want to do. It’s cool!
Thanks for your comment!
Apr 09, 2014 @ 13:59:25
Hi, as a project for our school we realize a parking sensorik!
Now my question is how to connect a bluetooth modul with an android smartphone?
Apr 11, 2014 @ 14:31:13
Hi! Check connections in http://armdudroid.com/#instructions
(Change servos for your ultrasonic sensors!)
Thanks for contacting
May 01, 2014 @ 20:10:07
Hello, good day!
I’m from Brazil, and I have a doubt. I wonder if the app inventor of the possibility decontrolar signal bluetooth for example it increases or decreases it, or if I can measure it?
Thank you already. embraces.
Jun 17, 2014 @ 21:14:17
I’m not able to download even if I do like it, what am I doing wrong.
Jun 17, 2014 @ 21:15:20
I’m not able to download even if I do like it, what am I doing wrong?
Aug 31, 2014 @ 12:16:57
Try now! Thanks for contacting and sorry for the inconvenience.
Jul 09, 2014 @ 10:04:30
Not able to download second program file.
Jul 09, 2014 @ 13:10:35
For the second program of your block i am getting “error507: Unable to connect. Is the device turned on”. Here my MAC address is 00:06:66:04:A5:44 FireFly-A544. If it is connected then small red led in the bluetooth module will turn into green. I have tested this one with blueterm app available in the playstore. but i need the following things:
In the controller side I have written a code like if i receive “b” then LED ON. If I receive second time “b” then LEDOFF. This is the one i am trying to establish. for this i have put all the example source code given in the you tube and your code. but the error is always same.
Need big help o solve this.
Aug 11, 2014 @ 13:50:27
Thank you for posting your projects for us to follow. I see that you have posted a snapshot of the AI2 user interface. I was wondering however, if you would be willing to post the new AI2 Block code as well?
Aug 31, 2014 @ 12:06:13
Ok, I am going to upload the screenshot!
Kurarin Jan Maikeru
Aug 31, 2014 @ 06:28:23
Hello! you’re tutorial is very helpful in our project. I want to download the updated AIA source for the App Inventor 2 but there is no link.
Aug 31, 2014 @ 12:05:36
Hi kurain! Try this link:
Sep 23, 2014 @ 16:06:46
Great bluetooth walkthrough, very helpful.
However… after connecting, I get the ‘Disconnect’ button showing. When you press it and highlight the device you want to disconnect from… it just returns to the ‘Disconnect’ button page. Nothing actually disconnects
Feb 19, 2015 @ 12:02:34
I used app inventer to create an app to control my arduino board.
but i am getting an error while connecting
ERROR 507: Unable to connect. Is the device turned on ?
please help me to get rid of it.
Mar 13, 2015 @ 19:00:03
Buenas tardes tengo un error al conectar que es el 507, veo que ya muchos te an preguntado y no das respuesta a ese error….
Apr 01, 2015 @ 02:47:08
hola muy buen tutorial .dos preguntas como puedo apagar mi bluethooth q lo active con android.bluetooth.adapter.action.REQUEST_ENABLE y activity started
y la otra pregunta al llamar la activity started me sale una notificacion que si deseo activar o no bluethooth ,,si presiono no como puedo hacer que se me cierre mi aplicacion
Jun 30, 2015 @ 21:31:27
Muy buen tutorial amigo, solo una pregunta me sale el ERROR 507?
Sabeis como solucionarlo.
Jul 12, 2015 @ 21:05:57
Hola Whatakuai, en primer lugar gracias por el aporte, eres un crack. en segundo lugar estoy haciendo una aplicación en la que me es necesario leer datos en android enviados desde una placa arduino, imagínate que tengo varios potenciómetros que me dan varios valores en las entradas analógicas de mi arduino uno, y quiero que se me plasmen en varias label de una pantalla de mi tlf android. No como una lista, sino como un valor que cambia. Lo he intentado de varias formas y no hay manera. Me podrias echar una mano? El resto del proyecto lo tengo claro. pero estoy anclado en esto.
Jul 19, 2015 @ 12:21:10
Me ha sido muy útil esta aplicación, solo una pequeña pega, la base de datos guardaba el MAC seleccionado en el Tag “ChooseMac” y luego lo intenta abrir con el Tag “ChoseMac” y no puede.
Esto ocurre en la app inventor 2.
Saludos y gracias
Jul 19, 2015 @ 12:23:03
quise escribir “chosenmac” y “choosenmac”
saludos de nuevo
Bluetooth Controlled LEDs on a Skateboard :: Student Project - Programming Electronics Academy
Sep 16, 2016 @ 19:48:34
[…] This is the phone interface he used to control the LEDs with the bluetooth module. The application end of the Bluetooth was developed by Whatakuai. You can check it out here: http://www.whatakuai.com/de/bluetooth-and-app-inventor/ […]