Sensors

Enter Your Electronics & Design Project for a chance to win a $200 shopping cart!

Submit an EntrySubmit an Entry  Back to homepage
Project14 Home
Monthly Themes
Monthly Theme Poll

 

       
                                                                                       
                                                                                            Motion Control Gimbal
                                                                                    

Hello Everyone,My name is Harji Nagi.I am currently a third year student studying electronics and communication engineering from Pranveer Singh Institute Of Technology,Kanpur(UP).I have a keen interest in robotics,arduino,Artificial Intelligence and Analog electronics.The word “gimbal” is defined as a pivoted support that allows rotation of any object in a single axis. So a three-axis gimbal allows any object mounted on the gimbal to be independent of the movement of the one holding the gimbal. The gimbal dictates the movement of the object, not the one carrying it.It consists of 3 MG995 servo motors for the 3-axis control, and a base on which the MPU6050 sensor, the Arduino and the battery will be placed.It’s used to keep the camera stabilized with no vibration. A 3-axis gimbal ensures that the motion of the camera is stabilized even if the one holding it is going up and down, left and right, front and back. This is what we refer to as yaw, pitch, and roll stabilization.

Step 1: Components List

The component list are:

1)Arduino Uno

2)8V,1.5 Amp Battery for powering Arduino Uno

3) 7805 Voltage regulator Ic or you can use buck conveter

4)MPU 6050

5)3*(MG995 SERVO Motors)

6)Jumper Wires

Other Equipments:

1)Soldering Iron

2)Glue Gun

3)Drill machine

4)Food Can

Instead of using breadborad I have use small coustom perf board for positive and negative bus connection.

Step 2: Assembling

 

AssemblingAssemblingAssembling

Foamcore, foam board, or paper-faced foam board is a lightweight and easily cut material used for mounting Servo motor and for making scale models.

Firstly I made a DIY L-shape brackets to mount servo motor with the help of foam board.

Step 3:

 

                                                                   

 

Assembling the gimbal was quite easy. I started with installing the Yaw servo,MPU 6050 sensor and ON-OFF switch. Using bolts and nuts I secured it to the base

Step 4: Next, Using the Same Method I Secured the Roll Servo. the Parts Are Specifically Designed to Easily Fit the MG995 Servos

 

Next, Using the Same Method I Secured the Roll Servo. the Parts Are Specifically Designed to Easily Fit the MG995 Servos

Step 5: Next, Using the Same Method I Secured the Roll Servo. the Parts Are Specifically Designed to Easily Fit the MG995 Servos

Next, Using the Same Method I Secured the Roll Servo. the Parts Are Specifically Designed to Easily Fit the MG995 Servos

Step 6: Connections

Connections

In the circuit diagram you can use either buck converter or 7805 Voltage regulator IC to convert 8V to 5 V.The microcontroller which is given the circuit diagram is Arduino Nano you can also use Arduino Uno,Arduino Mega.

The SCL and SDA pins of MPU 6050 is connected to Arduino Analog pin A5 and A4.(SCL and SDA pin may vary so check out datasheet for SCl and SDA pins for other microcontroller)

Step 7: Connection With 7805 Voltage Regulator IC

 

Connection With 7805 Voltage Regulator IC

This circuit diagram is for the connection of 7805 voltage regulator ic, connect the 8v battery at Vin and you will get an output voltage of 5v.

Step 8: Coding

You must include the following libraries:

1)#include<Wire.h>Click Hereto download zip file

2)#include<Servo.h>Click Here to download zip file

After downloading the zip file,add zip library in arduino sketch

