使用hm-10 BLE在arduino之间传输数据
我正在进行一个项目,其中我有一个arduino使用DHT11传感器记录房间的湿度和温度水平,还有一个arduino通过蓝牙接收数据 我正在使用hm-10 BLE模块 到目前为止,数据采集器可以通过BLE传输数据,接收器可以从我的手机接收数据,但我不知道如何将这两个模块配对,以便接收器可以从数据采集器接收数据 我在网上找到的所有解决方案都涉及使用AT指令集,而我使用的是SoftwareSerial.h库 我的data gatherer的代码如下所示:使用hm-10 BLE在arduino之间传输数据,arduino,bluetooth-lowenergy,at-command,hm-10,Arduino,Bluetooth Lowenergy,At Command,Hm 10,我正在进行一个项目,其中我有一个arduino使用DHT11传感器记录房间的湿度和温度水平,还有一个arduino通过蓝牙接收数据 我正在使用hm-10 BLE模块 到目前为止,数据采集器可以通过BLE传输数据,接收器可以从我的手机接收数据,但我不知道如何将这两个模块配对,以便接收器可以从数据采集器接收数据 我在网上找到的所有解决方案都涉及使用AT指令集,而我使用的是SoftwareSerial.h库 我的data gatherer的代码如下所示: //Include the DHT (humi
//Include the DHT (humidity and temperature sensor) library, and the serial library
#include <dht.h>
#include <SoftwareSerial.h>
//Define the constants for the input (DHT11) and output pins
#define RXpin 7
#define TXpin 8
#define DHT11_PIN 9
//Initialise a Serial channel as softSerial
SoftwareSerial softSerial(RXpin, TXpin);
//Initialise DHT object
dht DHT;
//Set initial measurement to be temperature (not humidity)
bool humidity = false;
void setup() {
//Start the serial function
Serial.begin(9600);
//Start the softSerial channel
softSerial.begin(9600);
}//void setup()
void loop() {
//Reset the reading variable
float(reading);
//Take in the values recorded by the DHT11
int chk = DHT.read11(DHT11_PIN);
//Store the necessary measurement in the reading variable
if (!humidity) {
reading = DHT.temperature;
} else {
reading = DHT.humidity;
}
//Output the reading on the softSerial channel
softSerial.print(reading);
//The DHT11 can only take one measurement per second, so waiting two seconds ensures there will be no null readings
delay(2000);
//Swap current measurement
humidity = !humidity;
}//void loop()
如果您有任何关于如何将其与另一个hm10模块连接以使其能够在不必将所有内容重新写入AT指令集的情况下交换信息的想法,我们将不胜感激。您需要学习AT命令,以便在主模式或从模式下配置HM-10,所有这些仍然可以使用SoftSerial库完成,获取AT命令的HM-10数据表,并查看这些站点以获取帮助 请参见下面的示例代码:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(4, 5);
void setup() {
Serial.begin(9600);
BTSerial.begin(9600);
BTSerial.write("AT+DEFAULT\r\n");
BTSerial.write("AT+RESET\r\n");
BTSerial.write("AT+NAME=Controller\r\n");
BTSerial.write("AT+ROLE1\r\n");
BTSerial.write("AT+TYPE1"); //Simple pairing
}
void loop()
{
if (BTSerial.available())
Serial.write(BTSerial.read());
if (Serial.available())
BTSerial.write(Serial.read());
}