Robot Arm Control with a Potentiometer


Description:

In this tutorial, we will learn how to use robotic arm control with potentiometer.
We will control 4 axis robot arm with 4 pcs potentiometer.
We will use external battery / power when doing this.

Watch review the robot arm : https://youtu.be/nWBmZ1HDGZc


--------------------

Hardware Required:

- 4 Axis Robot Arm Kit - https://goo.gl/6UZJL6
- Arduino Board - https://goo.gl/UyGYeF
- 10k Potentiometer x4 - https://goo.gl/c90Uix
- Battery and Battery Buckle - https://goo.gl/iAEgPl
- Wires - https://goo.gl/TdGrkk / https://goo.gl/VRzUN4
-Breadboard - https://goo.gl/yCa8hX

Robot Arm Servo Kit - https://goo.gl/6UZJL6

Recommended site to buy the required hardware:
https://www.banggood.com/?p=CS120478587752016125


--------------------

Connections:

- The external battery VCC / GND connect to the breadboard.
- The Arduino GND connect to the breadboard's GND input
- The servo connections we use in this project are as follows;

  Orange Input - Signal Input
  Red Input - Power Input (VCC)
  Brown Input - Ground Input(GND)

- The potentiometer connections we use in this project are as follows;

  Two outer pins are power (VCC) and ground (GND)
  Middle pin is signal pin

- The Servo1 VCC and GND connect to the breadboard's VCC / GND inputs
- The Servo1 Signal connect to the Arduino Digital PWM 3
- The Servo2 VCC and GND connect to the breadboard's VCC / GND inputs
- The Servo2 Signal connect to the Arduino Digital PWM 5
- The Servo3 VCC and GND connect to the breadboard's VCC / GND inputs
- The Servo3 Signal connect to the Arduino Digital PWM 6
- The Servo4 VCC and GND connect to the breadboard's VCC / GND inputs
- The Servo4 Signal connect to the Arduino Digital PWM 9

- The Potentiometer's one outer pin connect to the breadboard or the Arduino board VCC input
- The Potentiometer's other outer pin connect to the breadboard or the Arduino board GND input
- The Potentiometer's middle pin connect to the Arduino Analog 1-2-3-4 input

--------------------

Get the Code:
//add servo library
#include <Servo.h>

//define our servos
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

//define our potentiometers
int pot1 = A1;
int pot2 = A2;
int pot3 = A3;
int pot4 = A4;

//variable to read the values from the analog pin (potentiometers)
int valPot1;
int valPot2;
int valPot3;
int valPot4;

void setup()
{
  //attaches our servos on pins PWM 3-5-6-9 to the servos
  servo1.attach(3);
  servo1.write(0);  //define servo1 start position
  servo2.attach(5);
  servo2.write(90); //define servo2 start position
  servo3.attach(6);
  servo3.write(90); //define servo3 start position
  servo4.attach(9);
  servo4.write(70); //define servo4 start position
}

void loop()
{
  //reads the value of potentiometers (value between 0 and 1023)

  valPot1 = analogRead(pot1);
  valPot1 = map (valPot1, 0, 1023, 0, 180); //scale it to use it with the servo (value between 0 and 180)
  servo1.write(valPot1); //set the servo position according to the scaled value

  valPot2 = analogRead(pot2);
  valPot2 = map (valPot2, 0, 1023, 0, 180);
  servo2.write(valPot2);
  
  valPot3 = analogRead(pot3);
  valPot3 = map (valPot3, 0, 1023, 0, 180);
  servo3.write(valPot3);

  valPot4 = analogRead(pot4);
  valPot4 = map (valPot4, 0, 1023, 70, 150);
  servo4.write(valPot4);
  
}