Pages: [1]   Go Down
Author Topic: can you independently control 3 servos?  (Read 1355 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

is it possible to use an arduino duemilanove to control 3 servos independently?

thanks
« Last Edit: June 14, 2009, 07:37:32 pm by budsiskos » Logged

London, England
Offline Offline
Edison Member
*
Karma: 4
Posts: 1026
Go! Go! Arduinoooo !!!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

With the Mega Servo Library you can control 12 servos (48 if you have a Mega)

With the Software Servo library you can control 20 Servos at the same time.

Take a look at the Servo section in the Playground.
« Last Edit: June 14, 2009, 08:06:30 pm by zooto68 » Logged

magalia ca
Offline Offline
Jr. Member
**
Karma: 0
Posts: 70
When can I get an Arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well i spent about an hour looking where you told me to, and here is what i came up with. Can you please look over it and tell me if its right? I have lots of wires to hook up and i need the code to be right.  Thank you!

Code:
#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
}
Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

looks reasonable to me, apart from the first line.
The standard servo library only controls two servos.

Code:
#include <MegaServo.h>

#define N_SERVOS 4
Servo myservo [N_SERVOS];  // create servo object to control a servo
const byte servoPin [N_SERVOS] = {9, 10, 5, 6};
const byte potPin [N_SERVOS] = {0, 1, 2, 3};
int i;

void setup()
{
  for (i = 0; i < N_SERVOS; i++) {
    myservo [i].attach(servoPin[i]);
  }
}

void loop()
{
  for (i = 0; i < N_SERVOS; i++) {
    myservo[i].write(map(analogRead(potPin [i]), 0, 1023, 179, 0));
  }
  delay(15);
}
« Last Edit: July 07, 2009, 02:24:19 am by GrooveFlotilla » Logged

Per Arduino ad Astra

Pages: [1]   Go Up
Jump to: