Download Print this page

Arduino HM-11 User Manual page 4

Bluetooth v4.0 ble module

Advertisement

14) set the master-slave mode
Send: AT + ROLE [para1]
Send after a successful return: OK + Set: [para1]
Example Code
//master
/*
 This example code is in the public domain.
 */
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
void setup()  
{
 // Open serial communications and wait for port to open:
 Serial.begin(9600);
 while (!Serial) {
 ; // wait for serial port to connect. Needed for Leonardo only
 }
 Serial.println("Goodnight moon!");
 // set the data rate for the SoftwareSerial port
 mySerial.begin(9600);
 // set master
 mySerial.print("AT+ROLE1"); 
 delay(10000);
}
void loop() // run over and over
{
   // set the data rate for the SoftwareSerial port
 mySerial.print("test I am master  ");
 delay(10000);  
 if (mySerial.available())
   Serial.write(mySerial.read());
 if (Serial.available())
 mySerial.write(Serial.read());
}
//slave
/*
 This example code is in the public domain.
 */
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
void setup()  
{
 // Open serial communications and wait for port to open:
 Serial.begin(9600);
 while (!Serial) {
 ; // wait for serial port to connect. Needed for Leonardo only
 }
 Serial.println("Goodnight moon!");
 // set the data rate for the SoftwareSerial port
 mySerial.begin(9600);
 // set slave
 mySerial.print("AT+ROLE0"); 
 delay(10000);
}
void loop() // run over and over
{
   // set the data rate for the SoftwareSerial port
 mySerial.print("test I am slave ");
 delay(10000);  
 if (mySerial.available())
 Serial.write(mySerial.read());
 if (Serial.available())
 mySerial.write(Serial.read());
}

Advertisement

loading
Need help?

Need help?

Do you have a question about the HM-11 and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel