Arduino Forum

Community => Exhibition / Gallery => Topic started by: kerimil on Feb 14, 2013, 03:36 am

Title: Using android mobile to control arduino
Post by: kerimil on Feb 14, 2013, 03:36 am
Here is my android controlled arduino project. A simple app sends data through SPP over bluetooth and switches an LED on and off.

The circuit is just a bluetooth module, arduino UNO, LED, resistor and some wires.

The LED can be switched on using buttons as well as voice activation (anything that contains the word 'on','off' or 'blink' - so saying 'turn the LED on' works as well as just uttering 'on').
I created the app using MIT app inventor and this project was created pretty much only to show how easy it is to write custom apps using the tool and interface with microcotrollers in this manner. One could use MIT app inventor to add more more features, such as using accelerometer or GPS data to control the LED, switching the state using text messages, web communication, not only send but also receive data, etc.
...well the point is - MIT app inventor is pretty cool and you should check it out


VIDEO OF IT -> http://youtu.be/41MRGjdVIMQ


(http://i50.tinypic.com/292rznc.jpg)
(http://i47.tinypic.com/4g2blu.jpg)
(http://i46.tinypic.com/344sd90.jpg)
(http://i49.tinypic.com/1z4vj0n.jpg)

Here is the app for download -> http://speedy.sh/63Q9N/bluetoothforarduino-app-2.apk

and here is the source, you can upload it to  MIT's app inventor and modify as much as you want to -> http://speedy.sh/mDyAk/bluetoothforarduino-app-1.zip

Here is the arduino code
Code: [Select]


const int ledPin = 7;      // the pin that the LED is attached to
 byte serialA;
void setup()
{
 // initialize the serial communication:
 Serial.begin(19200);
 // initialize the ledPin as an output:
 pinMode(ledPin, OUTPUT);
}

void loop() {


 
     
     switch (serialA) {
   case 1:
     digitalWrite(ledPin, HIGH);
     break;
   case 2:
     digitalWrite(ledPin, LOW);
     break;
   case 3:digitalWrite(ledPin, HIGH);
     delay(100);
     digitalWrite(ledPin, LOW);
     delay(100);
   
     
 }
}
void serialEvent(){
serialA = Serial.read();
}


Title: Re: Using android mobile to control arduino
Post by: Nogueira on Feb 15, 2013, 07:16 pm
Could you share the AppInventor project?
Title: Re: Using android mobile to control arduino
Post by: kerimil on Feb 15, 2013, 08:04 pm
Here is the source file -> http://speedy.sh/mDyAk/bluetoothforarduino-app-1.zip


As I mentioned on hackaday it won't be the exact copy as I improved it to react not only to 'BLINK' command but also 'FLASH' and 'CYCLE'... done that just because google voice search usually returns 'pink' or even 'd#ck' instead of BLINK :-D
but apart from that it's the same

If you have any problems with downloading the files just let me know

Title: Re: Using android mobile to control arduino
Post by: scheelga on Feb 16, 2013, 05:11 pm
This might be a noob question but what bluetooth module did you use?
Title: Re: Using android mobile to control arduino
Post by: sjenkins2 on Feb 16, 2013, 08:02 pm
I just gave this a try myself and it worked great. Now I am trying to receive data (an integer value) from the arduino instead of sending to it, but cant seem to figure out how...
Title: Re: Using android mobile to control arduino
Post by: kerimil on Feb 17, 2013, 04:58 pm
Well it is a bit trickier.

Use a call bluetoothclient.receivetext and set th number of bytes to -1, which reads until delimiter byte is received.
Mmake sure you set the delimiter byte - I used '13' which is carriage return... ohh you might find this useful -> http://www.asciitable.com/index/asciifull.gif

What's more, it's seems there is no serial timout implemented yet and the app freezes if it doesn't receive anything. To solve that I set up the app to first send a 1 byte number to the arduino, when arduino receives that it sends its data.

Here is an app I created to receive data from a 1 wire temperature sensor (ds18b20). I think if you upload it into the MIT app inventor you should be able to work this out and modify it.
http://speedy.sh/qscGe/bluetoothforarduino-app-temperaturereadings-1.zip

and arduino code (temperature sensor is connected to digital pin 2)
Code: [Select]
#include <OneWire.h>
int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 2

//Temperature chip i/o
OneWire ds(DS18S20_Pin); // on digital pin 2


 byte serialA;
void setup()
{
 // initialize the serial communication:
 Serial.begin(19200);
 // initialize the ledPin as an output:
 pinMode(ledPin, OUTPUT);
}

void loop() {

 





 

   
   if (serialA == 49){float temperature = getTemp();
Serial.println(temperature); serialA = 0;

}


}
 
 
float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius

byte data[12];
byte addr[8];

if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -100;
}

if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return -1000;
}

if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Device is not recognized");
return -1000;
}

ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end

byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad


for (int i = 0; i < 9; i++) {
data[i] = ds.read();
}

ds.reset_search();

byte MSB = data[1];
byte LSB = data[0];

float tempRead = ((MSB << 8) | LSB);
float TemperatureSum = tempRead / 16;

return TemperatureSum;}


void serialEvent(){
serialA = Serial.read();
}





The code is a bit messy I admit but it does work
Title: Re: Using android mobile to control arduino
Post by: cyclegadget on Feb 18, 2013, 04:07 am
@kerimil

Thanks for sharing your code and work! I have now started trying to learn app inventor because of your post! I too wish to send and receive bluetooth data so, I am very interested in that!
Title: Re: Using android mobile to control arduino
Post by: cyclegadget on Feb 18, 2013, 05:01 am


What's more, it's seems there is no serial timout implemented yet and the app freezes if it doesn't receive anything. To solve that I set up the app to first send a 1 byte number to the arduino, when arduino receives that it sends its data.



I wonder if you have to test for bytes available? In the Arduino it would be a test like  if(Serial.available()){ Serial.read } .

In the code blocks you have a something that says BluetoothClient1BytesAvailableToReceive.............I think it should be combined with a if > 0 { read the byte }....or something like that.

P.S. I am tring to adapt your code to my purpose and I am learning while making the attempt.  :)
Title: Re: Using android mobile to control arduino
Post by: kerimil on Feb 18, 2013, 11:41 am



I wonder if you have to test for bytes available? In the Arduino it would be a test like  if(Serial.available()){ Serial.read } .

In the code blocks you have a something that says BluetoothClient1BytesAvailableToReceive.............I think it should be combined with a if > 0 { read the byte }....or something like that.



Well yeah, but you can't have (Serial.available()){ Serial.read } all by itself - meaning the control structure block has to be attached to something else - ideally it should happen with no user input. The only thing I can think of is to have it inside Clock.timer block and set it to fire every 10 ms or so. That's not ideal but it might work.

I had had some problems when I tried to implement it. Though the idea might be ok. I might have messed up something else - it is possible I sent data more often than the app received them and that freezed the app because of the buffer. Well at least that's my understanding of it
Title: Re: Using android mobile to control arduino
Post by: baligena on Feb 18, 2013, 07:13 pm
Where did you get the bluetooth module?
Title: Re: Using android mobile to control arduino
Post by: kerimil on Feb 18, 2013, 07:48 pm
it's a BTM222 module on a custom breakout board - kind of cool because it is a class 1 device - so the max range is not 10m but 100m  :D
I bought it from a local tinkerer who makes them - so I don't think you'd be able to get it

Though there are lots of such boards all over ebay - though most of them are class 2 (range ~10meter)



Title: Re: Using android mobile to control arduino
Post by: sjenkins2 on Feb 26, 2013, 12:43 am

I had had some problems when I tried to implement it. Though the idea might be ok. I might have messed up something else - it is possible I sent data more often than the app received them and that freezed the app because of the buffer. Well at least that's my understanding of it


