Arduino Wireless Communication

Introduction

Arduino Wireless communication
This post talks about how to implement an Arduino wireless communication system using two HC-05 modules. These modules were introduced in Arduino Bluetooth Interface and they can be configured as Masters or Slave. Methods of configuring the HC-05 modules are also provided in the original HC-05 post.

To achieve a wireless communication bridge between two Arduino, we of-course need 2 Arduino and two HC-05 modules, one configured as a master and one configured as a slave.

The aim is to send a series of text wirelessly from one Arduino to a second remote Arduino and display the text on an LCD connected to the remote Arduino.

Configuring the HC-05 modules

The wiring to Arduino for AT configuration mode is shown below:

HC-05 Connections
Figure1: HC-05 Connections

The HC-05 is in slave mode by default but to make sure that it is in Slave mode, the HC-05 module has to be put in command mode by holding down the key switch while powering the module and with the Arduino running the simple serial code shown in Arduino Bluetooth Interface.

To check whether the module is in slave or master, type the following command in your favourite serial console:

AT+ROLE?

If the answers is 0; then the HC-05 is in slave mode.

To set the HC-05 to Master mode, type:

AT+ROLE=1

To establish an automatic connection to a slave module, the master module must know the slave address. This is configured with the AT+BIND command with CMODE=0 (Use a predefined address). With CMODE=1, it is less secure as the master can connect to any device in its transmission range.

To get the address of the slave:

AT+ADDR?

In our case, we got this as a reply:

+ADDR:2015:12:293902

On the master, type:

AT+BIND=2015,12,293902

This will make sure that the master HC-05 pairs with the slave automatic when they are both powered on.

Arduino Connections

The connections for the master Arduino is as shown in Figure 1 above. The connections for the slave arduino is shown in Figure 2 below.

Arduino HC-05 LCD connections
Figure 2: Arduino Slave Connections

Master Arduino code

/*Author: BehindTheSciences.com */
#include <SoftwareSerial.h>// import the serial library
 
SoftwareSerial ser(10, 11); // RX, TX

void setup() {
  ser.begin(9600);
   } 
void loop() {
  // put your main code here, to run repeatedly:
ser.write("HELLO\n");
delay(1000);
ser.write("BehindTheSciences\n");
delay(1000);
ser.write("Bluetooth\n");
delay(1000);
ser.write("Tutorial\n");
delay(1000);
}

For the Arduino master code, we send a couple of phrases which ends with a new line (‘\n’). We used a delay of one second between each transmission.

Arduino Slave code

For the Arduino code for the slave, we first configure the LCD. The data received from the bluetooth is then read and then displayed on the LCD. The code for the slave can be found here: ArduinoCommsSlave

Demonstration of the Arduino to Arduino communication

After uploading the codes to the Master and Slave Arduinos respectively, we see the stream of phrases from the Master being displayed on the Slave Arduino’s LCD. A video demonstration is shown below:

Add a Comment

Your email address will not be published. Required fields are marked *

Show Buttons
Hide Buttons