Need help - Arduino Uno and HC-05 data transmission

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;

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

void loop()
{
float reading = analogRead(tempPin); // reading on tempPin
float voltage = reading*5.0/1024.0; // the resolution of a pin is 10 bit,
float tempC = voltage/0.01; // 10mV = 1 Celcius
mySerial.write(tempC);

delay(3000);
}

Moderator: please do not cross-post - it wastes time for everyone including you

please remove the duplicates

check this thread, might be interesting - [Solved] Arduino unstable reading from HC-05 Bluetooth modules - Networking, Protocols, and Devices - Arduino Forum

I tried but that thread is for receiving Bluetooth data.

Your code uses

mySerial.write(tempC);

That should at least be

mySerial.print(tempC, 2);

as write cannot send a float

give it a try

I should mention that I power my Arduino Uno externally by an 9V battery.

Put the 9V battery back in the smoke detector you stole it from and use a real battery.

Come on bro, I bought it from shop :~

robtillaart:
Your code uses

mySerial.write(tempC);

That should at least be

mySerial.print(tempC, 2);

as write cannot send a float

give it a try

Tks but it didn't work either. I also tried 'mySerial.print(tempC, DEC)' but nothing done.

PhanNam:
Come on bro, I bought it from shop :~

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.

I'm using a brand new 9V battery. Even I use the USB cable to power the Arduino, my code still doesn't work. Tks for your suggestion all bro.

PhanNam:
I'm using a brand new 9V battery.

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

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf
http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

You have two goals:

  1. prove your bluetooth communication
  2. prove the temperature readings

You do not need the first to prove the second.

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.

I agree !00% with everything else you said.