2 Potentiometers & 2 Servos: Controlled Motion With Arduino
by moont087 in Circuits > Arduino
6062 Views, 5 Favorites, 0 Comments
2 Potentiometers & 2 Servos: Controlled Motion With Arduino
First you need to gather relevant materials to put this circuit together.
Supplies
1 Arduino
2 Potentiometers
2 Servo
1 Breadboard
5 Black Jumper Wires (Ground/Negative)
5 Red Jumper Wires (Voltage/Positive)
4 Color Jumper Wires (Input/Output)
Understanding the Components
It is important before putting together the physical circuit to understand each component:
The breadboard has two sets of power rails on either side, that have slots for negative (black/blue) and positive (red) inputs. They are connected in series vertically. Terminal strips share the connection horizontally, however parallel terminal strips will require a jumper wire to bridge the divider.
The potentiometer has a 5V pin (red), a Vout pin (yellow/color) and Ground/GND pin (black).
The servo has a 5V port (red), a Pulse Width Modulation/PWM port (yellow/color) and a Ground/GND port (black). Click the link to know more about how it works.
Setting Up the Circuit
Follow the diagram layout. While setting up the circuit, always remember to keep the arduino unplugged to avoid any damage to your components. My thoughts in circuit organization, is to plug Potentiometer 1 next to Servo 1, and plug Potentiometer 2 next to Servo 2 - this helps you manage what is going on as more and more components get stacked together. This will also be visualized in the next code step.
Plug the potentiometer into the breadboard, taking note of its orientation (this will be important when using the jumper wires to connect to the arduino):
Potentiometer 1: Use a color jumper wire and connect the middle output pin to the analog (A0) port on the arduino. Plug the red jumper wire into V5 port and a black jumper wire into GND port on the arduino.
Potentiometer 2: Use a color jumper wire and connect the middle output pin to the
analog (A1) port on the arduino. Plug the red jumper wire into V5 port and a black jumper wire into GND port on the arduino.
Plug the servo into to the breadboard and arduino:
Servo 1: Use a color jumper wire to connect it's input/signal port to the digital PWM port, 5 on the arduino. Plug the red jumper wire into V5 terminal strip and a black jumper wire into GND terminal strip in series with potentiometer layout (refer to image).
Servo 2: Use a color jumper wire to connect it's input/signal port to the digital PWM port, 3 on the arduino. Plug the red jumper wire into V5 terminal strip and a black jumper wire into GND terminal strip in series with potentiometer layout (refer to image).
After the circuit is set up, proceed to connect your arduino into your computer.
Download Arduino GUI and Input Code
Download Arduino Graphical User Interface (GUI) here.
Plug in the code below, note the information to the right of "//" tells you what that line of code is doing:
----copy below and paste into arduino GUI----
#include
//**** servo 1 settings
Servo servo1;
const int servo1PotPin = A0;
const int servo1Pin = 5; // Must use PWM enabled pin
int servo1_test;
//**** servo 1 settings END
//**** servo 2 settings
Servo servo2;
const int servo2PotPin = A1;
const int servo2Pin = 3; // Must use PWM enabled pin
int servo2_test;
//**** servo 2 settings END
void setup() {
servo1.attach(servo1Pin);
servo2.attach(servo2Pin);
}
void loop() {
servo1_test = analogRead(servo1PotPin);
servo1_test = map(servo1_test, 0, 1023, 65, 0); //servo rotation is only 65 degrees. currently translating potentiometer values to degrees of rotation for servo, currently in reverse
servo1.write(servo1_test);
servo2_test = analogRead(servo2PotPin);
servo2_test = map(servo2_test, 0, 1023, 80 , 0); //servo rotation is only 80 degrees. currently translating potentiometer values to degrees of rotation for servo, currently in reverse
servo2.write(servo2_test);
delay(5);
}
2 Potentiometer + 2 Servo + Arduino
This is how the final circuit should look. Watch the video to see how it works.