I want to share With you Solved Problem of Failed to find MPU6050 chip If use Boards ESP32 , Arduino
My board am test on it is (ESP32 S3 Chines Version) , (Arduino Mega)
Library test on it: Adafruit_MPU6050
am find in a lot of forms miss under standing of hardware id ,device id
your sensor has two key values:
I2C Bus Address: The address the microcontroller uses to find the sensor on the wire. Your I2C scanner confirms this is 0x68. or other number
WHO_AM_I Device ID: A unique ID stored inside the sensor itself. Example of Your sensor's ID is 0x70 ,0x71,etc .
///////////////////////////////////////////////////////////////////////////////////////////
ESP32 S3 ,Arduino Examples of I2C Bus Address , WHO_AM_IDevice ID:
////////////////////////////////////////////////////////////////////////////////////////////
Important thing : if we Dont use standard pin of sda,scl in your board
like standard pin of some board
![]()
Arduino
-
Arduino Uno, Nano, Pro Mini: A4 (SDA), A5 (SCL)
-
Arduino Mega: Digital Pin 20 (SDA), Digital Pin 21 (SCL)
-
Arduino Leonardo, Micro: Digital Pin 2 (SDA), Digital Pin 3 (SCL)
-
Arduino Due, Uno WiFi Rev2, Zero: Digital Pin 20 (SDA), Digital Pin 21 (SCL)
ESP32
The ESP32 is more flexible, allowing you to define the I2C pins in your code. However, there are common default pins.
-
Default ESP32 Pins: GPIO 21 (SDA), GPIO 22 (SCL)
-
Custom Pins: You can use a different pair of pins by calling
Wire.begin(SDA_PIN, SCL_PIN);in your Arduino IDE sketch.
Raspberry Pi
Raspberry Pi boards have a dedicated I2C bus on the GPIO header.
- Standard I2C Bus: GPIO 2 (SDA), GPIO 3 (SCL)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Lets go to use other pin ![]()
For ESP Wire.begin.
Define pin number like this ![]()
#define SDA 5 //change to pin want to use
#define SCL 4 //change to pin want to use
//Give name to pin you prefer
Wire.begin(SDA, SCL);
first section put sda pin, second section scl pin
this line must put it like this Wire.begin(SDA, SCL); if use esp and dont have standard pin 20 ,21 for scl ,sda and want use other pin is GPIO you prefer and you see is safe
am choose to use pin sda to pin 5 , scl to pin 4
why said this you see is safe
See this video: https://youtu.be/LY-1DHTxRAk?si=SEhzXTnN9Wjvlukz
if want use default pin write like this Wire.begin();
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
For Arduino Wire.begin
only write like this Wire.begin();
when dont write any pin number inside wire.begin by default use default pins
this code am test it to get I2c Bus Address
#include <Wire.h>
// Define custom I2C pins
#define SDA 5
#define SCL 4
void setup() {
Serial.begin(115200);
Wire.begin(I2C_SDA, I2C_SCL);//Change to empty if use default pin
// Give the I2C bus a moment to initialize
delay(1000);
Serial.println("\nI2C Scanner");
}
void loop() {
Serial.println("Scanning...");
byte error, address;
int nDevices = 0;
for(address = 1; address < 127; address++ ) {
// We will use the return value of the endTransmission to see if it's there
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address < 16) {
Serial.print("0");
}
Serial.print(address, HEX);
Serial.println(" !");
nDevices++;
} else if (error == 4) {
Serial.print("Unknown error at address 0x");
if (address < 16) {
Serial.print("0");
}
Serial.println(address, HEX);
}
}
if (nDevices == 0) {
Serial.println("No I2C devices found\n");
} else {
Serial.println("done\n");
}
// Wait 5 seconds for next scan
delay(5000);
}
This code will get output in serial thing like this
Scanning...
I2C device found at address 0x68 !
done
The number( 0x68
or number you get it) will help you in code ino file basic_reading of library Adafruit_MPU6050 or other library you prefer
this code am test it to get WHO_AM_IDevice ID:
#include <Wire.h>
// Define custom I2C pins for ESP32
#define I2C_SDA 5
#define I2C_SCL 4
// The I2C address of the MPU6050, confirmed by your scanner
const int MPU6050_I2C_ADDRESS = 0x68;
// The register address for the 'WHO AM I' ID
const int MPU6050_WHO_AM_I_REGISTER = 0x75;
void setup() {
Serial.begin(115200);
Wire.begin(I2C_SDA, I2C_SCL);//Change to empty if use default pin
delay(1000);
Serial.println("Reading MPU6050 WHO_AM_I register...");
byte deviceId = 0;
// Begin communication with the MPU6050 at its I2C address
Wire.beginTransmission(MPU6050_I2C_ADDRESS);
// Tell it which register we want to read from
Wire.write(MPU6050_WHO_AM_I_REGISTER);
// End transmission
Wire.endTransmission(false); // 'false' keeps the I2C bus from releasing
// Request 1 byte of data from the MPU6050
Wire.requestFrom(MPU6050_I2C_ADDRESS, 1, true);
if (Wire.available()) {
deviceId = Wire.read(); // Read the byte from the register
} else {
Serial.println("Error: Could not read from sensor.");
}
Serial.print("Device WHO_AM_I value is: 0x");
if (deviceId < 0x10) {
Serial.print("0");
}
Serial.println(deviceId, HEX);
}
void loop() {
// Nothing to do in the loop for this example
}
This code will get output in serial thing like this
Reading MPU6050 WHO_AM_I register...
Device WHO_AM_I value is: 0x70
The number( 0x70
or number you get it) will help you in code run ino file basic_reading of library Adafruit_MPU6050 or other library you prefer
Save the 2 number you get it (I2C Bus Address , WHO_AM_IDevice ID:)
Go to folder it contain library you used in my situation am find on it this
C:\Users\Your_Username\Documents\Arduino\libraries\Adafruit_MPU6050
you can find most time in this destination or other destination can get help by an Ai chat bot
Choose file Adafruit_MPU6050 has type C Header Source File
Hint: You can open file by thing like visual studio code like in photo or by notepad only need to change device id
Change number you get in example device id and write it under red line you find number Hex is 0x68 is default change it to your device id
Press Ctrl+S to save and close file
We have reached the decisive moment
![]()
basic_reading ino file from Adafruit
// Basic demo for accelerometer readings from Adafruit MPU6050
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
#define SDA 5
#define SCL 4
Adafruit_MPU6050 mpu;
void setup(void) {
Serial.begin(115200);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Adafruit MPU6050 test!");
Wire.begin(SDA, SCL);//Change to empty if use default pin
// Try to initialize!
if (!mpu.begin(0x68)) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
Serial.println("MPU6050 Found!");
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
Serial.print("Accelerometer range set to: ");
switch (mpu.getAccelerometerRange()) {
case MPU6050_RANGE_2_G:
Serial.println("+-2G");
break;
case MPU6050_RANGE_4_G:
Serial.println("+-4G");
break;
case MPU6050_RANGE_8_G:
Serial.println("+-8G");
break;
case MPU6050_RANGE_16_G:
Serial.println("+-16G");
break;
}
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
Serial.print("Gyro range set to: ");
switch (mpu.getGyroRange()) {
case MPU6050_RANGE_250_DEG:
Serial.println("+- 250 deg/s");
break;
case MPU6050_RANGE_500_DEG:
Serial.println("+- 500 deg/s");
break;
case MPU6050_RANGE_1000_DEG:
Serial.println("+- 1000 deg/s");
break;
case MPU6050_RANGE_2000_DEG:
Serial.println("+- 2000 deg/s");
break;
}
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
Serial.print("Filter bandwidth set to: ");
switch (mpu.getFilterBandwidth()) {
case MPU6050_BAND_260_HZ:
Serial.println("260 Hz");
break;
case MPU6050_BAND_184_HZ:
Serial.println("184 Hz");
break;
case MPU6050_BAND_94_HZ:
Serial.println("94 Hz");
break;
case MPU6050_BAND_44_HZ:
Serial.println("44 Hz");
break;
case MPU6050_BAND_21_HZ:
Serial.println("21 Hz");
break;
case MPU6050_BAND_10_HZ:
Serial.println("10 Hz");
break;
case MPU6050_BAND_5_HZ:
Serial.println("5 Hz");
break;
}
Serial.println("");
delay(100);
}
void loop() {
/* Get new sensor events with the readings */
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
/* Print out the values */
Serial.print("Acceleration X: ");
Serial.print(a.acceleration.x);
Serial.print(", Y: ");
Serial.print(a.acceleration.y);
Serial.print(", Z: ");
Serial.print(a.acceleration.z);
Serial.println(" m/s^2");
Serial.print("Rotation X: ");
Serial.print(g.gyro.x);
Serial.print(", Y: ");
Serial.print(g.gyro.y);
Serial.print(", Z: ");
Serial.print(g.gyro.z);
Serial.println(" rad/s");
Serial.print("Temperature: ");
Serial.print(temp.temperature);
Serial.println(" degC");
Serial.println("");
delay(500);
}
// Try to initialize!
if (!mpu.begin(0x68)) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
in section if (!mpu.begin(0x68) inside mpu.begin put number you get I2C Bus Address
after this all steps run upper code of basic reading after do modifcaion in file Adafruit_mpu and in ino code
Good Luck ![]()
