Functionality: Android talks to Arduino
1. Run the Android "Bluetooth Chat" sample app (after we modify the app in this instructable). Type a message in the app's text box and press the "send" button. The message you typed echoes on the app display.
2. Message travels through the air from the built-in Android Bluetooth modem to the Bluetooth modem connected to the Arduino Uno.
3. Arduino Uno receives the typed message.
4. The Arduino Uno prints the typed message on the LCD.
Functionality: Arduino talks to Android
1. Every 30 seconds, the Arduino sends a message ("hello from Arduino") to the Android phone via Bluetooth.
2. The Arduino message appears on the Android "Bluetooth Chat" sample app display.
Why? Just an easy way to test the Arduino's ability to not only receive messages from, but send messages to the Android phone. You can take the example sketch and change it however you want.
Here's the full video instruction that we'll break out into steps:
Remove these ads by
Signing UpStep 1: Hardware list
- Arduino Uno (328, 16MHz, 5V).
- Bluetooth Modem: BlueSMiRF Gold, aka FireFly (Sparkfun sku: WRL-00582).
- Parallel LCD (Sparkfun sku: LCD-09051 but you can use pretty much any parallel LCD).
- 10k Potentiometer.
- Wires to connect electronic components.
- Computer and FTDI chip (to change BAUD rate).
- Android Phone (I used a Motorola Droid - operating system v2.2.2 - but Google has sample code for all versions).
Assemble your circuit as shown in the diagram. You don't have to assemble anything between circle #1 and circle #2: that is the message going through the air from Android to the Bluetooth modem. Hey, I'm an Arduino beginner so I'm not assuming anything. :)







































Visit Our Store »
Go Pro Today »




I followed your instructions for controlling LCD with arduino and android. I received a junk message from arduino.I did not get message "Hello from Arduino".But I got this message in serial monitor.Also the typed message from Bluetooth chat application not displayed on LCD Monitor.Please give me your suggestions.
No android programming is required and the Arduino code is simple.
Very flexiable control of Arduino projects via menus, multi-selection lists, text input, numeric input, navigation screens all controlled by the Arduino code (think micro pages max 255 chars). Arduino can send updates back to Andriod.
See www.pfod.com.au for numerous example projects, including showing text on an LCD. One user has coded the Arduino to run his KnightRider Lights from his Andriod using pfod with multiple menus, multiple screens and control options.
byte data;
String message;
void setup ()
{
// Sets the serial communication:
Serial.begin (57600);
// Sets the pins of the LEDs as output:
pinMode (6, OUTPUT);
pinMode (7, OUTPUT);
pinMode (8, OUTPUT);
pinMode (9, OUTPUT);
pinMode (10, OUTPUT);
}
void loop () {
int i=0;
// See if something has been received from the serial port:
if (Serial.available())
{
// Read the last byte received (value between 0 and 255)
data= Serial.read();
Serial.println (data);
if (data=='q') //q
{
digitalWrite(6, HIGH); // turn on LED 1 at pin6
message = "LED 1 On";
Serial.println (message);
}
if (data=='a') // a
{
digitalWrite(6, LOW); // off LED 1 at pin6
message = "LED 1 Off";
Serial.println (message);
}
if (data=='c') //c
{
digitalWrite(7, HIGH); //on LED 2
message = "LED 2 On";
Serial.println (message);
}
if (data=='d') //d
{
digitalWrite(7, LOW); // off LED 2
message = "LED 2 Off";
Serial.println (message);
}
if (data=='e') //e
{
digitalWrite(8, HIGH); //on LED 3
message = "LED 3 On";
Serial.println (message);
}
if (data=='f')// f
{
digitalWrite(8, LOW); //sets the LED 3
message = "LED 3 Off";
Serial.println (message);
}
if (data=='g') //g
{
digitalWrite(9, HIGH); //turn on LED 4
message = "LED 4 On";
Serial.println (message);
}
if (data=='h')//h
{
digitalWrite(9, LOW); //sets the LED 4
message = "LED 4 Off";
Serial.println (message);
}
if (data=='i') //i
{
digitalWrite(10, HIGH); //sets the LED 5
message = "L5 high";
Serial.println (message);
}
if (data=='j') //j
{
digitalWrite(10, LOW); //sets the LED 5
message = "LED 5 Off";
Serial.println (message);
}
if (data=='y') //y
{
digitalWrite(6, HIGH); // turn on ALL LEDs
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
message = "ALL LEDs ON";
Serial.println (message);
}
if (data=='z')//z
{
digitalWrite(6, LOW); //Turn off all LEDs
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
Serial.println ("ALL LEDs OFF");
}
else
{
digitalWrite(13, HIGH); //sets the LED 5
delay(3000); //3sec
digitalWrite(13, LOW);
delay(3000);
Serial.println (" else case executed ");
} ////end of else
// Send response
Serial.println (" end of loop "+message);
}
}
731
7
31
Any idea what could be causing this? I set the baud rate of the modem to 57600..thanks again
I've noticed the same thing and don't know what causes that. I'll try to check it out soon.
Thanks,
Mark
Thanks again,
Ervin
I verified what you saw and, unfortunately, I could not remedy it. For me, I get the problem about 10% of the time. I haven't had the time to test some workarounds but you could implement something similar to a checksum concept where you put an extra fixed message in your Arduino data and then check if that message comes through on the Android side. If on the receiving end (Android) you don't get the extra message that you append to your data on the Arduino side then you don't display the reading on Android. It is not complicated in concept but would take time to implement and test considering that you have a deadline. This was just a quick little proof-of-concept for me; hope it did more good than harm for you. :)
I was having the same problem. I somehow compensated for it. I am a newbie in these, so its not a very scientific solution, but works for me.
I am now sending fixed number of bytes from Arudino (even though sometimes the actual data is less.).
In the HandleMessage() funciton of BluetoothChat.java, under the case MESSAGE_READ, I check how many bytes there are to print. If it is less than expected, I wait for more bytes to arrive before printing and append the received incomplete String to the String that I will print.
case MESSAGE_READ:
byte[] readBuf = (byte[]) msg.obj;
// construct a string from the valid bytes in the buffer
String readMessage = new String(readBuf, 0, msg.arg1);
//messageString is declared as an empty global variable String
messageString = messageString + readMessage;
//the length of my message is 60
if (messageString.length()<60){
break;
}
//Get time
String mydate = java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
mConversationArrayAdapter.add(mydate +" : \n"+ messageString);
messageString = " ";
break;
Thanks in advanced :D
Jaycon
the file "bluetooth_chat_LCD.pde" is downloaded as a tmp file. I think this needs to be fixed?
thanks
frank