Controlling 2 Servo Motor with Joystick

in #utopian-io7 years ago (edited)

What Will I Learn?

Today In this tutorial, we will learn how to use multi-servo motor with Joystick. We will control two servo motor with one Joystick.
You can experiment your robotic arm orexcavator projects with reference to this tutorial. Of course we will use external battery to add another power source when doing this.

20180123_132806.jpg

Requirements

We need this couple of components in this tutorial;

20180123_131006.jpg

  • Joystick module
  • 2 servo motor
  • Breadboard
  • Arduino Board
  • Jumper wires

Difficulty

  • Basic

Tutorial Contents

We will be using the 2 servo as the components to control by a joystick, servo motor has everything built-in a motor, a feedback circuit, and most important, a motor driver. It just needs one VCC power line, one GND ground, and one control pin. or simply servo motors are great devices that can turn to a specified position. Lets start this tutorial by following the circuit diagram that i made on fritzing

fret2.png

Were going to use the Joysticks or in some cases thumbstick this component is a great source of input for a project. Especially for robotics. this joystick module is similar to a PS4 Controller. The X and Y axes are two ~10k potentiometers which control 2D movement by generating analog signals and also has a push button that could be used for special use.

Connection of servo and joystick to arduino

20180123_132258.jpg

Were placing the 9v battery on the horizontal rail of the breadboard to add another current source to the servo,.

  • connect the black/brown wire to the GND
  • the red wire to 5V
  •  the orange/yellow one to pin 3 for servo1 and pin 6 servo2
  • Connect the pin X of the joystick to pin A0 on uno
  • Y pin to A1
  • GND to GND
  • 5V to 5V
  • SOFTWARE

    Before we work on our sketch, make sure to download the Arduino IDE for your specific operating system. I’ll leave a link to where you can download this software: https://www.arduino.cc/en/Main/Software

    seq1.png

    The Servo library is already on the arduino ide so we are not going to add library on it, so lets start to work on the code for this.

    on the start line of the code include the Servo library #include <Servo.h>
    attach the servo1 and servo2 to pwm pin on digital pin output, servo1.attach(5);
    servo2.attach(2);
    define the pin output of the joystick to analog pin on the arduino, int joyX = 0;
    int joyY = 1;
    Define the roation map of the servo to 180 on JoyYand joyX joyVal = map (joyVal, 0, 1023, 0, 180);

    COPY CODE HERE:


    #include <Servo.h>
    Servo servo1;
    Servo servo2;
    int joyX = 0;
    int joyY = 1;
    int joyVal;
    void setup ()
    {
      servo1.attach(5);
      servo2.attach(2);
    }
    void loop()
    {
      joyVal = analogRead(joyX);
      joyVal = map (joyVal, 0, 1023, 0, 180);
      servo1.write(joyVal);
      joyVal = analogRead(joyY);
      joyVal = map (joyVal, 0, 1023, 0, 180);
      servo2.write(joyVal);
      delay(15);  
    }

    We can make a moving robot arm and a excavator or trucktors to move with this experiment.

    20180123_190520.gif


    20180123_191803.gif

    I hope you enjoy this actitvity if want to learn how arduino works, and how to make a sketch, then maybe this site http://educ8s.tv/ might help you, i was inspired by Mert arduino and tech for this wonderful stuff. thank you for stopping by.

    You can also check my previous posts:

    How to make 12 LED chaser without shift
    Control LED using Push Buttons/ Visual programming using XOD
    Control Servo motor using Joystick
    Stepper motor + Driver Uln2003 in arduino
    Control Servo motor using potentiometer - arduino



    Posted on Utopian.io - Rewarding Open Source Contributors

    Sort:  

    Hey, good job!
    Can you also make a tutorial about WS2812 LED-Stripes.

    And, is it possible to make a lightshow by Arduino?

    Thank you for the contribution. It has been approved.

    You can contact us on Discord.
    [utopian-moderator]

    Hey @pakganern I am @utopian-io. I have just upvoted you!

    Achievements

    • Seems like you contribute quite often. AMAZING!

    Suggestions

    • Contribute more often to get higher and higher rewards. I wish to see you often!
    • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

    Get Noticed!

    • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

    Community-Driven Witness!

    I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

    mooncryption-utopian-witness-gif

    Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x