Wireless Communication Between Two Arduino Board Using HC-05 Module


In this post I will show you how you can communicate between two Arduino Boards using HC-05 Module. I am using Arduino IDE's version 1.8.7.  There are now newer modules that use a 3.0-20170601 firmware due to which module gives an error, But I will show you how you can fix this error. Just follow the exact same steps listed below and you will not get any error.



Material Required-:

  • PCB Board
  • Arduino Uno x 2
  • Led
  • Bluetooth Module(HC-05) x 2
  • Push Button (Switch)
  • Resistor (1k ohm)
  • Jumper Wire



Connection for AT Mode -:

  • 5V to Arduino 5V
  • GND to Arduino GND
  • TX to Arduino TX(D1)
  • RX to Arduino RX(D0)
  • Enable Pin to 5V

Connections for AT Command Mode



Step-1:

  • Upload Blank code on Arduino Board.


Step-2:

  • While connecting supply to module long press the "Key Button" situated above enable pin.
  • Now, You will see a delay in flashing of HC-05 led, that's means you are successfully entered in AT Command Mode.


Step-3:

  • Now open serial monitor .
  • Remember that HC-05 requires Both "NL and CR" to be set and Baud rate should be on 38400
  • Now type "AT" without qoutes , you should get reply OK,  it means  yor are in AT Command Mode.

 

Step-4:

  • Type "AT+ROLE=0" as it is without quotes, this will set HC-05 on Slave Mode.
  • Now, Type "AT+ADDR?" as it is without quotes, this willl give you Module's address note it down somewhere.
  • This is all you have to do to set HC-05 on Slave Mode.


Step-5:

  • Connect other Module same as previous one.
  • Type "AT" to confirm that you are in AT Command Mode.
  • Now, Type "AT+ROLE=1" without quotes this will set this module to Master Mode.
  • Then, Type "AT+CMODE=0" this will set the connect mode to the fixed address.
  • Then,Type "AT+BIND=your_slave's_address", ( Paste the Slave's address you have noted earlier , Address should be in the pattern of 4,2,6 like this->FCA8,9A,00034)
Note-> If the address is not in 4,2,6 pattern make it by adding zeros in start,  and use commas instead of colan.

Step-6:

  • Now you have successfully set both module.
  • Now detach everything and power both module. They will automatically connect to each other
  • You will see a sync in flashing of led with a delay of 2seconds.
  • Now, it's time to test it.


Connections of Master Module-:

  • 5V to Arduino 5V
  • GND to Arduino GND
  • RX to Arduino TX
  • TX to Arduino RX
  • Button to Digital Pin 2
  • Button to GND

Master Connection



Connection of Slave Module-:

  • 5V to Arduino 5V
  • GND to Arduino GND
  • RX to Arduino TX
  • TX to Arduino RX
  • Led(+ terminal) to Digital Pin 2
  • Led (- terminal) to Arduino GND 

Slave Connection


=== MASTER CODE ===

#define button 2

int value = 0;



void setup() {

  Serial.begin(9600);

  pinMode(button, INPUT_PULLUP);

}


void loop() {

  int val = digitalRead(button);

  if (val == 0 && value == 0)

  {

    Serial.println("1");

    value = 1;

    delay(200);

  }

  else if (val == 0 && value == 1)

  {

    Serial.println("0");

    value = 0;

    delay(200);

  }

  delay(200);

}


=== SLAVE CODE ===



#define led 2


void setup() {

  Serial.begin(9600);

  pinMode(led, OUTPUT);

}


void loop() {

  if (Serial.available())

  {

    char val = Serial.read();

    Serial.println(val);

    if (val == '1')

    {

      digitalWrite(led, HIGH);

    }

    else if (val == '0')

    {

      digitalWrite(led, LOW);

    }

  }

}

 

Note-: 

  • While Uploading the code to Arduino disconnect the RX and TX pin.
  • We can also use "AT+CMODE=1" but this is not recommended because of security reason.

Some AT Commands-:

  • AT+NAME          (Show name of module)
  • AT+PSWD         (Show password of module)
  • AT+UART          (Show default baud rate)
  • AT+VERSION    (Show version of module)






For any queries contact me on  -:  tombriddle28@gmail.com

YouTube Channel-: Omnific{If this post helps you please do subscribe my               
            YouTube channel too ,It's only a click for you but it means a lot to me.}


Comments

Popular posts from this blog

Automatic Water Pumping System

Interfacing "Bluetooth Module" with Arduino Uno