Project tutorial
Controlling of Servo Motor with Arduino and MPU6050

Controlling of Servo Motor with Arduino and MPU6050 © GPL3+

In this tutorial we will get data from a MPU6050 Gyroscope and control a Servo motor according to the movement of MPU6050.

  • 14 views
  • 0 comments
  • 1 respect

Components and supplies

Apps and online services

About this project

Components

Connections

Check the attach diagram for connections

Note: You can also connect SDA and SCL pins of MPU6050 to A4 and A5 pin of Arduino respectively.

Programming

Include the attached library in your arduino IDE, then upload the code in your Arduino board.

Note

Check the video for complete understanding and subscribe our channel for more.

Thank You.

Code

MPU6050 LibraryC/C++
No preview (download only).
Code for ProjectC/C++
//hammadiqbal12@gmail.com
//https://www.youtube.com/watch?v=Cvtr3LKdqvk


#include <GY6050.h>           //library for GYRO 
#include <Wire.h>
#include <Servo.h>

Servo myservo;  // create servo object to control a servo


int X = 0;
int Y = 0;
GY6050 gyro(0x68);              //to save GYRO data


void setup() {

  Wire.begin();            //initializing GYRO
  gyro.initialisation();
  delay(100);
  myservo.attach(9);
}

void loop() {
  X = map(gyro.refresh('A', 'X'), -90, 90, 0, 180);                //mapping the gyro data according to angle limitation of servo motor 
  Y = map(gyro.refresh('A', 'Y'), -90, 90, 0, 180);
  myservo.write(Y);                                               //movement of Y axis will control servo
 delay(15);

}

Schematics

Circuit Digram
Servompu dqznm44jks

Comments

Similar projects you might like

All About Servo Motors and Servo Motor Tester

Project tutorial by RoboCircuits

  • 1,434 views
  • 0 comments
  • 7 respects

Obstacles Avoiding Robot With Servo Motor

Project tutorial by Sora JY

  • 9,346 views
  • 3 comments
  • 26 respects

Using Serial Monitor to Control Servo Motor

Project tutorial by Kub_Luk

  • 9,729 views
  • 9 comments
  • 36 respects

DC Motor Controlling Library

Project tutorial by ambhatt

  • 8,745 views
  • 12 comments
  • 39 respects

Unipolar Stepper Motor Controlling Library

Project tutorial by ambhatt

  • 2,635 views
  • 4 comments
  • 6 respects

Servo Motor Using Arduino & PCA9685 16 Chanel Module

Project tutorial by Jithin Sanal

  • 36,589 views
  • 2 comments
  • 18 respects
Add projectSign up / Login