Hi guys, I need help programming a robotic arm. The arm is a Robix kit that contains 6 servos, but if i can get 3 servos working, it is good enough. I also want to control it with a ps2 analouge controller. So far i need a robotic arm that can turn left/right up/down and activate a pincher. Any help will be great 8)
I am a noob btw, and i need it for a school project
To be honest I don't know how to use the ps2 controller but I can show you how to move your servos.
To control a servo you will need to use all three wires coming from it. The yellow one should be connected to a pwm pin on your Arduino. The black wire is ground and the red is live. You will need a 5v power supply. If you try to pull power from you Arduino you will destroy it. A battery pack or a wall wort should do the trick. Simply put the positive wire from the power source to the positive wire of your servo. Do the same with the ground wire.
Try just one servo to start with and use the code below. Once you get it working try to adapt the program to control 6 servos if you can't I will show you how.
I was actually planning to do the cheapest way possible without a transmitter and a receiver. A direct link with the controller and arduino, and then the arduino to the servo(s)
This video helped me a little, but i still need to control it with a ps2 controller.
The trial run with one servo was successful, thank you
I get it now. That is much easier to program then if it was wireless. It so cool… I want one
From what I can see you will need 5 servos and 5 buttons.
up
down
left
right
pincher.
What buttons on the controller do you want to use for those motions. I was thinking the group of buttons on the left of the controller for motion and maybe one of the ones on the back side to activate the pinch?
Chose which one you want and we can start programing. Also do you have any experience in C?
I have absolutely no experience in C, I am a junior in high school and I am just starting off . Ive seen a couple of tutorials on youtube but none really help me out. Although I have no experience this field really intrigues me and sheer amount of things one can create with an arduino.
I have 2 midterm tests this week so I don't know if I will be able to wright up an example for you this week. Unless somebody gets to it faster I should have something during spring break (next week).
Search the forums for posts by Zoomkat - his test code for servos should get you started with one axis and once you have that it should be easy enough to add others.
Not if you want the up and down to have two points of motion. This Arm has six servos so I assume their is more then one servo controlling up and down.
//zoomkat 11-22-12 simple delimited ',' string parse
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added
String readString;
#include <Servo.h>
Servo myservoa, myservob, myservoc, myservod; // create servo object to control a servo
void setup() {
Serial.begin(9600);
//myservoa.writeMicroseconds(1500); //set initial servo position if desired
myservoa.attach(6); //the pin for the servoa control
myservob.attach(7); //the pin for the servob control
myservoc.attach(8); //the pin for the servoc control
myservod.attach(9); //the pin for the servod control
Serial.println("multi-servo-delimit-test-dual-input-11-22-12"); // so I can keep track of what is loaded
}
void loop() {
//expect single strings like 700a, or 1500c, or 2000d,
//or like 30c, or 90a, or 180d,
//or combined like 30c,180b,70a,120d,
if (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
if (c == ',') {
if (readString.length() >1) {
Serial.println(readString); //prints string to serial port out
int n = readString.toInt(); //convert readString into a number
// auto select appropriate value, copied from someone elses code.
if(n >= 500)
{
Serial.print("writing Microseconds: ");
Serial.println(n);
if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
if(readString.indexOf('b') >0) myservob.writeMicroseconds(n);
if(readString.indexOf('c') >0) myservoc.writeMicroseconds(n);
if(readString.indexOf('d') >0) myservod.writeMicroseconds(n);
}
else
{
Serial.print("writing Angle: ");
Serial.println(n);
if(readString.indexOf('a') >0) myservoa.write(n);
if(readString.indexOf('b') >0) myservob.write(n);
if(readString.indexOf('c') >0) myservoc.write(n);
if(readString.indexOf('d') >0) myservod.write(n);
}
readString=""; //clears variable for new input
}
}
else {
readString += c; //makes the string readString
}
}
}