Robotic Arm Controlled by Potentiometers and Arduino (Servo Motor Control)
by STEAM-DIY in Circuits > Arduino
251 Views, 1 Favorites, 0 Comments
Robotic Arm Controlled by Potentiometers and Arduino (Servo Motor Control)
The robotic arm project uses four servo motors and four potentiometers. Each potentiometer adjusts the position of one servo, allowing you to control the robotic arm's joints. This setup can be used as a starting point for more complex robotic arm designs, or for applications like pick-and-place robots in small-scale projects.
The core of this project is the Arduino, which reads the analog inputs from the potentiometers and sends corresponding signals to the servos to adjust their angles.
Supplies
Supplies
You will need the following components to build this project:
- 1x Arduino Uno
- 4x Servo Motors (SG90 or equivalent)
- 4x Potentiometers (10k Ohms)
- Breadboard
- Jumper wires
- USB cable (to connect Arduino to a computer)
Wiring the Components
Step 1: Wiring the Components
To wire the robotic arm, follow these steps based on the provided image:
- Potentiometers:
- Connect the middle pin of each potentiometer to analog pins A0, A1, A2, and A3 on the Arduino.
- Connect one outer pin of each potentiometer to the 5V power line on the breadboard.
- Connect the other outer pin of each potentiometer to the ground (GND) line on the breadboard.
- Servo Motors:
- Connect the signal wire (orange) of each servo to the digital pins 9, 10, 11, and 12 of the Arduino.
- Connect the power wire (red) of each servo to the 5V power rail on the breadboard.
- Connect the ground wire (brown/black) of each servo to the GND rail on the breadboard.
- Power Supply:
- Ensure that both the servos and the potentiometers share the same power and ground connections with the Arduino.
Upload the Code
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2;
Servo myservo3;
Servo myservo4;
int potpin1 = 0; // analog pin used to connect the potentiometer
int potpin2 = 1;
int potpin3 = 2;
int potpin4 = 3;
int val1; // variable to read the value from the analog pin
int val2;
int val3;
int val4;
void setup() {
myservo1.attach(9);
myservo2.attach(6);
myservo3.attach(5);
myservo4.attach(3);// attaches the servo on pin 9 to the servo object
}
void loop() {
val1 = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023)
val1 = map(val1, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo1.write(val1); // sets the servo position according to the scaled value
val2 = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023)
val2 = map(val2, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo2.write(val2);
val3 = analogRead(potpin3); // reads the value of the potentiometer (value between 0 and 1023)
val3 = map(val3, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo3.write(val3);
val4 = analogRead(potpin4); // reads the value of the potentiometer (value between 0 and 1023)
val4 = map(val4, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo4.write(val4);
delay(15); // waits for the servo to get there
}
Test the Robotic Arm
Conclusion
This robotic arm project is a great way to learn about controlling servo motors using analog inputs. It can be expanded with additional features, such as using more servos or incorporating sensors for autonomous movement. You can also build a physical arm with links and joints to simulate a real robotic arm.
This setup allows for further experimentation in robotics, servo control, and interactive electronics.