Hi everyone,
I'm working in project involving Arduino, Bluetooth and Android. My Arduino hardware will collect data from sensors and send them to an Android tablet via Bluetooth. My application on Android seems to work well when I tested it with BlueChat; it successfully receives data from BlueChat. Following is my code for my Arduino hardware. I'm quite sure I initiate HC-05 correctly. Can anyone look at my code and suggest whether it works if my idea is to collect reading from a temperature sensor at Analog pin 0, then transmit them to Digital pin 11, which is the Tx pin on Arduino connecting to Rx pin of Hc-05?
I should mention that I power my Arduino Uno externally by an 9V battery.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11);
int tempPin=0;
He is just trying to be charitable, and it's probably still the best advice you have seen on this thread.
Your code looks a bit messy, but I think it's likely to give a result. You don't actually say if you've got a problem but, if you do, it may be down to inadequate power.
The problem with using a new 9v battery with an Arduino is the depressing speed with which it becomes an old one. Sending a boy on a man's job is never a good idea, and all it does is make solving your problem more complicated.
Even I use the USB cable to power the Arduino, my code still doesn't work.
This sounds like a better idea, to the point where one might conclude that you do have a problem, and it's not power. Having said that, even USB power can be inadequate when you start adding displays etc.
The problem is not likely to be serious, and I would suggest you go through basic tests. You might find the following background notes useful
Currently, one of the most important lines in your code
Serial.begin(9600);
is redundant.
You have not demonstrated a reason for using software serial, so I bet you haven't got one and you would be better off using the above line and ditching software serial. It may not be your problem, but sending it where it belongs makes sure that it isn't.
You have not demonstrated a reason for using software serial, so I bet you haven't got one and you would be better off using the above line and ditching software serial. It may not be your problem, but sending it where it belongs makes sure that it isn't.
I disagree with the first part of this statement. OP has a problem. It needs debugging. The only useful too is Serial.print() statements. That will be impossible if Serial is used to talk to the bluetooth device.