I need help with finding a code for Arduino Uno for robot\'s arm using two servo
ID: 2292514 • Letter: I
Question
I need help with finding a code for Arduino Uno for robot's arm using two servo motors stick together. The coding below makes the second motor move very fast and quick and the first motor turns the same. they are controlled using a joystick.
How can I slow down the speed of the moving servo motor 2 please can you provide me the code and add it to the code below?
//add the aervo library
#include <Servo.h>
//define our servos
Servo servo1;
Servo servo2;
//define joystick pin (Analog)
int joyX =0;
int joyY =1;
//variable to read the values from the analog pins
int joyVal;
void setup()
{ //attaches our servos on pins PWM 3-5
servo1.attach(3);
servo2.attach(5);
}
void loop()
{
//read the value of joystick (between 0-1023)
joyVal = analogRead(joyX);
joyVal = map (joyVal, 0, 1023, 0, 180); //servo value between 0-180
servo1.write(joyVal); //set the servo position according to the joystick value
joyVal = analogRead(joyY);
joyVal = map (joyVal, 0, 1023, 0, 180);
servo2.write(joyVal);
delay(15);
}
Explanation / Answer
You can vary the speed using delay by adding extra delay you can enhance the speed although the speed will be decrease for servo motor 1 also if you want to control independly you need to have cont
#include <Servo.h>
//define our servos
Servo servo1;
Servo servo2;
//define joystick pin (Analog)
int joyX =0;
int joyY =1;
//variable to read the values from the analog pins
int joyVal;
void setup()
{ //attaches our servos on pins PWM 3-5
servo1.attach(3);
servo2.attach(5);
}
void loop()
{
//read the value of joystick (between 0-1023)
joyVal = analogRead(joyX);
joyVal1 = map (joyVal, 0, 1023, 0, 180); //servo value between 0-180
servo1.write(joyVal1); //set the servo position according to the joystick value
joyVal2 = analogRead(joyY); // Same variable is updated again Here is the mistake
joyVal3 = map (joyVal2, 0, 1023, 0, 180);
servo2.write(joyVal3);
delay(15);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.