我有一个问题,我已经研究了一段时间了。我有一个Arduino Uno板和一个带有TTL输出的HC-05蓝牙收发器。
这些联系如下:
RX (HC_05) --> TX (Arduino UNO)
TX (HC_05) --> RX (Arduino UNO)
GND (HC-05) --> GND (Arduino UNO)
+5V (HC-05) --> +5V (Arduino UNO)我有以下Arduino代码:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX
void setup()
{
Serial.begin(9600);
BTSerial.begin(38400); // HC-05 default speed in AT command more
pinMode(9, OUTPUT); // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
pinMode(10, INPUT);
pinMode(11, OUTPUT);
digitalWrite(9, HIGH);
Serial.println("Enter AT commands:");
BTSerial.println("Welcome to ARBA-Beat");
}
void loop()
{
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTSerial.available()) {
Serial.println(BTSerial.read());
BTSerial.write(BTSerial.read());
BTSerial.flush();
}
}我通过蓝牙终端安卓应用程序连接蓝牙模块。一切正常工作(甚至蓝牙模块上的灯)。但是,当我从电话中发送一个字符到Arduino时,我得到以下输出:
发送到蓝牙模块的文本-一个

请帮帮忙
谢谢
发布于 2017-11-15 23:26:07
我也有过同样的问题。你试过9600运行HC-05吗?尝试下面的代码(用你的引脚)。我用代码来切换插脚2上的继电器,但是如果你想要的话,你可以使用LED。我使用了同样的蓝牙应用程序,效果很好:
#include <SoftwareSerial.h>
int relay = 2; // Set pin for relay control
SoftwareSerial bleserial(8,9);
// setup the relay output and the bluetooth serial, and the serial monitor (if you want to print the outputs)
void setup() {
// set relay pin as output.
pinMode(relay, OUTPUT);
// start bluetooth and serial monitor
bleserial.begin(9600);
Serial.begin(9600);
}
void loop() {
if(bleserial.available()){
char char1 = bleserial.read();
Serial.println(char1);
// Set protocol that you want to turn on the light bulb, I chose 1 and 0 as on and off, respectively
if(char1=='1'){
Serial.println("ON");
digitalWrite(relay,LOW);
} else if (char1=='0'){
digitalWrite(relay,HIGH);
}
}
}如果你想看布线等,请查看我博客上的条目:
https://stackoverflow.com/questions/46481518
复制相似问题