Hi, I have just started Arduino programming a few days ago and now I want to transfer potentiometer reading to a mobile device. I am using Arduino Leonardo and Bluetooth Mate Silver and the following code to transfer data:
#include <SoftwareSerial.h>
int bluetoothTx = 2; // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3; // RX-I pin of bluetooth mate, Arduino D3
int val;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
Serial.begin(9600); // Begin the serial monitor at 9600bps
bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
bluetooth.print("$"); // Print three times individually
bluetooth.print("$");
bluetooth.print("$"); // Enter command mode
delay(100); // Short delay, wait for the Mate to send back CMD
bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
bluetooth.begin(9600); // Start bluetooth serial at 9600
}
void loop()
{
int val = analogRead(A0);
if(bluetooth.available()) // If the bluetooth sent any characters
{
Serial.print(val);
}
if(Serial.available()) // If stuff was typed in the serial monitor
{
bluetooth.print(val);
}
delay(1000);
// and loop forever and ever!
}
I found that bluetooth connection estublished without any error, however I am not getting any data on mobile device. I changed the code (e.g., without the if statement/ printing potentiometer data on serial monitor and read the data from serial monitor to the transfer into mobile device), only I get the data in mobile device if I enter any values in serial monitor. I would highly appreciate if anyone could suggest me possible solutions to solve it.