-2

I am working on a project whereby I have an arduino recording the humidity and temperature levels of a room (using a DHT11 sensor), and a second arduino that recieve this data via bluetooth.

I am using the hm-10 BLE modules.

So far the data-collector can transmit data over BLE, and the reciever can recieve BLE data from my phone, but I can't figure out how to pair the two modules so that the receiver can receive data from the data-collector.

All of the solutions I have found online involve using the AT instruction set, whereas I am using the SoftwareSerial.h library.

The code for my data gatherer is as follows:

//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()

Any ideas on how I can connect it with another hm10 module so they can exchange information without having to re-write everything to the AT instruction set would be greatly appreciated.

too honest for this site
  • 12,050
  • 4
  • 30
  • 52

1 Answers1

-1

You need to learn AT commands to configure the HM-10 in master or slave mode, all these can still be done using the SoftSerial library, get the HM-10 datasheet for AT commands and check these site for help.

http://www.instructables.com/id/How-to-Use-Bluetooth-40-HM10/

https://www.hackster.io/achindra/bluetooth-le-using-cc-41a-hm-10-clone-d8708e

See sample code below:

#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());
}