I kept getting the same thing, its quite frustrating as my phone takes forever to recover! In my arduino code I just had Serial.println(...) in the loop and had my app to receive text every 1 second (with delimiter byte set to 13). I either get some odd values or it just crashes.
Title: Re: Using android mobile to control arduino
Post by: kerimil on Feb 26, 2013, 02:27 pm
it works but only if serial data is received as often as it's sent... so your arduino code should send the data every 1 second
Title: Re: Using android mobile to control arduino
Post by: levelapp on Feb 28, 2013, 10:59 pm
First of all THANKS,
this was the project that I was waiting for.
I do not understand very much the wiring connection, especially the bt connection, my lack.
green wire: pin0 (arduino) - ? (bt)
yellow wire: pin 7 (arduino) - led
black wire: ? (arduino) - resistor - ? (bt)
red wire: ? (arduino) - ? (bt)

and like in a loop I finish with
End of all THANKS
Title: Re: Using android mobile to control arduino
Post by: kerimil on Feb 28, 2013, 11:49 pm
Oh sorry I forgot to post wiring diagrams here. Now it should be a lot easier to understand.

(http://www.instructables.com/files/deriv/FI6/B1WK/HD7TZGDS/FI6B1WKHD7TZGDS.LARGE.jpg)
(http://www.instructables.com/files/deriv/FRR/8340/HD4VFIGK/FRR8340HD4VFIGK.LARGE.jpg)

If you can't see the pics just go here -> http://www.instructables.com/id/How-control-arduino-board-using-an-android-phone-a/

Title: New functionality
Post by: kerimil on Mar 10, 2013, 08:13 pm
I found out how to send data from the app to cosm website

here is a video showing an example app as well as a brief explanation of how to use app inventor

http://www.youtube.com/watch?v=Y-iDuUQCxQA

You can download the app here >>
<a href="http://speedy.sh/d4444/bluetoothAppCosmExampleTemperature1.apk">Download at SpeedyShare</a>

Here you can download the source >>
http://speedy.sh/Vwwww/bluetoothAppCosmExampleTemperature.zip


Here is arduino code I used (note that you need OneWire library for it to work)
Code: [Select]

#include <OneWire.h>
int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 2

//Temperature chip i/o
OneWire ds(DS18S20_Pin); // on digital pin 2



void setup()
{
 // initialize the serial communication:
 Serial.begin(19200);
 // initialize the ledPin as an output:

}

void loop() {


  float temperature = getTemp();
Serial.println(temperature); delay (250);

}


float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius

byte data[12];
byte addr[8];

if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -100;
}

if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return -1000;
}

if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Device is not recognized");
return -1000;
}

ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end

byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad


for (int i = 0; i < 9; i++) {
data[i] = ds.read();
}

ds.reset_search();

byte MSB = data[1];
byte LSB = data[0];

float tempRead = ((MSB << 8) | LSB);
float TemperatureSum = tempRead / 16;

return TemperatureSum;}
 
 



And here is the feed I created for the app -> The feed is available here - https://cosm.com/feeds/118188


In order to send data from or to your own COSM feed you have to modify the URL as follows (parts that you have to fill in are in capital letters):

http://api.cosm.com/v2/feeds/YOUR FEED ID/datastreams/YOUR DATASTREAM ID.csv?key=YOUR API KEY&_method=put

Then copy and paste the URL into a QR code generator, generate a QR code and scan it using the app. You might as well use the feed I created for the app - it's the default URL set in the app so you don't have to enter it - it's already there



If you have any questions feel free to ask them


Title: Re: Using android mobile to control arduino
Post by: maad on Mar 12, 2013, 07:42 am
When is necessary to use a level-shifter? some people use the 74HC4050N level shifter in conjunction with the btm222 module!
Title: Re: Using android mobile to control arduino
Post by: kerimil on Mar 20, 2013, 04:29 pm
The module I got has a proper level shifter on it, but AFAIK one could improvise with zener diodes to achieve the same effect (not that level shifters are very expensive)
Title: Re: Using android mobile to control arduino
Post by: sisyph on Mar 24, 2013, 09:38 pm
Tanks a lot Kerimil for your project vert helpfull.
I tried to do the same without Voice recognising. The connection From my phone and Bluetooth device    is ok, the wiring sure ok ( rx to dx and dx to rx). But nô serial data is send. On your sketch, you initialise serial communication with 19200 bauds. I think the Bluetooth deviçe should send is data at same speed. Where did you initialise serial data speed on Bluetooth device? Perhaps the problème comes From there.
Tanks for your answer
Title: Re: Using android mobile to control arduino
Post by: cyclegadget on Mar 25, 2013, 12:30 am
Quote
Where did you initialise serial data speed on Bluetooth device?


Between the Bluetooth device and the phone, the serial data speed is solved during "pairing" of the device to the phone. At least this is my belief.
Title: Re: Using android mobile to control arduino
Post by: kerimil on Mar 25, 2013, 02:33 pm
Quote
Where did you initialise serial data speed on Bluetooth device?
Cyclegadget is right - it's either when pairing or whenever connection is established

Even if baud rate was wrong you'd still receive something - if you don't then it has to be something else.


Verify if the module and the mobile works using a USB bluetooth dongle and a program like putty. Also check the datasheet of the module and the settings - is the module set as slave or master ? For apps I created it has to be set as master
Title: Re: Using android mobile to control arduino
Post by: sisyph on Mar 26, 2013, 10:22 pm
Thanks for sharing your  work. I tried it without voice detection. BT is paired with my phone but apperently no serial data is send. If I try to send "1" or "2" with my computer connected in bt, using putty the led switch on and off correctly so the hardware and arduino sketch is ok. my problem is coming from app inventor. what is button 1 set and number for? is the real value 1 and 2 are send or ascii value. I tried with mega 2560 with  external power and connect rx  and tx to serial 0
Title: Re: Using android mobile to control arduino
Post by: cyclegadget on Mar 26, 2013, 10:55 pm

@sisyph

I recommend you share your code that you are using, just to eliminate the possibility of the code being the problem.
Title: Re: Using android mobile to control arduino
Post by: kerimil on Mar 27, 2013, 07:01 am
ohh I see now... the problem you are experiencing is caused by data types

The app sends bytes so it converts '1' into '49' and that's what's sent through bluetooth.


Ohh and you really should have connected the app to the bluetooth dongle - that would make everything clear for you.
Title: Re: Using android mobile to control arduino
Post by: sisyph on Mar 27, 2013, 10:35 am
Yeah !! it works.
I used in my sketch : case '1' : instead of case 1:
So many hours for ''...
The strange things is that it worked before when I used my bt connection with my computer...
Thanks for your help
Title: Re: Using android mobile to control arduino
Post by: 4ntoine on Mar 29, 2013, 05:33 am
Just found this app. Those who are interested can check out ArduinoCommander android app too:
https://play.google.com/store/apps/details?id=name.antonsmirnov.android.arduinocommander (https://play.google.com/store/apps/details?id=name.antonsmirnov.android.arduinocommander)
Title: Re: Using android mobile to control arduino
Post by: ahmjazly on Apr 01, 2013, 09:28 pm
hi kerimill,

i wanna buy a bluetooth for this project.so just went through ebay and found this link

http://www.ebay.com/itm/JY-MCU-HC-06-V1-03-Bluetooth-Transeiver-RF-Module-Wireless-Serial-4p-Port-line-/261053366958?pt=LH_DefaultDomain_0&hash=item3cc7fe42aehttp://www.ebay.com/itm/JY-MCU-HC-06-V1-03-Bluetooth-Transeiver-RF-Module-Wireless-Serial-4p-Port-line-/261053366958?pt=LH_DefaultDomain_0&hash=item3cc7fe42ae

this bluetooth module has a pairing code 1234. so to pair this module with ur app, should i modify ur project?? will it automatically ask for code??
plz tel me that can i use this module??

thnx
Jazly :)
Title: Re: Using android mobile to control arduino
Post by: kerimil on Apr 02, 2013, 08:57 pm
The app doesn't have to pair with the module - just pair with it from the phone and then run the app

