Here is, I am sharing the Arduino code for 2 diffrent DC motor control with MPU-6050 and Arduino UNO with adafruid motor driver shield.
I am using:
- Two DC motors
- L329 Motor Driver Shield
- Arduino UNO
- Gy-521 (MPU-6050)
Video Demo MPU 6050 with Motors
Arduino Code MPU 6050
#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>
#include <AFMotor.h>
AF_DCMotor motor1(1, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
AF_DCMotor motor2(2, MOTOR12_64KHZ);
MPU6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy, gz;
int valMotor1;
int valMotor2;
void setup()
{
Wire.begin();
Serial.begin(9600);
Serial.println("Initialize MPU");
mpu.initialize();
Serial.println(mpu.testConnection() ? "Connected" : "Connection failed");
motor1.setSpeed(100); // set the speed to 200/255
motor2.setSpeed(100);
}
void loop()
{
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
ax = map(ax, -17000, 17000, -125, 125);
valMotor1 = 125+ax;
valMotor2 = 125-ax;
Serial.println(valMotor1, DEC);
Serial.println(valMotor2, DEC);
if(valMotor1 > 0 && valMotor1 < 255){
motor1.setSpeed(valMotor1);
}
if(valMotor2 > 0 && valMotor2 < 255){
motor2.setSpeed(valMotor2);
}
motor1.run(FORWARD); // turn it on going forward
motor2.run(BACKWARD);
delay(200);
}
Dear Circuit Magic,
please write to me how(or where can i find) can i get these libraries to i can use this code? Links are enough to me!
I2Cdev.h
MPU6050.h
AFMotor.h
Your code is very helpful, cos i’m rookie. Thanks the answer!
See ya!
Tem como associar isso aos motores de drone como os motores brushless rctimer
Hello,
Thanks for sharing you work. I am learning how to use the MPU 6050 myselfe and your codes are wonderful.
My question is, Are you using the DMP to get both the combined values to controll the motors?
And can you send me the “#include ” file via email? Have you tried making a balance robot?
Thank you.
AFMotor.h file can you Email it to me please.
How did you put the GY-521 GYRO / ACCELEROMETER MODULE (MPU-6050) AND DRIVER L329D ARDUINO SHIELD you have the design scheme for your site appears only the code
hello,
can you combine that with 4 motors ?
hey dude, can you share the schematic for connection MPU6050? please update this thread.. thanks
how to read the sensor? I can’t find the code to read pin A4 and A5 connected with MPU 6050. Pls, explain your code to me, fri. Give me the light for my stupid brain…. 🙁
Hi, i´m make the self balanced robot for the college project and i´m using your article as guide line, can you send me the circuit diagram for two dc motors and the adafruit shield..i already test the another one and work fine.
can you send schematic about this to me please
i need schematics
pleas send in my email
poudelmanish321@gmail,com
Impressive project man.
Excuse me, what is the Diagram Circuit?
Amigo no podrias ayudarme con el codigo para lenguaje ada
How does this “ax = map(ax, -17000, 17000, -125, 125);” map works?
I do not understand why some people say something in the details and don’t do it. Here you have not shown the schematic drawing, for which everybody is asking for!