以下代码可以使用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 = "";
}
}