need a code for mpu 6050 gyro module for arduino it needs to read the angle...

Free

60.1K

Verified Solution

Question

Electrical Engineering

need a code for mpu 6050 gyro module for arduino
it needs to read the angle of the pendulum and feed informationback into stepper motor to try to attain balance

Answer & Explanation Solved by verified expert
4.3 Ratings (808 Votes)

Actually this my code..and you need to modify some parts from this code

#include //wire library

#include//i2C Library

#include //mpu6050 library

MPU6050 mpu;

int16_t aa,ab,ac;

int16_t ba,bb,bc;

#define in1 5
#define in2 6

void setup(){
Serial.begin(9600);
Serial.println(\"Initialize MPU\");
mpu.initialize();
//Serial.println(mpu.testConnection() ? \"Connected\" : \"Connection failed\"); pinMode(in1,OUTPUT);
pinMode(in2,OUTPUT);

}

void loop(){
mpu.getMotion6(&aa, &ab, &ac, &ba, &bb, &bc);

aa = map(aa, -17000, 17000, -1500, 1500);

//Serial.println(aa);
if(aa > 0){
if(aa<255){
Serial.println(aa);
analogWrite(in2,aa);
}
else{
Serial.println(\"+255\");
analogWrite(pin2,255);
}

}
if(aa<0){
if(aa>-255){
Serial.println(aa);
analogWrite(in1, aa-aa-aa);
}

.........................................................................................................
else{
Serial.println(\"-255\");
analogWrite(in1, 255);
}
}
delay(1000);
}


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students