无法将BLE连接到Android应用

时间:2017-10-14 16:02:10

标签: android bluetooth hm-10

我刚买了一台带CC2541芯片的蓝牙HM-10模块。我用Arduino Uno为它供电。我用手机扫描了蓝牙设备(samsung j3,2016),发现名为BT05的模块。我配对设备,但我无法将蓝牙模块与任何应用程序连接。我尝试将其连接到 AMR语音/ BT语音控制应用 LED控制器。 我通过app控制LED的代码来自:create.arduino.cc/projecthub/user206876468/arduino-bluetooth-basic-tutorial-d8b737

我把代码放在这里:

char data = 0;            //Variable for storing received data
void setup()
{
Serial.begin(9600);   //Sets the baud for serial data transmission                               
pinMode(13, OUTPUT);  //Sets digital pin 13 as output pin
}
void loop()
{
if(Serial.available() > 0)      // Send data only when you receive data:
{
  data = Serial.read();        //Read the incoming data & store into data
  Serial.print(data);          //Print Value inside data in Serial monitor
  Serial.print("\n");        
  if(data == '1')              // Checks whether value of data is equal to 1
     digitalWrite(13, HIGH);   //If value is 1 then LED turns ON
  else if(data == '0')         //  Checks whether value of data is equal to 
  0
     digitalWrite(13, LOW);    //If value is 0 then LED turns OFF
 }
 }

这些是我得到的错误: enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

也许您可以尝试自己的工作并自行更改代码

#include <SoftwareSerial.h> 

SoftwareSerial BT(2, 3); //RX, TX

char val;

void setup() {

Serial.begin(9600);  
BT.begin(9600);
Serial.println("BT is ready!");  

}

void loop() {
if (BT.available()>0) {
    val = BT.read();
    Serial.print(val);
  }
}