For Code

  1. /*
  2.   DIY Gimbal - MPU6050 Arduino Tutorial
  3.   Code based on the MPU6050_DMP6 example from the i2cdevlib library by Jeff Rowberg:
  4.   https://github.com/jrowberg/i2cdevlib
  5. */ 
  6. // I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files 
  7. // for both classes must be in the include path of your project 
  8. #include "I2Cdev.h" 
  9.  
  10. #include "MPU6050_6Axis_MotionApps20.h" 
  11. //#include "MPU6050.h" // not necessary if using MotionApps include file 
  12.  
  13. // Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation 
  14. // is used in I2Cdev.h 
  15. #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE 
  16. #include "Wire.h" 
  17. #endif 
  18. #include <Servo.h> 
  19. // class default I2C address is 0x68 
  20. // specific I2C addresses may be passed as a parameter here 
  21. // AD0 low = 0x68 (default for SparkFun breakout and InvenSense evaluation board) 
  22. // AD0 high = 0x69 
  23. MPU6050 mpu; 
  24. //MPU6050 mpu(0x69); // <-- use for AD0 high 
  25.  
  26. // Define the 3 servo motors 
  27. Servo servo0; 
  28. Servo servo1; 
  29. Servo servo2; 
  30. float correct; 
  31. int j = 0
  32.  
  33. #define OUTPUT_READABLE_YAWPITCHROLL 
  34.  
  35. #define INTERRUPT_PIN 2 // use pin 2 on Arduino Uno & most boards 
  36.  
  37. bool blinkState = false
  38.  
  39. // MPU control/status vars 
  40. bool dmpReady = false; // set true if DMP init was successful 
  41. uint8_t mpuIntStatus; // holds actual interrupt status byte from MPU 
  42. uint8_t devStatus; // return status after each device operation (0 = success, !0 = error) 
  43. uint16_t packetSize; // expected DMP packet size (default is 42 bytes) 
  44. uint16_t fifoCount; // count of all bytes currently in FIFO 
  45. uint8_t fifoBuffer[64]; // FIFO storage buffer 
  46.  
  47. // orientation/motion vars 
  48. Quaternion q; // [w, x, y, z] quaternion container 
  49. VectorInt16 aa; // [x, y, z] accel sensor measurements 
  50. VectorInt16 aaReal; // [x, y, z] gravity-free accel sensor measurements 
  51. VectorInt16 aaWorld; // [x, y, z] world-frame accel sensor measurements 
  52. VectorFloat gravity; // [x, y, z] gravity vector 
  53. float euler[3]; // [psi, theta, phi] Euler angle container 
  54. float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector 
  55.  
  56. // packet structure for InvenSense teapot demo 
  57. uint8_t teapotPacket[14] = { '$', 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0x00, 0x00, '\r', '\n' }; 
  58.  
  59.  
  60.  
  61. // ================================================================ 
  62. // === INTERRUPT DETECTION ROUTINE === 
  63. // ================================================================ 
  64.  
  65. volatile bool mpuInterrupt = false; // indicates whether MPU interrupt pin has gone high 
  66. void dmpDataReady() { 
  67.   mpuInterrupt = true
  68.  
  69. // ================================================================ 
  70. // === INITIAL SETUP === 
  71. // ================================================================ 
  72.  
  73. void setup() { 
  74.   // join I2C bus (I2Cdev library doesn't do this automatically) 
  75. #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE 
  76.   Wire.begin(); 
  77.   Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having compilation difficulties 
  78. #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE 
  79.   Fastwire::setup(400, true); 
  80. #endif 
  81.  
  82.   // initialize serial communication 
  83.   // (115200 chosen because it is required for Teapot Demo output, but it's 
  84.   // really up to you depending on your project) 
  85.   Serial.begin(38400); 
  86.   while (!Serial); // wait for Leonardo enumeration, others continue immediately 
  87.  
  88.   // initialize device 
  89.   //Serial.println(F("Initializing I2C devices...")); 
  90.   mpu.initialize(); 
  91.   pinMode(INTERRUPT_PIN, INPUT); 
  92.   devStatus = mpu.dmpInitialize(); 
  93.   // supply your own gyro offsets here, scaled for min sensitivity 
  94.   mpu.setXGyroOffset(17); 
  95.   mpu.setYGyroOffset(-69); 
  96.   mpu.setZGyroOffset(27); 
  97.   mpu.setZAccelOffset(1551); // 1688 factory default for my test chip 
  98.  
  99.   // make sure it worked (returns 0 if so) 
  100.   if (devStatus == 0) { 
  101.   // turn on the DMP, now that it's ready 
  102.   // Serial.println(F("Enabling DMP...")); 
  103.   mpu.setDMPEnabled(true); 
  104.  
  105.   attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), dmpDataReady, RISING); 
  106.   mpuIntStatus = mpu.getIntStatus(); 
  107.  
  108.   // set our DMP Ready flag so the main loop() function knows it's okay to use it 
  109.   //Serial.println(F("DMP ready! Waiting for first interrupt...")); 
  110.   dmpReady = true
  111.  
  112.   // get expected DMP packet size for later comparison 
  113.   packetSize = mpu.dmpGetFIFOPacketSize(); 
  114.   } else
  115.   // ERROR! 
  116.   // 1 = initial memory load failed 
  117.   // 2 = DMP configuration updates failed 
  118.   // (if it's going to break, usually the code will be 1) 
  119.   // Serial.print(F("DMP Initialization failed (code ")); 
  120.   //Serial.print(devStatus); 
  121.   //Serial.println(F(")")); 
  122.   } 
  123.  
  124.   // Define the pins to which the 3 servo motors are connected 
  125.   servo0.attach(10); 
  126.   servo1.attach(9); 
  127.   servo2.attach(8); 
  128. // ================================================================ 
  129. // === MAIN PROGRAM LOOP === 
  130. // ================================================================ 
  131.  
  132. void loop() { 
  133.   // if programming failed, don't try to do anything 
  134.   if (!dmpReady) return
  135.  
  136.   // wait for MPU interrupt or extra packet(s) available 
  137.   while (!mpuInterrupt && fifoCount < packetSize) { 
  138.   if (mpuInterrupt && fifoCount < packetSize) { 
  139.   // try to get out of the infinite loop 
  140.   fifoCount = mpu.getFIFOCount(); 
  141.   } 
  142.   } 
  143.  
  144.   // reset interrupt flag and get INT_STATUS byte 
  145.   mpuInterrupt = false
  146.   mpuIntStatus = mpu.getIntStatus(); 
  147.  
  148.   // get current FIFO count 
  149.   fifoCount = mpu.getFIFOCount(); 
  150.  
  151.   // check for overflow (this should never happen unless our code is too inefficient) 
  152.   if ((mpuIntStatus & _BV(MPU6050_INTERRUPT_FIFO_OFLOW_BIT)) || fifoCount >= 1024) { 
  153.   // reset so we can continue cleanly 
  154.   mpu.resetFIFO(); 
  155.   fifoCount = mpu.getFIFOCount(); 
  156.   Serial.println(F("FIFO overflow!")); 
  157.  
  158.   // otherwise, check for DMP data ready interrupt (this should happen frequently) 
  159.   } else if (mpuIntStatus & _BV(MPU6050_INTERRUPT_DMP_INT_BIT)) { 
  160.   // wait for correct available data length, should be a VERY short wait 
  161.   while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount(); 
  162.  
  163.   // read a packet from FIFO 
  164.   mpu.getFIFOBytes(fifoBuffer, packetSize); 
  165.  
  166.   // track FIFO count here in case there is > 1 packet available 
  167.   // (this lets us immediately read more without waiting for an interrupt) 
  168.   fifoCount -= packetSize; 
  169.  
  170.   // Get Yaw, Pitch and Roll values 
  171. #ifdef OUTPUT_READABLE_YAWPITCHROLL 
  172.   mpu.dmpGetQuaternion(&q, fifoBuffer); 
  173.   mpu.dmpGetGravity(&gravity, &q); 
  174.   mpu.dmpGetYawPitchRoll(ypr, &q, &gravity); 
  175.  
  176.   // Yaw, Pitch, Roll values - Radians to degrees 
  177.   ypr[0] = ypr[0] * 180 / M_PI; 
  178.   ypr[1] = ypr[1] * 180 / M_PI; 
  179.   ypr[2] = ypr[2] * 180 / M_PI; 
  180.     
  181.   // Skip 300 readings (self-calibration process) 
  182.   if (j <= 300) { 
  183.   correct = ypr[0]; // Yaw starts at random value, so we capture last value after 300 readings 
  184.   j++; 
  185.   } 
  186.   // After 300 readings 
  187.   else
  188.   ypr[0] = ypr[0] - correct; // Set the Yaw to 0 deg - subtract the last random Yaw value from the currrent value to make the Yaw 0 degrees 
  189.   // Map the values of the MPU6050 sensor from -90 to 90 to values suatable for the servo control from 0 to 180 
  190.   int servo0Value = map(ypr[0], -90, 90, 0, 180); 
  191.   int servo1Value = map(ypr[1], -90, 90, 0, 180); 
  192.   int servo2Value = map(ypr[2], -90, 90, 180, 0); 
  193.     
  194.   // Control the servos according to the MPU6050 orientation 
  195.   servo0.write(servo0Value); 
  196.   servo1.write(servo1Value); 
  197.   servo2.write(servo2Value); 
  198.   } 
  199. #endif 
  200.   } 

 

 

Finally using the write function, we send these values to the servos as control signals. Of course, you can disable the Yaw servo if you want just stabilization for the X and Y axis, and use this platform as camera gimbal.

 

Step 9: When All the Components Are Connected ,its Look Similar to This Picture

 

When All the Components Are Connected ,its Look Similar to This Picture

 

Step 10: Now Insert All Base Stuff Inside the Food Can

 

Now Insert All Base Stuff Inside the Food Can

Step 11: When All the Wires and Components Are Placed Inside a Food Can Then Applied Glue Gun at the Base of Foam Board.

 

When All the Wires and Components Are Placed Inside a Food Can Then Applied Glue Gun at the Base of Foam Board.

 

Step 12: Conclusion

Please note this far from good camera gimbal. The movements are not smooth because these servos are not meant for such a purpose. Real camera gimbals use a special type of BLDC motor for getting smooth movements. So, consider this project only for educational purpose.

That would be all for this tutorial, I hope you enjoyed it and learned something new. Feel free to ask any question in the comments section below and don’t forget to check my collections of project