Reputation: 9
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?
#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);
}
I should mention that I power my Arduino Uno externally by an 9V battery.
Upvotes: 0
Views: 1936
Reputation: 21
Steps to try in this case: - Send anything via HC-05 (hello world) -> this will exclude connection problems (might be a good idea to put HC-05 on the "real" serial and the debug messages on the 'soft' serial)
Test analog read part of the code via Serial Monitor: you can see if you get reasonable data
Test the combination of sensor reading and sending via HC-05
Upvotes: 1
Reputation: 14274
I don't think SoftwareSerial
has a write( float )
method. I suggest you report back the raw data and let your app do the conversion. Don't forget delimiters, so you know when one number ends and the next starts:
void loop()
{
int reading = analogRead(tempPin); // reading on tempPin
mySerial.println( tempC, DEC );
delay(3000);
}
Upvotes: 0