05從Arduino傳資料到Android

Arduino端的程式

#include <SoftwareSerial.h>

SoftwareSerial BT(0,1); // 接收腳(RX), 傳送腳(TX);接HC-06之TXD、RXD;先不要用0,1,因為USB用

int potPin = 0; //A0 滑桿,可用S4A擴充板來做

void setup()

{

Serial.begin(9600); //for arduino serial port mointor

BT.begin(9600);

Serial.print("BT is ready!");

pinMode(potPin, INPUT);

}

void loop()

{

int value = analogRead(potPin); // read the value of the Analog Input

BT.println(value);

Serial.println(value); // Print the value; can also be seen on Serial Monitor

delay(1000); // Don't send too fast or the Android buffer will flood溢出 - this worked for me

}