Controlling 2 Servo Motor with Joystick
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.
Requirements
We need this couple of components in this tutorial;
- 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
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
Were placing the 9v battery on the horizontal rail of the breadboard to add another current source to the servo,.
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
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.
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
Hey, good job!
Can you also make a tutorial about WS2812 LED-Stripes.
And, is it possible to make a lightshow by Arduino?
yes! maybe soon
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
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
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