I want to control 2 servos using a Arduino Mega. The mega is connected to the PC using a USB cable and I've also connected an external powersupply to the mega.
The servos are connected to pin 9 and 10 of the Arduino Mega.
The servos are powered using an external stabilized power supply (5 V). The Brown wire to the ground, the red wire to 5 V and the orange wire to Pin 9 of the Mega.
When I power up the power supply the servos move a little bit but when I use the following code nothing happens?
I've used this code to test 1 servo:
// Sweep
// by BARRAGAN <http://barraganstudio.com>
#include <Servo.h>
Servo myservo; // create servo 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()
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 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
Serial.print("Hello World!");
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 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
}
}
Nothing happens using this code :-* I have also tried increased delay values but also without succes......
Is there a way to see if the Pin 9 gives a signal? (I don't have a Oscilloscope) Am I overlooking something obvious?
No I have not got a common ground. How do I realize this?
BTW: I have removed the external power supply of the Mega. So I just have the external power supply for the servos and the USB power of the Mega.
And I have connected the power supply ground with a wire to the ground to the arduino (in the power area of the arduino). Is this the right way to make a "common ground"?
I have tested the setup again but still without succes.......
I have connected the power supply ground with a wire to the ground to the arduino (in the power area of the arduino). Is this the right way to make a "common ground"?
pins 9 and 10 on the mega use timer4 for PWM. The Arduino Servo library uses Timer1, which as I said in the earlier post uses pins 11 and 12 on the Mega.
It doesn't use a timer so it will be a good test to see if the servo itself is working. If you can't get the servo to work with that code then problem is either with the servo, the wiring or power. Once you do get the servo working we can see if we can get it going with the Arduino library (or you could try this one: Arduino Playground - MegaServo )
I've used the mega servo library and this works :). I have connected one servo to pin 2. So now I know the servo works
I have also tried pin 11 and 12 with the servo library but this doesn't work. Is it possible a error in the library of is there something wrong with with my mega?
Update:
I have also tried to connect the servo to pins 9 and 11 using the MegaServo library and this also works.
In Arduino 0016 and earlier, the Servo library uses functionality built in to the hardware, and works only on pins 9 and 10 (and does not work on the Arduino Mega). In this case, if only one servo is used, the other pin cannot be used for normal PWM output with analogWrite(). For example, in Arduino 0016 and earlier, you can't have a servo on pin 9 and PWM output on pin 10.