#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3; // create servo object to control a servo
Servo servo4;
int potpin1 = 0; // analog pin used to connect the potentiometer
int potpin2 = 1;
int potpin3 = 2;
int potpin4 = 3;
int val; // variable to read the value from the analog pin
int val2;
int val3;
int val4;
void setup() {
servo1.attach(3);
servo2.attach(5);
servo3.attach(6);
servo4.attach(9);// attaches the servo on pin 9 to the servo object
}
void loop() {
val = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
servo1.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
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)
servo2.write(val2); // sets the servo position according to the scaled value
delay(15);
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)
servo3.write(val3); // sets the servo position according to the scaled value
delay(15);
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)
servo4.write(val4); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
So i'm making a 4 axis arm and i plugged one servo in to try it and it bugged out im using a HS-755HB servo
Servo servo1;
Servo servo2;
Servo servo3; // create servo object to control a servo
Servo servo4;
int potpin1 = 0; // analog pin used to connect the potentiometer
int potpin2 = 1;
int potpin3 = 2;
int potpin4 = 3;
int val; // variable to read the value from the analog pin
int val2;
int val3;
int val4;
This just frosts me. If you are going to number variables in set, number ALL of them, as you do in the first two sets.
servo1.attach(3);
servo2.attach(5);
servo3.attach(6);
servo4.attach(9);// attaches the servo on pin 9 to the servo object
Servos do NOT need to be connected to PWM pins. They can be, but they do not NEED to be.
The servo spazzed out. I have a 6 volt batterey pack that goes to the breadboard and then a 9v goes to the Arduino. If I didn't connect to a PWM what does it get connected to?
Do you have the 6V battery pack ground (- lead) tied to the Arduino and servo grounds? You should. Does your breadboard have a break in the upper and lower power rails. If so, is the break bridged?
And learn about arrays. They would make your code much shorter.
sciolyluvr:
I have a SSC-32U Lynx motion servo project extender could I somehow incorporate that to my device. (sorry I'm new to arduinos and robotics)
You could. But, why? The Arduino is perfectly capable of commanding servos with not servo controller needed.