以下代码可以使用IDE自带的串口工具单个命令配置
使用Uno和HC-05实验
#include<SoftwareSerial.h>
SoftwareSerialbluetooth(12, 13); //RX,TX
String at ="";
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while (!Serial) {
;
}
Serial.println("Goodnight moon!");
bluetooth.begin(38400);
bluetooth.println("Hello, world?");
}
void loop() {
// put your main code here, to runrepeatedly:
if (bluetooth.available())
Serial.write(bluetooth.read());
while (Serial.available() > 0)
{
at += char(Serial.read());
delay(2);
}
if (at.length() > 0)
{
bluetooth.println( at);
at = "";
}
}
Arduino蓝牙串口通信
本文介绍了一个使用Arduino Uno和HC-05模块实现串口通信的例子。通过该示例,可以学习如何设置软件串口,并实现Arduino与蓝牙设备之间的双向数据传输。
6万+

被折叠的 条评论
为什么被折叠?



