I am looking for a good strategy for sending and receiving real time data from an android uno and an android app using a silver bluetooth mate.
The arduino has a potentiometer hooked up as a sensor. I need to send constant readings from this sensor to the android. Also the android app needs to send occasional commands to the arduino like “Set your threshold variable to 945”
Right now I have the arduino check for available data on the bluetooth and reads it if available otherwise it writes the sensor reading. I am able to get the sensor reading on the android app consistently, but the commands from android to the arduino are garbled. Sometimes the letters come across properly but most of the time its just funny looking characters. If I add a 100ms delay after sending the sensor reading everything seems fine, but that really slows down the readings.
I am not sure if its a factor or not, but I have the bluetooth serial line hooked up to arduino’s D2 and D3 pins and am using the NewSoftSerial libary to do the talking to the bluetooth at 9600 baud. I also have the arduino plugged into my pc via usb where I use the serial monitor to debug the values
Is the NewSoftSerial a problem?
Can I use the Rx/Tx pins on the arduino for the bluetooth and still be able to program and communicate from the pc?
Is there a problem with sending and receiving data at the same time?
NewSoftSerial: NewSoftSerial | Arduiniana
Bluetooth Mate: http://www.sparkfun.com/products/10404
I was recently doing something very similar except the bulk of my data was flowing from Android's accelerometer to the Arduino. However I didn't finish the work so I'm not able to fully answer.
First, you cannot connect the Bluetooth serial to the Uno's hardware UART if you want to keep USB functionality. These pins (0 and 1) are tied to the USB to serial chip on all Arduino models. However, if it is an option I would highly recommend moving to the Arduino Mega as you can use multiple hardware UARTs to be able to use USB and Bluetooth both without the need for software serial.
If the mega isn't an option... Which Arduino version are you using? Which NewSoftSerial version are you using? If you use Arduino 1.0 NewSoftSerial is included as SoftwareSerial (replacing the old SoftwareSerial). This would be the best setup for a known good config for a software setup.
In any case, I don't see any particular reason your setup wouldn't work as 9600 is a very acceptable speed for SoftwareSerial. Maybe post your relevant code?
Look my project, its a cheap US$ 6,00 Deal Extreme bluetooth module.
This is my source right now
int bluetoothTx = 2;
int bluetoothRx = 3;
byte testValue = 254;
char readIndex = 0;
int sensorValue = 0;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
LiquidCrystal lcd(12, 11, 10, 13, 9, 8);
//Setup usb serial
while(bluetooth.available() > 0)
char aChar = bluetooth.read();
if(aChar == ‘\n’)
p = readBuffer;
str = strtok_r(p, “,”, &p);
//str = strtok_r(p, “,”, &p);
readIndex = 0;
readBuffer[readIndex] = aChar;
readBuffer[readIndex] = ‘\0’; //Keep the string null terminated
sensorValue = analogRead(A5);
char toSend = (char)Serial.read();
Try reducing the Bluetooth serial port speed. 57600 was max in my case.