2-axis Gimbal

2,326

23

2

2-axis gimbal are commonly used for the stabilization of cameras for both smartphones and drones. Optical Imaging Stabilization is a popular example of the use of a 2-axis gimbal. The phone camera is physically connected to two motors that moves in the opposite direction of the measurements of the internal inertial measurement unit.

This project uses 2 servo motors, a common application for drones particularly, for adjusting the pitch and yaw. While, 2 potentiometers serves as a manual input to control the movement of the servo motors. This type of application can be used for drones and is the same technology in handheld gimbals, and can be made for under $15.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Tools and Materials

  • Arduino Uno or Arduino 101
  • 2 Servo Motors
  • 2 Trimmer Potentiometers
  • Jumper Wires

Step 2: Glue the Servos

  • Momentarily plug in the servo to 5V such that the control horns shall be centered.
  • Glue the control horn of one servo to the body of the other servo. Make sure to not glue onto the sticker, since it can easily peel off.

Step 3: Circuitry

Supply power from the Arduino board to the breadboard power rails for both 3.3V and 5V.

  • Connect the Arduino's 3.3V pin to the red rail on the 'j' side of the breadboard.
  • Connect the Arduino's 5.5V pin to the red rail on the 'a' side of the breadboard
  • Connect the Arduino's GND pin to the black rail on both sides of the breadboard.

Connect the servo motor to the Arduino board and breadboard power rails

  • Connect the red wire of the servo motors to the 5V rail on the breadboard
  • Connect the black wire of the servo motors to the ground rail on the breadboard
  • Then connect both of the signal wires, yellow or beige in colour, to pins 3 and 9 respectively.

Lastly, connect the potentiometer to the analog pins of the Arduino board and power rails of the breadboard.

  • Connect one of the outer pins of each of the potentiometer to ground.
  • While the other outer pin to the 3.3V rail of the breadboard. There are no polarity requirements, so order does not matter.
  • Then, connect the middle pins to A0 and A1 on the Arduino, order it as to how you wish the servo to be controlled.

Step 4: Code

The Arduino code simply reads the two analog inputs from the potentiometer and maps the maximum and minimum bounds of this signal to the maximum and minimum angles that the servo can turn, and relays the signal to the servo motors to adjusts accordingly.

//include the servo library
#include

//create the servo objects called servo1 and servo2 Servo servo1; Servo servo2;

// declare the pins to which the servo and potentiometers is connected. const int servoPin1 = 3; const int servoPin2 = 9; const int pot1 = 0; const int pot2 = 1;

void setup() { //attach servo1 to pin 5 on the Arduino 101 servo1.attach(servoPin1); //attach servo1 to pin 5 on the Arduino 101 servo2.attach(servoPin2);

}

void loop() { // put your main code here, to run repeatedly: //record the value of the two potentiometers. int pot1Value = analogRead (pot1); int pot2Value = analogRead (pot2);

// linearly scale the value of the sevo output from the 0 to 1023 range of the potentiometer // to the angle limits by the servo which is 0 to 180 degrees pot1Value = map(pot1Value, 0, 1023, 0, 150); pot2Value = map(pot2Value, 0, 1023, 0, 150);

// record the now-adjusted value of the potentiometer to the servo motor servo1.write(pot1Value); servo2.write(pot2Value);

}

Step 5: Demo

As I adjust the potentiometer knob, the servo motor turns accordingly. Each potentiometer is mapped to each one of the servos. By extension this could be applied to make a 3 axis gimbal. Though, 2 axis gimbals are used in a wider variety of applications.

Enjoy your build!

Makerspace Contest 2017

Participated in the
Makerspace Contest 2017

Be the First to Share

    Recommendations

    • CNC Contest

      CNC Contest
    • Make it Move

      Make it Move
    • Teacher Contest

      Teacher Contest

    2 Discussions

    0
    None
    Jungminkim

    Question 6 months ago on Introduction

    Hello! I want to use your code for my project Arduino servo-gimbal. So, I tried to upload your code on my Arduino Uno(I don't have potentiometers so I didn't use that. I only used two servo motors.)

    // Code
    #include <Servo.h>
    const int servoPin1 = 9;
    const int servoPin2 = 3;
    const int pot1 = 0;
    const int pot2 = 1;
    Servo servo1;
    Servo servo2;
    void setup() {
    // attach servo1 to pin 5 on the Arduino
    servo1.attach(servoPin1);
    servo2.attach(servoPin2);
    }
    void loop() {
    // put your main code here, to run repeatedly:
    int pot1Value = analogRead(pot1);
    int pot2Value = analogRead(pot2);
    pot1Value = map(pot1Value, 0, 1023, 0, 180);
    pot2Value = map(pot2Value, 0, 1023, 0, 180);
    servo1.write(pot1Value);
    servo2.write(pot2Value);
    }


    There was an error "servo1 is not declared in this scope" So, I put the global variable on the top of the code.
    And I uploaded the code above, But The servo motor didn't work. There are no movements. I don't know why It didn't work.

    Has this problem occurred because there are no potentiometers? Or are there anything wrong with this code?

    1 answer
    0
    None
    TechMartianJungminkim

    Reply 5 months ago

    It should be fine, so long as the range is between 0 and 180. Sometimes I encouter this issue with a bad servo or if the servo is under powered. Try an external power source.