Show Posts
Pages: [1]
1  Using Arduino / Motors, Mechanics, and Power / Re: How to run 4 servos separately using the Arduino R3 board? on: January 09, 2013, 01:38:31 pm
Simply declare another three instances of the servo. That is the it where you say what pin it is on. Use a different pin and a diffrent name.
Post your code if you have troubl. Use code tags if you do.

Thanks Mike for the feedback. I actually did that but I faced a weird problem. When I connected the two servos on an external power supply the two servos moved in one direction and stopped, however when I connected them both to the Arduino 5V power both servos worked simultaneous. I then used one on the external power and one on the board power, only the one connected to the board works. I am using two identical servos and used signals from pins 8 and 12. What is going wrong? Below is the code:


#include <Servo.h>
 
Servo myservo;  // create servo1 object to control a servo
                // a maximum of eight servo objects can be created

Servo myservo2;  // create servo2 object to control a servo
                // a maximum of eight servo objects can be created
               
int pos = 0;    // variable to store the servo position
 
void setup()
{
  myservo.attach(smiley-cool;  // attaches the servo on pin 8 to the servo object
  myservo2.attach(12);  // attaches the servo on pin 10 to the servo object

 
void loop()
{
  for(pos = 0; pos < 160; pos += 1)  // goes from 0 degrees to 160 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }

  for(pos = 0; pos < 120; pos += 1)  // goes from 0 degrees to 120 degrees
  {                                  // in steps of 1 degree
    myservo2.write(pos);              // tell servo2 to go to position in variable 'pos'
    delay(25);                        // waits 25ms for the servo to reach the position
  }


  for(pos = 160; pos>=1; pos-=1)     // goes from 160 degrees to 0 degrees
  {                               
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }


 for(pos = 120; pos>=1; pos-=1)     // goes from 120 degrees to 0 degrees
  {                               
    myservo2.write(pos);              // tell servo to go to position in variable 'pos'
    delay(30);                       // waits 30ms for the servo to reach the position
  }
}



Note: after the upload is complete I am getting the following note at the bottom of the page (the black space): avrdude: stk500_getsync() : not in sync: resp=0x00. Does this have anything with the fault??
2  Using Arduino / Motors, Mechanics, and Power / How to run 4 servos separately using the Arduino R3 board? on: January 07, 2013, 07:57:26 am
I am another new commer to this nice hobby.
Purchased an Arduino Uno R3, downloaded the software, connected one Futaba Servo, used the Servo "sweep" example on pin 13 and everything worked perfect.
I want to run 3 more servos separately on other pins (with an outside power supply) but got stuck on the code.
How can I make each servo roate separately (left - right) by modifying the servo "sweep" example?

Appreciate assistance from any one. Regards,
Pages: [1]