Hammad Iqbal
Published © GPL3+

Controlling of Servo Motor with Arduino and MPU6050

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

IntermediateFull instructions provided1 hour25,828
Controlling of Servo Motor with Arduino and MPU6050

Things used in this project

Story

Read more

Schematics

Circuit Digram

Code

MPU6050 Library

C/C++
No preview (download only).

Code for Project

C/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);

}

Credits

Hammad Iqbal

Hammad Iqbal

6 projects • 42 followers
I'm an Electrical Engineer and here I'm to share my knowledge about Embedded system.

Comments