How to use RN42 Bluetooth module and MPU-6050 simultaneously?

Hello everyone in Arduino community. I have a question about using two modules with Arduino UNO at the same time.

I’m now trying to measure the tilt angle of the head by MPU-6050 sensor and move the cursor on the monitor according to its angle. The HID protocol of RN42 BT module is used to move the cursor.

I checked each module separetaly. In other words I confirmed MPU-6050 correctly works when I only connected it to Arduino. Also RN42 correctly works in HID mode when I connected it without MPU-6050. The problem is when I connnect those two modules at the same time, I does not work. Does anyone have a solution for that? Any help would be appreciated!

Here’s a detailed description of what I have now:

MPU-6050 — Arduino UNO
VCC — 3.3V

RN42 — Arduino UNO
3.3V — 3.3V
CTS -|
RTS -|

The below code is what I am trying to run:

#include <SoftwareSerial.h>
#include <Wire.h>

#define RAD_TO_DEG 180/PI
#define DEG_TO_RAD PI/180

#define tx 1
#define rx 0

#define LED 13

int xRaw, yRaw, zRaw;
int xAcc, yAcc, zAcc;
int roll, pitch;

SoftwareSerial btSerial(rx, tx);

void setup() {



  pinMode(LED, OUTPUT);
  digitalWrite(LED, HIGH);
  digitalWrite(LED, LOW);

void loop() {
  // put your main code here, to run repeatedly:
  Wire.requestFrom(0x68, 14);

  digitalWrite(LED, HIGH);
  while (Wire.available() < 14);
  digitalWrite(LED, LOW);

  xRaw = << 8 |;
  yRaw = << 8 |;
  zRaw = << 8 |;

  roll = atan2(yRaw, xRaw) * RAD_TO_DEG;
  pitch = atan2(zRaw, xRaw) * RAD_TO_DEG;

  int xMove = convertToRange(roll);
  int yMove = convertToRange(pitch);
  btSerial.write((byte)xMove);  // the displacement of the cursor along the x-axis
  btSerial.write((byte)yMove);  // the displacement of the cursor along the y-axis


int convertToRange(int angle) {
  int res;
  if (0 <= angle && angle <= 40) {
    res = (angle/40) * 127;
  else if (-40 <= angle && angle < 0) {
    res = 255 - (angle/40) * 127;
  else {
    res = 0;
  return res;

Please tell us what "it does not work" means.

What did you expect to happen, and what happened instead? Post examples of output.