I having a very hard time running 4 servos with the arduino. I can only get 2 to work.
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
Servo myservo2;
Servo myservo3; // create servo object to control a servo
Servo myservo4;
int potpin1 = 0; // analog pin used to connect the potentiometer
int potpin2 = 1;
int potpin3 = 2; // analog pin used to connect the potentiometer
int potpin4 = 3;
int val; // variable to read the value from the analog pin
void setup()
{
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10); // attaches the servo on pin 10 to the servo object
myservo3.attach(5); // attaches the servo on pin 5 to the servo object
myservo4.attach(6); // attaches the servo on pin 6 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, 179, 0); // scale it to use it with the servo (value between 0 and 180)
myservo1.write(val); // sets the servo position according to the scaled value
val = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo2.write(val);
val = analogRead(potpin3); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo3.write(val);
val = analogRead(potpin4); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 179, 0); // scale it to use it with the servo (value between 0 and 180)
myservo4.write(val); // sets the servo position according to the scaled value
// sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
Thats the code i em using, the turbble is that pin 5 and 6 are not sending pwm signals or any signal for that mater (aslo used LED light to test this) every thing else works. 9 and 10 are running 2 of the servos just fine. all 4 inputs are tested and good. Please help me i have been stuck on this for some time now.