Introduction: 2 Servos Controlled by a Joystick

This circuit is designed so that depending on how a joystick is moved, a servo will move in a similar direction. For example, if the joystick is pushed left or right, one of the servos will move when triggered, and if the same joystick is moved up and down, then the other servo will trigger.

Contributors:

Evan T

Evan B

Jaden B

Cruz V

Elijah S

Kevin L

Supplies

Step 1: Code

We put this code into the Arduino IDE 2.3.2

and the notes tell what each line of code does.


#include <Servo.h>

Servo myservo; // creates a servo object to control the servos
Servo myservo2; //creates a servo object to control the servo

  int input = A0; //analog pin used to control the servo
  int val; //variable to read the value from the analog pin
  int input2 = A1; //analog pn used to control the serv
void setup() {
  myservo.attach(9); //attaches the servo on pin 9 on the servo object
  myservo2.attach(10); //ataches the servo on pin 10 to the servo object
}
void loop() {
  val = analogRead(input);      // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);  // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);         // sets the servo position according to the scaled value
  delay(15);       // waits for the servo to get there
   val = analogRead(input2);      // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);  // scale it to use it with the servo (value between 0 and 180)
  myservo2.write(val);         // sets the servo position according to the scaled value
  delay(15);             // waits for the servo to get there
}

Step 2: Connecting Positive, Negative and the Capacitors

Positive and Negative

  1. To connect negative you first need to find the ground pin (marked gnd and in white on the Arduino) and connect the ground pin to the negative lead on your breadboard (marked - )
  2. To connect positive you need to find the pin marked 5V (next to the gnd pin on the Arduino) and then connect the 5V pin to the positive lead on your breadboard (marked +)

The Capacitors

One important thing to understand about polarized capacitors is that they have a positive and negative, because of this it does matter how you attach the capacitors. The positive is on the long leg and the negative pin is on the short leg of the capacitor

The function of the capacitor in this circuit is to stabilize the current and keep it constant instead of in pulses.

Where you put the capacitor doesn't really matter but i still would recommend separating them on different sides of the breadboard for ease of putting it together

Step 3: Wiring the Servos

The servos have 3 places to connect wires. The Control pin, Positive, and Negative. The control pin on the servo is orange, the positive is red, and the negative is black.

  1. To connect the servos to the Arduino find the Control Pin, then connect the control pin to either pin ~9 or pin ~10
  2. the Positive of the servos to the positive on one of the Capacitors and do the same for the Negative.

Step 4: Wiring the Joystick

The joystick works by using 2 potentiometers attached to a single control stick, those potentiometers are what we are using to control the servo

  1. To connect the joystick you need to first look at the pinout of your specific joystick. You want to find the pins GND, +5v r VCC, VRX/Vert, and VRY/HORZ. First connect the 5V pin to the positive of the second capacitor and the GND pin to the Negative of the same Capacitor.
  2. Connect the Vert to pin A0 and HORZ to pin A1

Step 5: Your Done

if you followed the steps correctly you should have a working circuit, if not do trouble shooting idk