HC05 doesn't work, TX nor RX leds do not flash on both arduinos

Hi! I’m working on an RC car and I bound both of my HC05 and one is master and slave.
This is the code for the Master connected on an Arduino Uno.

int xAxis, yAxis;
int SW_state,SW = 3;
void setup() {
  pinMode(SW,INPUT_PULLUP);
  Serial.begin(38400); // Default communication rate of the Bluetooth module
}
void loop() {
  SW_state = digitalRead(SW);
  xAxis = analogRead(A1); // Read Joysticks X-axis
  yAxis = analogRead(A2); // Read Joysticks Y-axis
  
  // Send the values via the serial port to the slave HC-05 Bluetooth device
  // Dividing by 4 for converting from 0 - 1023 to 0 - 256, (1 byte) range
  Serial.write(xAxis/4);
  delay(10);
  //Serial1.write(yAxis/4);
  //delay(20);
  //Serial1.write(SW_state);
  //delay(10);
}

And this is the code for the Slave which also has an joystick connected to it. *The xb,yb and SWb are data that is supposed to come from the MASTER, the x,y,SW are from the SLAVE device.

#include "DualG2HighPowerMotorShield.h"
DualG2HighPowerMotorShield24v14 md;
int xAxis, yAxis;
int xbAxis, ybAxis;
int SW = 3;
int SW_state = 0;
int SWb_state = 1;
unsigned int  x = 0;
unsigned int  y = 0;
unsigned int  xb = 0;
unsigned int  yb = 0;
int motorSpeedA = 0;
int motorSpeedB = 0;
void setup() {
  
  Serial.begin(38400); // Default communication rate of the Bluetooth module
  pinMode(SW, INPUT_PULLUP); 
  md.init();
  md.calibrateCurrentOffsets();
}
void loop() {
  // Default value - no movement when the Joystick stays in the center
  
  //x = 510;
  //y = 510;
  
  
  // Read the incoming data from the Joystick, or the master Bluetooth device
  while (Serial.available()>= 2) { // 
    xb = Serial.read();
    delay(10);
    //yb = Serial.read();
    //delay(20);
    //SWb_state = Serial.read();
  }
  delay(10);

  x = analogRead(A2);
  delay(10);
  y = analogRead(A3);
  xb = x/4;
  yb = y/4;
  
  
  xbAxis = xb*4;
  ybAxis = yb*4;
  xAxis = x;
  yAxis = y;
  SW_state = digitalRead(SW);

  xAxis = map(xAxis,0, 1024, -400, 400);
  yAxis = map(yAxis,0, 1024, -400, 400);
  xbAxis = map(xAxis,0, 1024, -400, 400);
  ybAxis = map(yAxis,0, 1024, -400, 400);

  Serial.print(xAxis);
  Serial.print("    ");
  Serial.print(yAxis);
  Serial.print("    ");
  Serial.print(SW_state);
  Serial.print("\n");
  //***********************************************************************************
  // FORWARD AND BACK
  //***********************************************************************************
  
  if (yAxis < -40 || ybAxis < -5) {
    md.enableDrivers();
    md.flipM1(true);
    md.flipM2(true);
    motorSpeedA = yAxis;
    motorSpeedB = yAxis;
  }
  else if (yAxis > 40 || ybAxis > 5) {
    md.enableDrivers();
    md.flipM1(true);
    md.flipM2(true);
    motorSpeedA = yAxis;
    motorSpeedB = yAxis;
  }
  // If joystick stays in middle the motors are not moving
  else {
    motorSpeedA = 0;
    motorSpeedB = 0;
    md.disableDrivers();
  }

//***********************************************************************************
// SHARP LEFT AND RIGHT
//***********************************************************************************


  if((xAxis < -100 || xbAxis < -100) && (SW_state == 0 || SWb_state == 0)) {
    md.enableDrivers();
    motorSpeedB = xAxis;
    motorSpeedA = (-1*xAxis);
  }

    if((xAxis > 100 || xbAxis > 100) && (SW_state == 0 || SWb_state == 0)) {
    md.enableDrivers();
    motorSpeedB = xAxis;
    motorSpeedA = (-1*xAxis);
  }
  
  //***********************************************************************************
  // REGUAR LEFT AND RIGHT
  //***********************************************************************************

  if((xAxis < -40 || xAxis < -40) && (SW_state == 1 || SWb_state == 1)) {
    md.enableDrivers();
    motorSpeedA = (-1*xAxis);
  }

    if(xAxis > 40 || xAxis > 40 && (SW_state == 1 || SWb_state == 1)) {
    md.enableDrivers();
    md.flipM2 (true);
    motorSpeedB = xAxis;
  }
  
  

  md.setM1Speed(motorSpeedA); // Send PWM signal to motor A
  md.setM2Speed(motorSpeedB); // Send PWM signal to motor B
}

the RX and TX are not flashing, but the HC05 are paired because their less are blinking in sync.

Probably not true. Bluetooth needs to be specifically configured to 38400. Have you done that? If not, you can simply change this to 9600 on both Arduinos, and then it might work.

38400 is the baud rate for communicating with the HC05 in AT mode.

The default baud rate for HC05 communication is 9600. So to use the HC05 as a master or slave use 9600 unless you have used the AT mode to change the baud rate (on both units).

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.