It should work just fine - just make sure you check the datasheet of the module & make sure the baud rate is the same (if so then the arduino code has to be modified or the setting of the module)
Title: Re: Using android mobile to control arduino
Post by: moeabok on Apr 11, 2013, 03:46 pm
hi , i am interested in such project .. i purchased arduino uno , bluetooth bee , and x bee sheild ..
i am having a problem in bluetoothfor arduino app.. i couldnt figure out on wat program it will run ...
thnk u for ur cooperation ..
Title: Re: Using android mobile to control arduino
Post by: kerimil on Apr 11, 2013, 07:51 pm
I don't really understand the question... could you be more specific ? I know English is probably not your native language but I can't really tell what's the problem
Title: Re: Using android mobile to control arduino
Post by: moeabok on Apr 11, 2013, 09:03 pm
I have a senior project , our instructor couldnt help me , because he siad that arduino and android isnt his domain, and said that it a new tech ,go ask some experts,, so i made plenty of searches but rarely i got info :(
in my project i need to control ( turn on and off lights using arduino,  android mobile phone , via bluetooth )
i bought an arduino uno , arduino shield (for Bbee ) , bluetoothbee, and relay...
i saw ur codes , but i need u to tell me where to use them  .. plz help me if u can..
ive downloaded books but sooo many codes....
MY problem is that in our country we have no experts in arduino, neither android programs..
i tryed to download from speedy share as u suggested , but it was denied , they asked for premium......
can u help , and be an advisor for this project which i couldnt have  , plzzz
Title: Re: Using android mobile to control arduino
Post by: kerimil on Apr 12, 2013, 06:09 am
You have to copy and paste arduino code into arduino IDE and then upload it to the board

You're right about speedyshare - you can no longer download the files for free
I'll try to upload them somewhere else
Title: Re: Using android mobile to control arduino
Post by: kerimil on Apr 12, 2013, 03:05 pm
Here is a link to the files ->
https://docs.google.com/file/d/0B_PfPoEotOF8WEwyUVhkWnY3b00/edit?usp=drive_web&pli=1

or try this if it doesn't work
https://drive.google.com/folderview?id=0B_PfPoEotOF8N2JwT3RSX011SjQ&usp=sharing

Title: Re: Using android mobile to control arduino
Post by: moeabok on Apr 12, 2013, 05:14 pm
thank u ive downloaded the files , but i couldnt copy them to arduino ide,, it didnt open ,, do u have a way to open those files ,, ar any program to open them ???
Title: Re: Using android mobile to control arduino
Post by: moeabok on Apr 12, 2013, 05:26 pm
i have a bluetooth bee iteadstudio ,, but ive seen some codes from seeedstudio for my bluetooth, is it the same ???
i tryed but it didnt work !
http://tronixstuff.wordpress.com/2012/04/30/arduino-android-and-seeedstudio-bluetooth-bee
how can i try it ??
Title: Re: Using android mobile to control arduino
Post by: moeabok on Apr 12, 2013, 06:22 pm
the code for arduino uve prviosly wrote in the first page about pin 7 coudnt be uploaded to arduino ,, problem is because of COM .. but only 3 COMs  4, 5, 7  also didnt work , access is denied ..
whats the problem?? i am using arduino 1.5.2
Title: Re: Using android mobile to control arduino
Post by: kerimil on Apr 13, 2013, 08:11 am
First of all you can't have the bluetooth module connected to RX and TX when you upload code - upload code and then connect them.

Secondly, the module you have might be set to different default baud rate - you either have to change it (using AT commands) or modify arduino code to use the module default baud rate.

What's more, make sure that the module is set as master. The datasheet should have some information on that.


Finally, use a USB bluetooth dongle and program such as Putty to try to establish connection with the module and android device. In this way you can manually send and receive commands and see if the module and/or android device works as expected.
Title: Re: Using android mobile to control arduino
Post by: moeabok on Apr 15, 2013, 12:48 pm
i uploaded the code it worked ..
as for comunication with bluetooth it didnt happen , i tryed to comunicate with bluetooth by serial monitor .. it didnt work , as for Putty i tryed it it also didnt comunicate , i tryed AT and +++ ,, waiting for an OK .. also nothing happen ..
what baud rate , and com do ITEADSTUDIO bluetooth bee work ????..
kerimil am realy thankful for ur concern :)
Title: Re: Using android mobile to control arduino
Post by: kerimil on Apr 15, 2013, 06:26 pm
Did you try to establish connection between the phone (app) and a computer to see if it works ?? it should work just fine.
Quote


i tryed to comunicate with bluetooth by serial monitor .. it didnt work , as for Putty i tryed it it also didnt comunicate
even if the baud rate is wrong you still get something on the other side - just a bunch of characters that make no sense

There must be some other problem - I assume it's either wiring or slave/master setting


Quote
i tryed AT and +++ ,, waiting for an OK .. also nothing happen
All bluetooth modules that I've seen require you to send AT commands through FTDI adapter not directly through bluetooth SPP.




Not sure if that's the module you have but I found this ->
ftp://imall.iteadstudio.com/IM120417010_BT_Shield_v2.2/DS_BluetoothHC05.pdf

Also I found this thread that you might find useful -> http://arduino.cc/forum/index.php?topic=100008.0;wap2
Title: Re: Using android mobile to control arduino
Post by: moeabok on Apr 19, 2013, 02:27 pm
thnk u , i only need ur source code for the application on android phone plzz .. i gues i figured out the problem ,, in the xbee shield its not suppoting a connection betwwen bluetooth rx , and arduinos tx...
so now its responding .. so plz give me ur app source code
Title: Re: Using android mobile to control arduino
Post by: kerimil on Apr 19, 2013, 03:13 pm
The source file can be downloaded here -> https://drive.google.com/folderview?id=0B_PfPoEotOF8N2JwT3RSX011SjQ&usp=sharing

Note that source files have .ZIP extension. That's why you didn't notice it. I describe how to upload them in this video
https://www.youtube.com/watch?feature=player_detailpage&v=Y-iDuUQCxQA#t=126s


Title: Re: Using android mobile to control arduino
Post by: moeabok on Apr 19, 2013, 04:41 pm
those codes can be opened by what program... ??? i couldnt open them ..
Title: Re: Using android mobile to control arduino
Post by: kerimil on Apr 19, 2013, 09:49 pm
it has to be uploaded (the entire zipped file) into app inventor

more on it here -> http://appinventor.mit.edu/
Title: Re: Using android mobile to control arduino
Post by: maad on Apr 20, 2013, 04:17 am
Can you please republish your mit app inventor application? the file no longer exists, I'm having troubles trying to emulate your application.
Title: Re: Using android mobile to control arduino
Post by: kerimil on Apr 20, 2013, 12:34 pm
Try this link -> https://drive.google.com/folderview?id=0B_PfPoEotOF8N2JwT3RSX011SjQ&usp=sharing
Title: Re: Using android mobile to control arduino
Post by: moeabok on May 02, 2013, 11:55 am
hi, kerimil ,, m sorry i was busy with my exams , i really thank u for ur support ,,please am also interessted with temp aplication , can u send me the code for the application , as you know i cant download from speedy ...
thnk u again dr kerimil..
Title: Re: Using android mobile to control arduino
Post by: moeabok on May 02, 2013, 12:10 pm
another thing , i am trying to make my arduino read the device if its on or off , and to read it and then send the data to my phone throughout bluetooth .if its on the text tv is grean , if its off the text " tv" is red , so a user for example will not turn off a device witch is already off . do u think its a good idea ??
Title: Re: Using android mobile to control arduino
Post by: kerimil on May 02, 2013, 09:46 pm
Quote
please am also interessted with temp aplication , can u send me the code for the application , as you know i cant download from speedy
The source file can be downloaded from my google drive - the link is in my previous post

it's a zipped file - you have to upload it into app inventor


