我的 HC-05 蓝牙模块没有收到正确的数据

My HC-05 Bluetooth module is not receiving correct data

我正在尝试使用 HC-05 构建 LED 信号灯,但我遇到了错误。

这是 Arduino 代码:

int 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())      // 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
   }
}

无论我按下或关闭哪个按钮,int 数据的值将保持不变 (255)。

我也用过很多app所以我觉得不是app的问题

我找到了这个问题的答案。

只需更改波特率并观察输出。我的模块在 38400 上运行完美。

希望对您有所帮助。