本系统中主要用的是蓝牙配对和 Bluetooth Serial Port 协议。其中配对是两个 Bluetooth 设备间建立新关系的过程。在此过程中,将交换链路密钥(在请求建立连接之前或在连接阶段);而 Bluetooth Serial Port 的主要功能是将 Bluetooth 的通信转化成 Virtual Serial Port (虚拟串口)。
#include "BluetoothSerial.h" BluetoothSerial SerialBT; void setup() { Serial.begin(115200); if(!SerialBT.begin("ESP32")){ Serial.println("An error occurred initializing Bluetooth"); } } void loop() { while(SerialBT.available()){ Serial.write(SerialBT.read()); } delay(50); } Testing...
Serial.begin(9600);//Allow Serial communication via USB cable to computer (if required)pinMode(RxD, INPUT);//Setup the Arduino to receive INPUT from the bluetooth shield on Digital Pin 6pinMode(TxD, OUTPUT);//Setup the Arduino to send data (OUTPUT) to the bluetooth shield on Digital Pin ...
BluetoothSerial SerialBT; Moving on to the setup function, we will start by opening a regular serial connection, to print the results of our program. We are not going to change any actual data over the Bluetooth connection, so all the prints will be done on the wired serial connection. Yo...
1x DF-BluetoothV3蓝牙串口模块 1x USB to Serial 转串口 STEP 2: 切换到AT模式 如下图所示,模块有一个2位拨码开关,1号开关LED Off是LINK灯的开关,可以关闭LINK省电,拨到ON为开,拨到1端为关;2号开关AT Mode是AT命令模式开关,拨到ON进入AT命令模式,拨到2端退出AT命令模式。
}if(Bluetooth=='b') {Serial.println("Turn OFF"); digitalWrite(LedPin,LOW); } } } 手机端设置: APP初始界面: 设置流程: 连接完成后,在命令行进行对应的指令输入,那么就可以发现LED能够根据预设的指令进行变化了。 练习二:蓝牙小车 实现通过手机蓝牙输入指令来控制小车进行对应的运动控制。
Arduino_Learning/BluetoothControlLed 代码语言:javascript 代码运行次数:0 运行 AI代码解释 /* * 通过蓝牙用手机控制 LED,并在 LCD 上显示开关信息 */#include<LiquidCrystal_I2C.h>#include<wire.h>// 设置 LCDLiquidCrystal_I2Clcd(0x27,16,2);// 设置 LED 引脚int led=13;voidsetup(){pinMode(led,OUTPUT...
serialFAN);”向风扇模块的信号引脚写入一个0-255之间的数据,作用是控制输出对应的PWM值,即不同的转速;最后,再添加一个2秒钟的延迟语句:“delay(2000);”,将程序保存为BlueToothFAN(如图6)。同样,程序编译后不要直接上传至Arduino,仍然是将插接在RX和TX引脚的两条杜邦线从Arduino上拔出后再进行上传,上...
不过可以通过Serial Bluetooth Terminal这样一款App进行连接。下载链接。具体操作后面会讲到。 关于该模块的文档可以参考。 一、基本连接 使用模块首先就需要进行简单基本的配置,比如改名字,配置连接的密码;基本的配置就是AT指令,这个就跟HC-05模块类似了。
//HC-05进入设置AT模式#include <SoftwareSerial.h>SoftwareSerial BT(8,9);voidsetup() {//开启电脑通信串口,因为HC-05的波特率为38400,两者通信保持一致Serial.begin(38400); //开启蓝牙,设置波特率38400,进入AT模式BT.begin(38400);//告诉电脑,蓝牙准备好了Serial.println("BT is ready!"); ...