Quote
another thing , i am trying to make my arduino read the device if its on or off , and to read it and then send the data to my phone throughout bluetooth .if its on the text tv is grean , if its off the text " tv" is red , so a user for example will not turn off a device witch is already off . do u think its a good idea ??
That's doable - just write arduino sketch that reports the state of the TV through bluetooth
Title: Re: Using android mobile to control arduino
Post by: Dennis0222 on May 06, 2013, 03:10 am
Hello, I was wondering would you be able to help me with problems I am having with my Android to ardiuno setup.
Basically what I am trying to do is making my phone read the voltage signal from the A0 port. I am using an ardiuno UNO. When I press button 8 on my phone, I can see the ardiuno print the voltage in the serial monitor. I was wondering would you know how to send the voltage back to the phone, and have it print out the voltage there.

Code: [Select]


byte serialA;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
serialA = Serial.read();
  if (serialA == 1)
  {
    int sensorValue = analogRead(A0);
    Serial.println(sensorValue);
    Serial.write(sensorValue);
    serialA = 0;


  }
}


Title: Re: Using android mobile to control arduino
Post by: kerimil on May 06, 2013, 02:52 pm
Did you use a bluetooth dongle and putty to check what is sent by both the phone and the arduino ??

Do so and you should see what's wrong  :)
Title: Re: Using android mobile to control arduino
Post by: moeabok on May 09, 2013, 10:42 am
in application , i have label tv , then 2 buttons turn off and turn on ..
if i want to change the color of label TV due to its state , how can i do it ..
for example : if its already turned on so label TV is green , else its color is red ..
                 
Title: Re: Using android mobile to control arduino
Post by: ttttkk on May 30, 2013, 10:14 am
Hi, I'm having fun with your example. But one problem though, how come the android doesn't recognize my "OFF" oral command?
Title: Re: Using android mobile to control arduino
Post by: kerimil on May 30, 2013, 11:42 am
So everything works but it does not recognize just the command ??

well if that's the case then apparently google voice engine returns something different than 'off' - modify the app to react to a different command.
Title: Re: Using android mobile to control arduino
Post by: ttttkk on May 30, 2013, 03:17 pm
it turns out that the android itself doesn't recognize many of my command such as "flash","apple","off","power","one","two". But it recognize my "banana", so now the OFF command is banana.
Title: Re: Using android mobile to control arduino
Post by: kerimil on May 30, 2013, 08:43 pm
Heh yeah but you see the app works fine it's google voice recognition engine fault. I can't blame them really - lots of words sound very similar, there is ambient noise, lack of context and various accents.

I found that the best method is to use longer words or two word phrases. Apparently that makes it easier for the engine to recognize the command properly
Title: Re: Using android mobile to control arduino
Post by: ttttkk on May 31, 2013, 06:17 pm
so does the app inventor support phase command ?
Title: Re: Using android mobile to control arduino
Post by: kerimil on Jun 01, 2013, 01:25 am
what is phase command ?? if you asking whether or not it can receive more than one word then the answer is yes
Title: Re: Using android mobile to control arduino
Post by: calou1 on Jul 01, 2013, 11:47 am
Hello
i try to control the led  but nothing is ok
my sketch is:

const int ledPin = 2;      // the pin that the LED is attached to
 byte serialA;
void setup()
{
 // initialize the serial communication:
 Serial.begin(19200); //baud rate - make sure it matches that of the module you got:
 // initialize the ledPin as an output:
 pinMode(ledPin, OUTPUT);
}

void loop() {

if (Serial.available() > 0) {serialA = Serial.read();Serial.println(serialA);}

 
     switch (serialA) {
   case 49:
     digitalWrite(ledPin, HIGH);
     break;
   case 50:
     digitalWrite(ledPin, LOW);
     break;
   case 51:digitalWrite(ledPin, HIGH);
     delay(100);
     digitalWrite(ledPin, LOW);
     delay(100);
    default:

     break;
 }

}


I can control the led with my PC and the bluetooth v3
on/off/blink

my android ins connect to bluetooth (apaire ok!)

but nothing when i swith on
i dont know what  can i do?

thank you

With App programme i send 1, 2, 3

and my baud rate is 19200.

Title: Re: Using android mobile to control arduino
Post by: kerimil on Jul 01, 2013, 06:39 pm
you're rayrayan1 from instructables?? if so see my response there
Title: Re: Using android mobile to control arduino
Post by: handyaner on Jul 03, 2013, 07:54 pm
hello

i can choose the decive, but no connection will be establishe.
must i chance the baudrate to 9600?
if yes, where must i chance it n the app inventor?
Title: Re: Using android mobile to control arduino
Post by: kerimil on Jul 04, 2013, 01:55 am
there is no need to change baud rate in the app as it automaticly uses the baud rate used by the bluetooth module

the module I got is set to 19200 by default and I was too lazy to change it... so check what's the default baud rate of your module and change arduino code accordingly
Title: Re: Using android mobile to control arduino
Post by: pictux on Jul 18, 2013, 07:12 pm
Hi,
you can use also the cheap HC-05 / HC-06 / HC-07 bt module (about 5 usd on ebay  :smiley-mr-green:).

More info about this kind of module:
http://forum.arduino.cc/index.php?topic=104903.msg786726#msg786726
(ok, it's in italian language :) but there are a lot of pictures and code and i promise: i'll translate it in english  :smiley-roll-sweat:).
Title: Re: Using android mobile to control arduino
Post by: kerimil on Aug 06, 2013, 05:20 am
UPDATE - I made a new app and a new video to show that you can use the phone as a GSM shield
enjoy

https://www.youtube.com/watch?v=_L_JyCndeKI (https://www.youtube.com/watch?v=_L_JyCndeKI)

more details here -> http://www.instructables.com/id/Android-phone-used-as-a-GSM-shield-for-arduino/
Title: Re: Using android mobile to control arduino
Post by: cyclegadget on Aug 07, 2013, 03:15 am

Nice upgrade to your previous work! I tried to get you file as a zip but, could not figure out how. I have the pieces and will try to make them work later.


Thanks for sharing your discovery!
Title: Re: Using android mobile to control arduino
Post by: kerimil on Aug 07, 2013, 05:01 am
ohh sorry
For some unknown reason the link I provided on instructables to the source file showed contents of the ZIP archive itself. I've just fixed it

try this link -> https://drive.google.com/folderview?id=0B_PfPoEotOF8N2JwT3RSX011SjQ&usp=sharing
Title: Re: Using android mobile to control arduino
Post by: cyclegadget on Aug 07, 2013, 12:24 pm

That link worked, thank you!
Title: Re: Using android mobile to control arduino
Post by: Jimdare on Aug 09, 2013, 02:25 am
Hi Kerimil,

I'm trying to expand on your app that sends temperature data to android via bluetooth, by adding two more sensor values.  On the arduino side I send the values as so:

Code: [Select]

Serial.print(SoilTemp);
Serial.print(",");
Serial.print(AirTemp);
Serial.print(",");
Serial.print(Humidity);
Serial.print(",");
Serial.println();



Assume:

SoilTemp = 15.00
AirTemp = 22.00
Humidity = 63.00


I intend this to send the following via the serial output:

15.00,22.00,63.00,

I then receive this with the blocks below:
 
