我正在做一个项目,我有一个 arduino 记录房间的湿度和温度水平(使用 DHT11 传感器),还有一个通过蓝牙接收这些数据的 arduino。
我正在使用 hm-10 BLE 模块。
到目前为止,数据收集器可以通过 BLE 传输数据,接收器可以从我的手机接收 BLE 数据,但我不知道如何配对这两个模块,以便接收器可以从数据收集器接收数据。
我在网上找到的所有解决方案都涉及使用 AT 指令集,而我使用的是 SoftwareSerial.h 库。
我的数据收集器的代码如下:
//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 指令集,将不胜感激。