我正在從事涉及Arduino,藍牙和Android的項目。我的Arduino硬件將從傳感器收集數據並通過藍牙將它們發送到Android平板電腦。當我用BlueChat測試它時,我的Android應用程序似乎運行良好;它成功地從BlueChat接收數據。以下是我的Arduino硬件代碼。我很確定我正確啓動HC-05。任何人都可以看看我的代碼,並建議它是否工作,如果我的想法是收集模擬引腳0上的溫度傳感器讀數,然後將它們傳輸到數字引腳11,這是Arduino上的Tx引腳連接到Hc-05的Rx引腳?Arduino傳輸數據到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);
}
我應該提一下,我使用9V電池從外部爲Arduino Uno供電。
謝謝,但它沒有工作,錯誤'類'SoftwareSerial'沒有名爲'writeln'的成員發生。 – 2014-09-20 02:02:49
這是println,我打錯了。 – 323go 2014-09-21 01:36:42
TKS兄弟,我已經嘗試了println和打印,但沒有任何作品。 – 2014-09-21 04:22:49