(https://lh5.googleusercontent.com/-ZIpYBxhCawg/UgIRecQ576I/AAAAAAAAAGo/mMTWyHgrTrI/s1600/BlocksMITApp.png)

The problem is; when I run my app, it comes up with the error telling me that the list index object (2) is too big for the list.  I understand that this means the list hasn't been split properly.  Do you have any tips as to how to get this working?

Thanks very much for your time.

Kind Regards,
Jimdare
Title: Re: Using android mobile to control arduino
Post by: kerimil on Aug 09, 2013, 06:15 am
jimdare
It took me a while to figure it out...
You get this error because of select list item block. It crashes when there isn't item #2. Apparently something gets through serial but it isn't what you expect it to be and list index #2 doesn't exist.

How I fixed it ? Just put all your select list index number X inside an if block - and set condition to (list length = number of items you should get in the list)
Title: Re: Using android mobile to control arduino
Post by: Jimdare on Aug 12, 2013, 03:58 am
Thanks Kerimil, but this doesn't seem to fix it.  I have investigated further, and it seems like the list only ever consists of one item.  I wonder why mitAI is not splitting the string properly?  Perhaps I will try using a different delimeter. 
Title: Re: Using android mobile to control arduino
Post by: kerimil on Aug 12, 2013, 06:00 am
hmm... I am just guessing here but have you tried setting the condition Bluetooth client bytes available to receive to number of bytes you expect to get through serial (probably including delimeter byte)??
Title: Re: Using android mobile to control arduino
Post by: MechArd on Aug 12, 2013, 05:25 pm
Hi, I have followed your tutorial. I have connected  android phone to my Bluetooth device (HC-06) and the TX light flashes on the Arduino when i press the led on button on my app. Although the led does not flash. Is there any way to check what byte the arduino is receiving?
Title: Re: Using android mobile to control arduino
Post by: kerimil on Aug 13, 2013, 08:09 pm
You're 100% sure that TX light is flashing ?? since you're sending stuff to the arduino board shouldn't the RX LED flash ?? I am away from my board ATM so I can't check whether RX or TX flashes when it receives but I think it should be RX not TX

Is the bluetooth module TX pin connected to RX pin on the arduino board ?? it should be. If it isn't correct that


If you want to check exactly what is being sent from the module to the board then use software serial to create another UART port on other pins and create a sketch that retrieves whatever is sent through that serial and passes it to hardware serial (and thought USB connection to the computer where it can be seen using a serial monitor)
The reason why you need to use software serial is because you can't have anything connected to hardware uart pins and use serial through USB connection.
Title: Re: Using android mobile to control arduino
Post by: Jimdare on Aug 14, 2013, 11:45 am
Success!! I finally made the bloody thing work! Turns out it didn't like the first byte of the string I was sending, so I added an 'X' in front.  This made the string look like this:

X15.00,22.00,63.00,

The split by ',' block worked fine after this.  I still have issues with the length of the list, but I will just add an 'if list = 3' condition. 

Thanks kerimil.

Code: [Select]


Serial.print("X");
Serial.print(temperature);
Serial.print(",");
Serial.print(temp);
Serial.print(",");
Serial.print(humi);
Serial.print(",");
Serial.println();
delay (2000);
Title: Re: Using android mobile to control arduino
Post by: kerimil on Aug 14, 2013, 06:23 pm
Glad I could help even if I didn't  :smiley-slim:

Anyway here is my newest project that also interfaces arduino and android devices - nothing fancy really it just a wireless ignitor

http://www.youtube.com/watch?v=jFRN8juM_yU

more details here -> http://www.instructables.com/id/Wireless-cell-phone-igniter/
Title: Re: Using android mobile to control arduino
Post by: MechArd on Aug 16, 2013, 12:04 am
I change the RX and TX connections and nothing flashes now. I have attached the Arduino code and the android app code.

Title: Re: Using android mobile to control arduino
Post by: kerimil on Aug 16, 2013, 01:34 am
as I said tens of times in this thread: get a bluetooth dongle and use a terminal program (such as putty) to check if:
A) the app is sending
B) the BT module reacts to manualy entered commands (through serial)

But even before that check if TX pin on the BT module is connected with RX pin on arduino
Title: Re: Using android mobile to control arduino
Post by: RuiSantos on Aug 31, 2013, 05:41 pm
Hi kerimil.
First I would like to say thanks so much for sharing your work!
I would love if you could help me...
I'm working on a project similar to a previous project I've made a few months ago (you can visit my website to check my project http://randomnerdtutorials.com/arduino-control-dc-motor-via-bluetooth/ (http://randomnerdtutorials.com/arduino-control-dc-motor-via-bluetooth/))

In my previous project I was controlling one DC motor... But now instead of controlling one DC motor I want to control 2 DC motors... my code is working perfectly when I'm using the BlueTerm app for android. (BlueTerm app is similar to putty it sends information to my arduino via bluetooth....) And my circuit is pretty much the same as the one i've showed on my website... I just added another motor... My circuit is working perfectly because it works with the serial monitor (when i send 1,2,3,4,5... and when I send via blueterm app those numbers)

And I want to create an App to send that same information to my arduino but with MIT App Inventor...
here is my arduino code: http://randomnerdtutorials.com/wp-content/uploads/2013/08/sketch_aug29a.zip (http://randomnerdtutorials.com/wp-content/uploads/2013/08/sketch_aug29a.zip)
here is my Mit App Inventor code: http://randomnerdtutorials.com/wp-content/uploads/2013/08/blue.zip (http://randomnerdtutorials.com/wp-content/uploads/2013/08/blue.zip)

I've tried to replicate your code to my project but It's not working. (I'm using HC-05 Bluetooth Module)
I can't find out my problem and I've searched a lot...

My app connects fine to my bluetooth module but when I click forward, left ... nothing happens.
So It's a problem with my app... somethings is missing...

Could you please take a look at my code and project?
And try to help me out I would be really thankful! I want to share this project with my friends on randomnerdtutorials and of course I will give you credit for helping me out!!

Thanks again and best regards,
Rui Santos

P.S. I would like that my app looks similar to this: http://randomnerdtutorials.com/wp-content/uploads/2013/08/d.png (http://randomnerdtutorials.com/wp-content/uploads/2013/08/d.png)
Title: Re: Using android mobile to control arduino
Post by: kerimil on Aug 31, 2013, 07:44 pm
I see you haven't set delimiter byte

It's under components - select BluetoothClient1 and there you can enter delimiter byte. Set it to 13 and see if it helps.
Title: Re: Using android mobile to control arduino
Post by: RuiSantos on Sep 02, 2013, 09:54 pm
I've just tried that ... It's still not working :s
Its working fine with blueterm app... but when I try with the app inventor app it connects fine to my bluetooth module but when i press the buttons nothing happens...

do you have a better idea for me to debugg this code?

thanks so much for answering!
Title: Re: Using android mobile to control arduino
Post by: kerimil on Sep 03, 2013, 02:09 pm
Quote
do you have a better idea for me to debugg this code
You should have tested communication of both devices, that is use Putty/Serial monitor and a USB bluetooth dongle to:
A) check if the arduino responds to manually entered commands
B) see what does the phone and app send

I understand you did A, but you didn't do B.

The two procedures pretty much help in 95% of cases

EDIT
Ohh and I double checked your project and I just found out another error. You'll see what I mean when you do what I described above
Title: Re: Using android mobile to control arduino
Post by: RuiSantos on Sep 11, 2013, 01:34 pm
thanks!
Actually I made my app work 2 days ago before I saw your answer . I don't know why I didn't figured out that before it was pretty easy bug to fix ... :)
thanks for your help (yeah that was my mistake: " the problem was that your app was sending bytes and arduino was expecting integers")

All the best,
Rui Santos
Title: Re: Using android mobile to control arduino
Post by: kerimil on Sep 26, 2013, 09:52 pm
I'll add a new example app soon - I still have to film it. Support for sliders has recently been added so I just want to show you how to use them to control RGB lights (and how to send several values using send string and parse int on arduino side)

ohh and if you have any suggestions or ideas for apps feel free to post them - I am running out of ideas  :)
Title: Re: Using android mobile to control arduino
Post by: RuiSantos on Sep 28, 2013, 12:55 pm

I'll add a new example app soon - I still have to film it. Support for sliders has recently been added so I just want to show you how to use them to control RGB lights (and how to send several values using send string and parse int on arduino side)

ohh and if you have any suggestions or ideas for apps feel free to post them - I am running out of ideas  :)


