Greetings! I'm building a Robot arm for my high school robotics team and I know it's pretty simple but I'm having trouble with the code.
Alright, so I'm using an Arduino Mega 2560, 2 L298n dual H-bridges preassembled with four in ports each: in1 in2 in3 and in 4, four 3v dc motors hooked up to tamiya gearboxes, and four potentiometers. I'm building a robot arm that has three joints (arm, shoulder, and wrist) along with a rotating base. What I want to do is when the pot is in the middle, the motor is off. When the pot is all the way to the left, then the motor will go to the left. When it goes all the way to the right, then the motor would go to the right. If there's a way to control the speed, then that would be great too! Although I feel as if i'm asking for much, I really hope I can understand the code as soon as I'm able to visibly see it. Thanks a lot!
My off-the-cuff thought is that servos, not dc motors, is the way to go.
The attached pic is my daughter’s arm (not hers, her robot’s 8) ), still very much under construction. It has 2 x standard size servos in a pan / tilt bracket on the base, and a micro servo as the elbow. The metalwork is all Meccano (= Erector). Control is via a thumb joystick which gives pan / tilt, and a separate pot for the elbow- probably going to neaten that up with another joystick.
When the pot is all the way to the left, then the motor will go to the left. When it goes all the way to the right, then the motor would go to the right. If there’s a way to control the speed, then that would be great too!
Sounds as if you want to use the controls to define the speed. That’s perfectly possible, but wouldn’t it be much easier to use if you designed it so that the pots defined the position of the joint?
Anyway, what you need to control the speed or position is closed loop feedback control, and the PID algorithm is a simple and very flexible way to provide that. There’s a PID library for Arduino. I recommend that you read and understand the theory behind it before you try to use it, otherwise you can get hopelessly lost.
If you use an ordinary hobby servo instead of separate motors and drivers and so on, the problem is much, much easier because you can use the Servo library to send each servo to whatever position you want - all you’d need is a loop to read the pot, map the analog value to a servo position, and instruct the servo to go to that position. The limitation here is that cheaply available hobby servos are quite small and low powered, and perhaps you’re aiming for something much bigger.
I did want to use servos but with the time I had left and the tremendous amount of torque I needed it wouldn't be possible. I also did want to use some sort of feedback like a pot hooked up to the side of an output shaft but the arm is gonna move pretty slowly to be able to do that.