i have a question about bluetooth module

I would like to send the mapping value of mpu 6050 pitch roll yaw via Bluetooth module (hc-06). Bluetooth is set to master, btSerial speed is set to 115200 (AT+BAUD8). mapping value of pitch roll yaw is also confirmed through serial monitor. However, after inserting this program with the slave device turned off, the light in Bluetooth does not flash and indicates that it has pairing. I don’t even have a Bluetooth connection around master device, so why is that?

And can I send an int value of 0-180 through btSerial.println(); and receive it as an int using int a= btSerial.read();??

#include <Wire.h>
#include <MPU6050.h>
#include <SoftwareSerial.h>
MPU6050 mpu;

SoftwareSerial btSerial(3,2);
// Timers
unsigned long timer = 0;
float timeStep = 0.01;

// Pitch, Roll and Yaw values
float pitch = 0;
float roll = 0;
float yaw = 0;

void setup() 
{
  btSerial.begin(115200);
  Serial.begin(115200);
  // Initialize MPU6050
  while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
  {
    Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
    delay(500);
  }
  
  // Calibrate gyroscope. The calibration must be at rest.
  // If you don't want calibrate, comment this line.
  mpu.calibrateGyro();

  // Set threshold sensivty. Default 3.
  // If you don't want use threshold, comment this line or set 0.
  mpu.setThreshold(3);
}

void loop()
{
  timer = millis();

  // Read normalized values
  Vector norm = mpu.readNormalizeGyro();

  // Calculate Pitch, Roll and Yaw
  pitch = pitch + norm.YAxis * timeStep;
  roll = roll + norm.XAxis * timeStep;
  yaw = yaw + norm.ZAxis * timeStep;

  int pitchmap= map(pitch ,-100,100,0,180);
  int rollmap = map(roll,-100,100,0,180);
  int yawmap = map(yaw, -100,100,0, 180);
  Serial.print(pitchmap);
  Serial.print(rollmap);  
  Serial.println(yawmap);
  // Wait to full timeStep period
  btSerial.println(pitchmap);
  btSerial.println(rollmap);
  btSerial.println(yawmap);
  delay(10);
 
}

Make one test using only the two modules, one master and one slave. No other components. And try sending an int. Tell us what happens.

..Arnav

haeyoungpa:
I would like to send the mapping value of mpu 6050 pitch roll yaw via Bluetooth module (hc-06). Bluetooth is set to master, btSerial speed is set to 115200 (AT+BAUD8). mapping value of pitch roll yaw is also confirmed through serial monitor. However, after inserting this program with the slave device turned off, the light in Bluetooth does not flash and indicates that it has pairing. I don’t even have a Bluetooth connection around master device, so why is that?

And can I send an int value of 0-180 through btSerial.println(); and receive it as an int using int a= btSerial.read();??

Your post is incoherent. Your Bluetooth is not set to master, HC-06 is slave only. You do not say what you are trying to send the data to, presumably it is a master, even though you seem to refer to it as a slave. Whatever might be going on your main problem would seem to be procedural, and knowing what you are holding in your hand. Address the latter first.

You might find the following background notes useful.

When the slave was connected, the pairing was correct, but when the following program was put into the master and slave respectively, the serial monitor was as 48

//master
#include <SoftwareSerial.h>
 
SoftwareSerial bluetooth(3,2);
 
void setup(){
  bluetooth.begin(115200);
}
 
void loop(){
  bluetooth.println(0);
  bluetooth.println(90);
  bluetooth.println(180);
  delay(100);
}
//slave
#include <SoftwareSerial.h>
 
SoftwareSerial bluetooth(3,2);
 
void setup(){
  bluetooth.begin(115200);
  Serial.begin(115200);
}
 
void loop(){
  if(bluetooth.available()){
    int a=bluetooth.read();
    Serial.println(a);
    delay(100);
  }
}

Nick_Pyner:
Your post is incoherent. Your Bluetooth is not set to master, HC-06 is slave only. You do not say what you are trying to send the data to, presumably it is a master, even though you seem to refer to it as a slave. Whatever might be going on your main problem would seem to be procedural, and knowing what you are holding in your hand. Address the latter first.

You might find the following background notes useful.

Dropbox - GUIDE_2BT.pdf - Simplify your life
Dropbox - BT_2_WAY.ino - Simplify your life

i think there was an error in the model name. I checked that AT+ROLE=M was set to be the master and that it was pairing with other Bluetooths, but I don't know what the problem is.

Check an ASCII table...
48 == ‘0’

Hint: Bluetooth.read() reads only a single character and gives you the ASCII code of it.

pcbbc:
Check an ASCII table
48 == ‘0’

Hint: Bluetooth.read() reads only a single character and gives you the ASCII code of it.

but my master code send 0 and 5 and 8. if Bluetooth.read() only a single character and gives you the ASCII code of it, the slave device’s serial monitor shows three numbers. however, the slave device’s serial monitor shows only 48.

haeyoungpa:
but my master code send 0 and 5 and 8. if Bluetooth.read() only a single character and gives you the ASCII code of it, the slave device's serial monitor shows three numbers. however, the slave device's serial monitor shows only 48.

It doesn’t, it sends...

  bluetooth.println(0);
  bluetooth.println(90);
  bluetooth.println(180);
  delay(100);

Unless of course you changed it. But as you do not show new code for what you changed we cannot know that. If you change code, always paste the full new code so we can see it.

But you are saying you get only a single character at the receiver: 48 == ‘0’?
Try changing at least the first value you write to something other than bluetooth.println(0);
Does that change the single character you receive?
Are you sure software serial connection at 115200 baud is practical?
Personally I doubt it.
What Arduino device are you using?
If it has extra hardware serial ports use them.
If not, change the software serial to something slower. 9600 for example.
If you cannot reconfigure the Bluetooth module, used hardware serial for the Bluetooth and software serial at 9600 for the serial monitor window.

haeyoungpa:
i think there was an error in the model name. I checked that AT+ROLE=M was set to be the master and that it was pairing with other Bluetooths, but I don’t know what the problem is.

Being master or slave has nothing to do with pairing. It has everything to do with initialising connection.

As I said before, you really need to know what you are holding in your hand. At the moment, you are just guessing. My guess is that you have no idea, but the Bluetooth is likely to be an HM-10. It may identify itself as HMSoft if you sniff it with the phone.

Don’t expect anything to work with your code as it stands. Software serial will give you grief at 115200, and anything you see on monitor or device is junk, or soon will be. The most you can expect with software serial is 38400 and, needless to say, you need to ensure that Bluetooth is configured to work at that rate.

pcbbc:
software serial at 9600 for the serial monitor window.

Don't do that, not at any baud rate, ever.