Thanks Kerimil!
I finished my project a few days ago... (you can watch it here: http://randomnerdtutorials.com/arduino-control-2-dc-motors-via-bluetooth/ (http://randomnerdtutorials.com/arduino-control-2-dc-motors-via-bluetooth/))

And by the way, please read the P.P.S.

Thanks again for your awesome help!
Title: Re: Using android mobile to control arduino
Post by: kerimil on Sep 28, 2013, 04:51 pm
Thx santos - I am glad I could help


Here is the new video ->
http://www.youtube.com/watch?v=cSDkNptPpYU
It's really basic
the arduino sketch is here:
Code: [Select]


// pins for the LEDs:
const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;

void setup() {
 // initialize serial:
 Serial.begin(19200);
 // make the pins outputs:
 pinMode(redPin, OUTPUT);
 pinMode(greenPin, OUTPUT);
 pinMode(bluePin, OUTPUT);
 Serial.setTimeout(50);
}

void loop() {
 // if there's any serial available, read it:
 while (Serial.available() > 0) {

   // look for the next valid integer in the incoming serial stream:
   int red = Serial.parseInt();
   // do it again:
   int green = Serial.parseInt();
   // do it again:
   int blue = Serial.parseInt();

   // look for the newline. That's the end of your
   // sentence:
   if (Serial.read() == '\n') {
     // constrain the values to 0 - 255 and invert
     // if you're using a common-cathode LED, just use "constrain(color, 0, 255);"
     red = 255 - constrain(red, 0, 255);
     green = 255 - constrain(green, 0, 255);
     blue = 255 - constrain(blue, 0, 255);

     // fade the red, green, and blue legs of the LED:
     analogWrite(redPin, red);
     analogWrite(greenPin, green);
     analogWrite(bluePin, blue);

 
     
   }
 }
}
Obviously you might have to change baud rate if your module uses different

rgb_1.apk is the app
rgb_1.zip is a source file for use with app inventor (to upload the source it into app inventor you have to click on more actions button right next to to new button you use to create new projects - there is an option upload source. Just select it an upload the file)

Wiring is almost exactly the same as in here -> http://arduino.cc/en/Tutorial/ReadASCIIString
but I used pins 9,10 and 11 instead of 3,5 and 6.

NOTICE
If you're not logged in as a member here you can't see the attachments so you can't download them. I just realized this problem. So if for the aforementioned reason you can't see the files just try this link instead ->>
https://drive.google.com/folderview?id=0B_PfPoEotOF8N2JwT3RSX011SjQ&usp=sharing
Title: Re: Using android mobile to control arduino
Post by: spline on Sep 30, 2013, 07:37 pm
http://speedy.sh/63Q9N/bluetoothforarduino-app-2.apk

kerimil, please, upload again...

edit

I found the correct download link.
Title: Re: Using android mobile to control arduino
Post by: RuiSantos on Oct 12, 2013, 07:14 pm
That's the project I've made with the help of Kerimil.
Take a look below! you can download everything at my website:

http://randomnerdtutorials.com/arduino-control-2-dc-motors-via-bluetooth/ (http://randomnerdtutorials.com/arduino-control-2-dc-motors-via-bluetooth/)

http://www.youtube.com/watch?v=3RsfA6ngLdQ (http://www.youtube.com/watch?v=3RsfA6ngLdQ)
Title: Re: Using android mobile to control arduino
Post by: kevindomadia on Oct 14, 2013, 10:15 am
Hi!!..thanks for this application...whenever I connect my android phone to bluetooth device to arduino uno it shows a runtime error :
Need bluetooth _admin permission :neither user 10116 nor current proces has android.permission.BLUETOOTH_ADMIN...please help..
I am using HC-06 bluetooth module. It gets paired normally but not using this application....
Please help!!
Title: Re: Using android mobile to control arduino
Post by: kerimil on Oct 21, 2013, 11:54 pm

Hi!!..thanks for this application...whenever I connect my android phone to bluetooth device to arduino uno it shows a runtime error :
Need bluetooth _admin permission :neither user 10116 nor current proces has android.permission.BLUETOOTH_ADMIN...please help..
I am using HC-06 bluetooth module. It gets paired normally but not using this application....
Please help!!

AFAIK that's problem with your device. Apparently for some reason bluetooth SPP is blocked on it. Probably rooting the phone might help but I never tested that. Other people who reported the same problem just used a different device
Title: Re: Using android mobile to control arduino
Post by: kerimil on Nov 08, 2013, 04:14 am
New update coming soon. This time a major one - I decided to switch to ethernet rather than a bluetooth communication. There are a couple of reasons for that...
First of all, I found a cheap ethernet module (ENC28j60) that's roughly $6 a piece and a good library for it (not the standard one) - that's more less as cheap as the cheapest bluetooth modules.
Secondly, it eliminates the need to have a separate android device to serve as a relay between arduinos and the internet - that gets annoying when you want to have a remote temperature sensor at home.
What's more, I think it will be easier to understand and troubleshoot than bluetooth communication since everything is more transparent (some ppl just couldn't understand that it's good to see what's being sent).
Finally, it allows to use all the different devices to access arduino (not just android devices, but computers and apple/ windows phone devices as well.... though that's through a browser not an app created with MIT's app inventor, but it's nice to have that option)

Not sure if I post it here or in a separate thread - probably in a seperate one because I am afraid it will get confusing after a couple of pages and ppl might fail to notice that there are completely two different methods.
Title: Re: Using android mobile to control arduino
Post by: lovejoy777 on Dec 15, 2013, 12:31 pm
Hi guys if anyone just wants an android app for switching relays then here's a nice free app iv'e written.
https://play.google.com/store/apps/details?id=com.lovejoysa.btswitch
Title: Re: Using android mobile to control arduino
Post by: ROBOHIPPY on Dec 17, 2013, 11:11 pm
hi i found you artical, good stuff, i tried downloading the app inventor source code, but it seems it wont work in app inventor 2, any ideas ?
Title: Re: Using android mobile to control arduino
Post by: kerimil on Dec 18, 2013, 01:03 am
Just use the previous version. Upload it there and see how it works, you can replicate it in appinventor2 in a few minutes once you understand what's needed.

Also as far as I know Appinventor 2 doesn't have any new features yet and its GUI is almost identical

Here you can access the standard version http://beta.appinventor.mit.edu/
Title: Re: Using android mobile to control arduino
Post by: StanD on Jan 27, 2014, 04:14 am
Great write-up, thanks for sharing! It is annoying that App Inventor does not offer a conversion tool. I used App Inventor 2 to create  a basic remote for my test robot. Video  and the code are here: http://42bots.com/showcase/arduino-robot-controlled-from-an-android-phone-via-bluetooth/
Title: Re: Using android mobile to control arduino
Post by: goodsayan on Feb 04, 2014, 11:18 am
Hi,
I work on similar project. I would like controlling lamps by RF emitter via android app/bluetooth.
I have found sketch "HE300 Automatic Protocol Transmitter 'Simulator' " for replace my chacon remote on Homeeasy page:
http://playground.arduino.cc/Code/HomeEasy
The frame is composed of 32 bits (ON / OFF)
it's works great.

Now I would like send frame by android app like you.
In your case, you make pin on high or low but how I can send the chacon frame composed of 32 bits?

Thank you!
Title: Re: Using android mobile to control arduino
Post by: Tafrata on Feb 16, 2014, 12:06 pm
Hi Kerimil,
I've tried to load your file, but seems impossible the current App inventor release do not support .zip file format, only suffix .aia format is supported, and the blocks code are not compatible.

do you have please an .aia release

Thanks
Title: Re: Using android mobile to control arduino
Post by: kerimil on Feb 16, 2014, 12:31 pm
No, I don't.
My advice ?? open the old file using the old version of app inventor, see what blocks are used and what they do and then replicate it in the new version
Title: Re: Using android mobile to control arduino
Post by: KOTSOS5 on Feb 19, 2014, 12:01 am
Hi Kerimil! Your project is wonderful but since you look for new ideas how about mixing your circuits and make one program that can control, let's say 9 different lamps, with indicators ON/OFF and when you switch one you can dim it!
Title: Re: Using android mobile to control arduino
Post by: Gazzla on Feb 21, 2014, 05:53 am
Hi kerimil
how to get LED indikator off or ON Status  to show in android app?
Title: Re: Using android mobile to control arduino
Post by: Spyrakos88 on Feb 24, 2014, 07:31 pm
Hello my friends. Firstly i want to say thenks for the code because it helped with a handy project.

The problem is that the same code that i use with the arduino duemilanove it doesnt work with attiny 85... the code is very simple.
here is the code for attiny85
Code: [Select]

#include <SoftwareSerial.h>//Software Serial Port
#define RxD 1
#define TxD 2


SoftwareSerial blueToothSerial(RxD,TxD);

byte serialA;

void setup()
{
 blueToothSerial.begin(9600);
 pinMode(RxD, INPUT);
 pinMode(TxD, OUTPUT);

}

void loop()
{
 
   if (serialA == 49){int sensorValue = analogRead(A0);
 blueToothSerial.println(sensorValue);
 delay(100);
 serialA = 0;
 
 }


void serialEvent(){
serialA = blueToothSerial.read();
}


when i connect the app is freazing as you see i try to send contineus data from arduino to phone.  Do you think that i must find another way to communicate?
Thanks!

Edit: It seems that the serial with the attiny85 doesn't working properly. I always take chinese characters. I dont know why i burned the bootloader without any errors the blink example is working but the serial no...
Title: Re: Using android mobile to control arduino
Post by: wacou123 on Feb 25, 2014, 02:53 pm
It doesn't work for my :/ i have tried with like 5 diffrent apps and codes but none of them worked..
Title: Re: Using android mobile to control arduino
Post by: kerimil on Mar 21, 2014, 12:21 am
1. Well if you want to control more than one LED just modify the app.
2. If you want a status indicator then you can either implement it within the app without getting any confirmation from the board that the message was received (less complicated) or write a code that sends serial data from the arduino board to the phone when the LED is switched on.

@ spyrakos88
I have no idea why it doesn't work with attiny85, but there is an error in your code (or at least the version that you posted here). Your void loop() is missing a "}" sign. Other than that make sure your tx pin is attached to rx pin on the bluetooth module. What's more make sure the baud rate of your code is the same as the one your bluetooth module is set to. What's more try to get rid of that serialEvent - I don't know if it works with software serial, but I know that it doesn't work with leonardo, micro and esplora. So get rid of it.
Title: Deleted File
Post by: agtzg92 on Apr 14, 2014, 01:20 am
Hi, can you upload the app again please? that link is no longer available, and also MIT App inventor asks for an ".aia" file to open this project.

Can you upload it as well? thanks
Title: Re: Using android mobile to control arduino
Post by: kerimil on Apr 14, 2014, 11:31 am
I'll update it one day but my friend borrowed the bluetooth module for some experimenting so it might take a while.

You can still access the older version of app inventor here -> http://beta.appinventor.mit.edu/
And here are all of my projects -> https://drive.google.com/folderview?id=0B_PfPoEotOF8N2JwT3RSX011SjQ&usp=sharing

Just use the older version to see what blocks I used and what they do and rebuild it in the newest version. Or just use the old one
Title: Re: Using android mobile to control arduino
Post by: kitkatbarxp on Jul 31, 2014, 11:59 am

I'll update it one day but my friend borrowed the bluetooth module for some experimenting so it might take a while.

You can still access the older version of app inventor here -> http://beta.appinventor.mit.edu/
And here are all of my projects -> https://drive.google.com/folderview?id=0B_PfPoEotOF8N2JwT3RSX011SjQ&usp=sharing

Just use the older version to see what blocks I used and what they do and rebuild it in the newest version. Or just use the old one


hi Kerimil, thanks for your work! I do have a question though. I installed in on my Android, but when I ran it, it gave me a RunTime Error of not having Bluetooth Admin permission. Is it not built in?
Title: Re: Using android mobile to control arduino
Post by: mzh_s on Aug 04, 2014, 10:22 am
hi friend..

can u show how you use the mit app inventor..
Title: Re: Using android mobile to control arduino
Post by: naurisdzerve on Nov 18, 2014, 11:49 pm
Can someone please help to send information from App inventor Spinner to arduino. I made Spinner 1-9 and now I want this information on arduino.
Title: Re: Using android mobile to control arduino
Post by: kalpana on Apr 13, 2015, 02:07 pm
hi,

    Is it possible to have android accessory on ATSAMD21 similar to that of AVR32848.
If so how can this be implemented.
Title: Re: Using android mobile to control arduino
Post by: janjust99 on May 06, 2015, 12:26 pm
Hello, could you pls uploaded apk file.
This link is not working http://speedy.sh/63Q9N/bluetoothforarduino-app-2.apk
Thanks
Jan
Title: Re: Using android mobile to control arduino
Post by: Arne_ on May 19, 2015, 08:21 pm
Hi , I'm trying to combine the temperature appication and the slide application (with the LEDs) to one application. when I am trying to connect the application it freezes, appart the two applications work but to merge it I still have some problems. the Arduino program that I currently have.


#include <OneWire.h>

int DS18S20_Pin = 2;

//temperatuur chip in/ out
OneWire ds(DS18S20_Pin);
const int greenPin = 9;
const int bluePin =11; 
const int redPin2 = 10;
byte serialA;

void setup() {

Serial.begin(9600);



pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(redPin2, OUTPUT);




}

void loop() { // word steets herhaalt


if (serialA == 49){float temperature = getTemp();
serialA = 0;

}
// als er serial data is, lees dit
while (Serial.available() > 0) {


 int green = Serial.parseInt();

 int blue = Serial.parseInt();

 int red2 = Serial.parseInt();

 if (Serial.read() == '\n') {       

   green = constrain(green, 0, 255);
   blue = constrain(blue, 0, 255);
   red2 = constrain(red2, 0, 255);

   analogWrite(greenPin, green);
   analogWrite(bluePin, blue);
   analogWrite(redPin2, red2); 
 }
}

}

float getTemp(){

byte data[12];
byte addr[8];
if ( !ds.search(addr)) {

ds.reset_search();
return -100;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
return -1000;

}
if ( addr[0] != 0x10 && addr[0] != 0x28) {
return -1000;

}
ds.reset();
ds.select(addr);
ds.write(0x44,1);
byte present = ds.reset();
ds.select(addr);
ds.write(0xBE);
for (int i = 0; i < 9; i++) {
data = ds.read();
}
ds.reset_search();
byte MSB = data[1];
byte LSB = data[0];
float tempRead = ((MSB << 8) | LSB);
float TemperatureSum = tempRead / 16;
return TemperatureSum;}
void serialEvent()
{
serialA = Serial.read();
}



thanks for helping
Title: Re: Using android mobile to control arduino
Post by: Hanadi on May 21, 2015, 11:52 am
Hay Guys anyone can help here i need an arduino code with 4 DC  cuz only the 2DC is working with me
with bluetooth module

- i dunno how to change the com if i want the car to be controlled by andriod mobile

- the car wheels only moves while am holding it up from the ground only i dunno what is the reason

HELPP Please ! Thanks in advance.
Title: Re: Using android mobile to control arduino
Post by: Sushma_S on Jun 27, 2015, 09:29 am
hi kerimil
thank you for sharing ur work with us.
please helpme.

am doing project on arduino. my project is controlling the lighting systems, where i have to control the LED blinking ON/Off , dimming LED's .

am using below code to dimming the LED's

// Output
int redPin   = 9;   // Red LED,   connected to digital pin 9
int greenPin = 10;  // Green LED, connected to digital pin 10
int bluePin  = 11;  // Blue LED,  connected to digital pin 11

// Program variables
int redVal   = 255; // Variables to store the values to send to the pins
int greenVal = 1;   // Initial values are Red full, Green and Blue off
int blueVal  = 1;

int i = 0;     // Loop counter   
int wait = 50; // 50ms (.05 second) delay; shorten for faster fades
int DEBUG = 0; // DEBUG counter; if set to 1, will write values back via serial

void setup()
{
  pinMode(redPin,   OUTPUT);   // sets the pins as output
  pinMode(greenPin, OUTPUT);   
  pinMode(bluePin,  OUTPUT);
  if (DEBUG) {           // If we want to see the pin values for debugging...
    Serial.begin(9600);  // ...set up the serial ouput on 0004 style
  }
}

// Main program
void loop()
{
  i += 1;      // Increment counter
  if (i < 255) // First phase of fades
  {
    redVal   -= 1; // Red down
    greenVal += 1; // Green up
    blueVal   = 1; // Blue low
  }
  else if (i < 509) // Second phase of fades
  {
    redVal    = 1; // Red low
    greenVal -= 1; // Green down
    blueVal  += 1; // Blue up
  }
  else if (i < 763) // Third phase of fades
  {
    redVal  += 1; // Red up
    greenVal = 1; // Green low
    blueVal -= 1; // Blue down
  }
  else // Re-set the counter, and start the fades again
  {
    i = 1;
  } 

  analogWrite(redPin,   redVal);   // Write current values to LED pins
  analogWrite(greenPin, greenVal);
  analogWrite(bluePin,  blueVal); 

  if (DEBUG) { // If we want to read the output
    DEBUG += 1;     // Increment the DEBUG counter
    if (DEBUG > 10) // Print every 10 loops
    {
      DEBUG = 1;     // Reset the counter

      Serial.print(i);       // Serial commands in 0004 style
      Serial.print("\t");    // Print a tab
      Serial.print("R:");    // Indicate that output is red value
      Serial.print(redVal);  // Print red value
      Serial.print("\t");    // Print a tab
      Serial.print("G:");    // Repeat for green and blue...
      Serial.print(greenVal);
      Serial.print("\t");   
      Serial.print("B:");   
      Serial.println(blueVal); // println, to end with a carriage return
    }
  }
  delay(wait); // Pause for 'wait' milliseconds before resuming the loop
}




In my project am using arduino uno with bluetooth HC-05./bluetooth+HC+05‎

i want to control this arduino with my android phone.i want to send commands from my phone to arduino through the bluetooth to controll this dimming of LED's.

for this control am using the android mobile app is andudroid.https://play.google.com/store/apps/details?id=com.techbitar.android.

i want to write a code for controlling arduino by android. so what can i add to my code to response with my android commands.
can u please send me a  source code to do this operation. its very helpfull for me.
Am waiting for ur reply.


thank u

Title: Re: Using android mobile to control arduino
Post by: Sushma_S on Jun 27, 2015, 09:32 am
hi kerimil
thank you for sharing ur work with us.
please helpme.

am doing project on arduino. my project is controlling the lighting systems, where i have to control the LED blinking ON/Off , dimming LED's .

am using below code to dimming the LED's

// Output
int redPin   = 9;   // Red LED,   connected to digital pin 9
int greenPin = 10;  // Green LED, connected to digital pin 10
int bluePin  = 11;  // Blue LED,  connected to digital pin 11

// Program variables
int redVal   = 255; // Variables to store the values to send to the pins
int greenVal = 1;   // Initial values are Red full, Green and Blue off
int blueVal  = 1;

int i = 0;     // Loop counter   
int wait = 50; // 50ms (.05 second) delay; shorten for faster fades
int DEBUG = 0; // DEBUG counter; if set to 1, will write values back via serial

void setup()
{
  pinMode(redPin,   OUTPUT);   // sets the pins as output
  pinMode(greenPin, OUTPUT);   
  pinMode(bluePin,  OUTPUT);
  if (DEBUG) {           // If we want to see the pin values for debugging...
    Serial.begin(9600);  // ...set up the serial ouput on 0004 style
  }
}

// Main program
void loop()
{
  i += 1;      // Increment counter
  if (i < 255) // First phase of fades
  {
    redVal   -= 1; // Red down
    greenVal += 1; // Green up
    blueVal   = 1; // Blue low
  }
  else if (i < 509) // Second phase of fades
  {
    redVal    = 1; // Red low
    greenVal -= 1; // Green down
    blueVal  += 1; // Blue up
  }
  else if (i < 763) // Third phase of fades
  {
    redVal  += 1; // Red up
    greenVal = 1; // Green low
    blueVal -= 1; // Blue down
  }
  else // Re-set the counter, and start the fades again
  {
    i = 1;
  }

  analogWrite(redPin,   redVal);   // Write current values to LED pins
  analogWrite(greenPin, greenVal);
  analogWrite(bluePin,  blueVal);

  if (DEBUG) { // If we want to read the output
    DEBUG += 1;     // Increment the DEBUG counter
    if (DEBUG > 10) // Print every 10 loops
    {
      DEBUG = 1;     // Reset the counter

      Serial.print(i);       // Serial commands in 0004 style
      Serial.print("\t");    // Print a tab
      Serial.print("R:");    // Indicate that output is red value
      Serial.print(redVal);  // Print red value
      Serial.print("\t");    // Print a tab
      Serial.print("G:");    // Repeat for green and blue...
      Serial.print(greenVal);
      Serial.print("\t");   
      Serial.print("B:");   
      Serial.println(blueVal); // println, to end with a carriage return
    }
  }
  delay(wait); // Pause for 'wait' milliseconds before resuming the loop
}




In my project am using arduino uno with bluetooth HC-05./bluetooth+HC+05‎

i want to control this arduino with my android phone.i want to send commands from my phone to arduino through the bluetooth to controll this dimming of LED's.

for this control am using the android mobile app is andudroid.https://play.google.com/store/apps/details?id=com.techbitar.android.

i want to write a code for controlling arduino by android. so what can i add to my code to response with my android commands.
can u please send me a  source code to do this operation. its very helpfull for me.
Am waiting for ur reply.


thank u
Title: Re: Using android mobile to control arduino
Post by: broxcode on Aug 01, 2015, 01:32 pm
Hi,


You can find here a very recent application with new openings about how to control your board from your mobile  : https://play.google.com/store/apps/details?id=com.errafay.arduinobluecontrol , i hope you enjoy it ;) !
Title: Re: Using android mobile to control arduino
Post by: RiteshKotiyal on Sep 25, 2015, 04:08 pm
Can some one tell me how to make the andorid source code to send string to the arduino mega and the arduino sends some data to the android without using MIT app inventor... Plz help.
Title: Re: Using android mobile to control arduino
Post by: allend62 on Apr 27, 2016, 06:16 pm
great ive been searching for this thanks
Title: Re: Using android mobile to control arduino
Post by: NAQEEBULLAH on Oct 13, 2016, 05:15 pm
hi
   I would like to control Arduino nano through android, but its not working, even I have download arduinodroid
from android ply store but still failed to run it kindly guide me in this regard

NaqeebUllah
Title: Re: Using android mobile to control arduino
Post by: rguig1u on Mar 06, 2018, 04:52 pm
Why you dont initialise your communication for exemple BTSerial(10,11) //(RX,TX)
Title: Re: Using android mobile to control arduino
Post by: the_muck on Jul 22, 2018, 12:46 pm
Hello,
i start to playing with this example...

https://www.youtube.com/watch?v=xjtxrxVauZg

so, i received the massages in the TextBox but my problem is that i am not sure how i find the end of my massage. What i have to do with  DelimiterByte and CharacterEncoding in MIT Appinventor?

in my TextBox is a long massage not only the sendet value...

Malte

Title: Re: Using android mobile to control arduino
Post by: polymorph on Jul 23, 2018, 05:03 am
You should start a new thread rather than posting on a thread this old.
Title: Re: Using android mobile to control arduino
Post by: foufouner on Mar 27, 2019, 03:33 pm
Hello kerimil
I want test your apk but the link apk or aia for download not work !
Title: Re: Using android mobile to control arduino
Post by: Jun_Z on Apr 12, 2019, 04:24 am
Thank you for your explanation.

Is this only can use for cosm website?
How could i create my own website and how to let the arduino to send the data to that webiste?