HC-05和x2E2E;串行模式不起作用

HC-05和x2E2E;串行模式不起作用,c,bluetooth,serial-port,ascii,arduino-uno,C,Bluetooth,Serial Port,Ascii,Arduino Uno,我最近为我的arduino获得了一个HC-05蓝牙模块,但我无法从中发送或接收数据。我使用一个代码来打开或关闭led,但在我从电脑的串行监视器发送一个字符后,我得到了⸮. 此外,模块不响应任何AT命令。我运行了9600和38400波特的串行数据,但没有任何变化。我也尝试了无行结束和NL和CR。但是这个模块有问题吗?这是我的密码: /* Arduino Turn LED On/Off using Serial Commands Created April 22, 2015 Hammad Tariq

我最近为我的arduino获得了一个HC-05蓝牙模块,但我无法从中发送或接收数据。我使用一个代码来打开或关闭led,但在我从电脑的串行监视器发送一个字符后,我得到了⸮. 此外,模块不响应任何AT命令。我运行了9600和38400波特的串行数据,但没有任何变化。我也尝试了无行结束和NL和CR。但是这个模块有问题吗?这是我的密码:

/*
Arduino Turn LED On/Off using Serial Commands
Created April 22, 2015
Hammad Tariq, Incubator (Pakistan)

It's a simple sketch which waits for a character on serial
and in case of a desirable character, it turns an LED on/off.

Possible string values:
a (to turn the LED on)
b (tor turn the LED off)
*/

char junk;
String inputString="";

void setup()                    // run once, when the sketch starts
{
 Serial.begin(9600);            // set the baud rate to 9600, same     should be of your Serial Monitor
 pinMode(13, OUTPUT);
}

void loop()
{
  if(Serial.available()){
  while(Serial.available())
    {
      char inChar = (char)Serial.read(); //read the input
      inputString += inChar;        //make a string of the characters     coming on serial
    }
    Serial.println(inputString);
    while (Serial.available() > 0)  
    { junk = Serial.read() ; }      // clear the serial buffer
    if(inputString == "a"){         //in case of 'a' turn the LED on
      digitalWrite(13, HIGH);  
    }else if(inputString == "b"){   //incase of 'b' turn the LED off
      digitalWrite(13, LOW);
    }
    inputString = "";
  }
}
#包括
软件系列hc(2,3);//RX | TX
无效设置()
{
pinMode(4,输出);
数字写入(4,高);
Serial.begin(9600);
Serial.println(“Enter AT commands:”);
hc.begin(38400);//hc-05 AT命令中的默认速度更多
}
void循环()
{
//保持HC-05的读数并发送至Arduino串行监视器
if(hc.available())
Serial.write(hc.read());
//保持Arduino串行监视器的读数并发送至HC-05
if(Serial.available())
hc.write(Serial.read());
}
使用此代码在命令模式下测试蓝牙模块。hc-05中有两种模式。一种是命令模式,另一种是数据模式。 按下蓝牙模块上的按钮几秒钟。然后led缓慢切换,此时模块处于命令模式,您可以在此模式下测试at命令。 注意:以9600波特率打开串行监视器 软件系列hc(2,3);//RX | TX 无效设置() { pinMode(4,输出); 数字写入(4,高); Serial.begin(9600); Serial.println(“Enter AT commands:”); hc.begin(38400);//hc-05 AT命令中的默认速度更多 } void循环() { //保持HC-05的读数并发送至Arduino串行监视器 if(hc.available()) Serial.write(hc.read()); //保持Arduino串行监视器的读数并发送至HC-05 if(Serial.available()) hc.write(Serial.read()); } 使用此代码在命令模式下测试蓝牙模块。hc-05中有两种模式。一种是命令模式,另一种是数据模式。 按下蓝牙模块上的按钮几秒钟。然后led缓慢切换,此时模块处于命令模式,您可以在此模式下测试at命令。 注意:以9600波特率打开串行监视器

我将逐步进行- 连接 Arduino引脚蓝牙引脚

RX(引脚0)--->TX

TX(引脚1)--->RX

5V-->VCC

GND-->GND

将LED负极连接至arduino的GND,正极连接至针脚13,电阻值介于220Ω–1KΩ之间。你的电路也完成了。 注意:不要将蓝牙的RX连接到RX,TX连接到TX,否则不会收到任何数据,此处TX表示发送,RX表示接收

/*
* This program lets you to control a LED on pin 13 of arduino using a bluetooth module
*/
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
   }
}
链接到连接:

注意:上传代码时,从Arduino上拔下蓝牙模块的TX和RX线,上传完成后,将其连接。我将一步一步地进行- 连接 Arduino引脚蓝牙引脚

RX(引脚0)--->TX

TX(引脚1)--->RX

5V-->VCC

GND-->GND

将LED负极连接至arduino的GND,正极连接至针脚13,电阻值介于220Ω–1KΩ之间。你的电路也完成了。 注意:不要将蓝牙的RX连接到RX,TX连接到TX,否则不会收到任何数据,此处TX表示发送,RX表示接收

/*
* This program lets you to control a LED on pin 13 of arduino using a bluetooth module
*/
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
   }
}
链接到连接:

注意:上传代码时,从Arduino上拔下蓝牙模块的TX和RX线,上传完成后,将其连接。