0

$USD

$USD
PROJECTS Arduino

Controlling of Servo Motor with Arduino and MPU6050

DFRobot Jul 15 2019 2529

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


 

Things used in this project

Hardware components

Arduino UNO & Genuino UNO ×1 
DFRobot 6 DOF Sensor - MPU6050 ×1 
SG90 Micro-servo motor ×1 
 


Software apps and online services

Arduino IDE 

 

Story



Components

  • Arduino UNO
  • MPU6050
  • MG 996R Servo Motor
  • Jumper Wires


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.

 

Schematics

Circuit Digram


 

Code

Code for ProjectC/C++     Click Here to Download

//[email protected] //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); }
 

This article copied from hackster.io, Author: Hammad Iqbal