Bluetooth communication between two Arduino boards with hc-05 and hc-06 modules

Hello

I know this topic has been presented like 100 times from before but i’m have problem making the arduino talking to each other

What I’m trying to do is establish a connection between two Arduino by reading multiple sensor data from master and send to slave to able to see it in serial plot.

So far I was able to pair the two module in AT + model and the module are blinking one time every two second.

I try all the different example that was done from before but still without any luck
link that I tried so fat:

http://www.martyncurrey.com/connecting-2-arduinos-by-bluetooth-using-a-hc-05-and-a-hc-06-pair-bind-and-link/
http://forum.hobbycomponents.com/viewtopic.php?f=39&t=1567

what I’m doing right now after pairing the two module is trying this code below

// transmitter
// there's no button, it just sends every 2 secs.
#include<SoftwareSerial.h>
const int rxPin = 10;
const int txPin = 11;
//const int button = 2;

SoftwareSerial mySerial(rxPin,txPin);//RX,TX.

void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop()
{
  mySerial.write("4");
  delay (2000);
}
// receiver
#include<SoftwareSerial.h>
const int rxPin = 10;
const int txPin = 11;
SoftwareSerial mySerial(rxPin,txPin);//RX,TX.
byte packet;

void setup() 
{  
  pinMode(13, OUTPUT);
  Serial.begin(9600);
  mySerial.begin(9600);
}


void loop()
{
  if(mySerial.available != 0)
  {
    int inData = mySerial.read();
    Serial.print("# ");
    Serial.print(packet,DEC);
    Serial,print("  ");
    Serial.println(inData);
    packet ++;
  }
}

but still without any luck.

my module are connected to Arduino’s in this way

Arduino 1:

PIN 10 - TX Bluetooth 1
PIN 11 - RX Bluetooth 1
GND → GND of the other Arduino + Bluetooth 1
5V → VCC Bluetooth 1

Arduino 2:

PIN 10 - TX Bluetooth 2
PIN 11 - RX Bluetooth 2
GND → GND of the other Arduino, Bluetooth 2
5V → VCC Bluetooth 2

I also change the Bluetooth band rate of two module to 9600 in AT+ model but did not get far

Can you please help me !!

You paired the modules, but did you bind and link them aswell?

I’ve done exactly what you’re trying to do and, although it is possible, it is a pain in the neck. I suggest looking at examples from Martyn Currey’s blog. I used one of his examples (unfortunately he leaves out a small detail or two of the process, but we can take care of that later).

This might be one of those times where you think something has happened but it hasn't.

Both modules are set to 9600 by default but, if they answered OK no harm is dome.

AT mode is a a configuration mode. "Pairing" requires communication. You cannot communicate in AT mode

I have never heard of an HC-06 flashing once every two seconds, so I bet yours is not the first. If you really mean twice every one second, that means "power on ready to connect" The HC-06 is in AT mode by default. You will not get any communication until the HC-06 LED is solid, which signifies a connection is made.

much the same applies to HC-05 but it is not in AT mode by default, and the "connected" signal can vary. I have never heard of a "connected" signal like you describe. I again bet that yours is not the first, principally because the intended connection is to the HC-06.

Your code appears to be kosher and, by description, the wiring is OK but it is good practice to use a 1k/2k voltage divider on Arduino Tx. It therefore seems your problems lie with the AT configuration. I suggest you stick with the Martyn Currey stuff. There are two methods there.

Nick_Pyner:
This might be one of those times where you think something has happened but it hasn’t.

Thank very much for the response,

yes it was blinking twice every one second,

I figure out the problem after using this code below, All what i did was swipe the rx to tx and tx to rx. for the receiving and it work

 /// receiving code 

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10,11); // RX, TX

void setup()
{
  mySerial.begin(9600);
  Serial.begin(9600);
}
  int r1,r2,r4,r5;
  byte r3;
void loop() 
{
  while (!mySerial.available());   // stay here so long as COM port is empty
      r1 = mySerial.read();     
      r2 = mySerial.read();     
      r3 = mySerial.read();     
      r4 = mySerial.read();     
      r5 = mySerial.read();     

      mySerial.flush();           //attempting to remove 'random' 255 in Serial Monitor
      Serial.print("tmode\t");
      Serial.print(r1);
      Serial.print("\tDistance\t");
      Serial.print(r2);
      Serial.print("\tSansor\t");
      Serial.print(r3);
      Serial.print("\tMIN\t");
      Serial.print(r4);
      Serial.print("\tTracked\t");
      Serial.println(r5);
      delay (500);
      
}
///transmitting code
#include <SoftwareSerial.h>
#include<AFMotor.h>

SoftwareSerial mySerial(10,11); // RX, TX
AF_DCMotor motor1(3); // Right Motor
AF_DCMotor motor2(4); // Left Motor
const int trigPin = 9;
const int echoPin = 8;
const int sensor_LL = A0;
const int sensor_L = A1;
const int sensor_R = A2;
const int sensor_RR = A3;
int distance;
int Mode = 0;
int minimum = 400;
int left;
int F_left;
int right;
int F_right;
int speedL = 130;
int speedR = 130;
int mstatus = 0;
int target;
int R;
int L;
int RR;
int LL;
int tiempo = 180;
int IR_distance = 210;
byte sensors;


void setup() {

 // put your setup code here, to run once:
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT);  // Sets the echoPin as an Input
Serial.begin(9600);       // Starts the serial communication
mySerial.begin(9600);

}
void loop() {

if (Mode == 0)
{
distance = object_distance(trigPin, echoPin);
right = object_turned(sensor_R);
left = object_turned(sensor_L);
F_right = object_turned(sensor_RR);
F_left = object_turned(sensor_LL);
sensors = scan_sensors(F_left, left, right, F_right);
R = analogRead(sensor_R);
L = analogRead(sensor_L);
RR = analogRead(sensor_RR);
LL = analogRead(sensor_LL);
     mySerial.write(Mode);
     mySerial.write(distance);
     mySerial.write(sensors);
     mySerial.write(minimum);
     mySerial.write(target);
     Serial.print("Mode\t");
     Serial.print(Mode);
     Serial.print("\tDistance\t");
     Serial.print(distance);
     Serial.print("\tF_Left\t");
     Serial.print(F_left);
     Serial.print("\tLL\t");
     Serial.print(LL);
     Serial.print("\tLeft\t");
     Serial.print(left);
     Serial.print("\tL\t");
     Serial.print(L);
     Serial.print("\tRight\t");
     Serial.print(right);
     Serial.print("\tR\t");
     Serial.print(R);
     Serial.print("\tF_Right\t");
     Serial.print(F_right);
     Serial.print("\tRR\t");
     Serial.print(RR);
     Serial.print("\tSensors\t");
     Serial.println(sensors, BIN);
     delay (100);
  if (distance <= 3 && distance != 0)
  
  }
}

But now I’m having different issue which is im not reading different data from the one i sending
I attach picture how the data look

I'm afraid I'm not familair with that stuff, I just send data to the phone. Now that oyu have bluetooth fixed, I suggest you raise this matter in the motor section or robotics.