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?
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.
Grumpy_Mike:
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(8); // 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??
//zoomkat 11-22-12 simple delimited ',' string parse
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added
String readString;
#include <Servo.h>
Servo myservoa, myservob, myservoc, myservod; // create servo object to control a servo
void setup() {
Serial.begin(9600);
//myservoa.writeMicroseconds(1500); //set initial servo position if desired
myservoa.attach(6); //the pin for the servoa control
myservob.attach(7); //the pin for the servob control
myservoc.attach(8); //the pin for the servoc control
myservod.attach(9); //the pin for the servod control
Serial.println("multi-servo-delimit-test-dual-input-11-22-12"); // so I can keep track of what is loaded
}
void loop() {
//expect single strings like 700a, or 1500c, or 2000d,
//or like 30c, or 90a, or 180d,
//or 30c,180b,70a,120d,
if (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
if (c == ',') {
if (readString.length() >1) {
Serial.println(readString); //prints string to serial port out
int n = readString.toInt(); //convert readString into a number
// auto select appropriate value, copied from someone elses code.
if(n >= 500)
{
Serial.print("writing Microseconds: ");
Serial.println(n);
if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
if(readString.indexOf('b') >0) myservob.writeMicroseconds(n);
if(readString.indexOf('c') >0) myservoc.writeMicroseconds(n);
if(readString.indexOf('d') >0) myservod.writeMicroseconds(n);
}
else
{
Serial.print("writing Angle: ");
Serial.println(n);
if(readString.indexOf('a') >0) myservoa.write(n);
if(readString.indexOf('b') >0) myservob.write(n);
if(readString.indexOf('c') >0) myservoc.write(n);
if(readString.indexOf('d') >0) myservod.write(n);
}
readString=""; //clears variable for new input
}
}
else {
readString += c; //makes the string readString
}
}
}
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??
It normally means that the code has not been uploaded to the board correctly and so the sketch running is not the one you think has just been downloaded.
I am new in the world of Arduino. I used Arduino Uno board and tried 6 servo motors with six button and 12 led for controlling turnouts in my N scale layout. but after adding 5 servo no pin left to connect another servo. I had succeed to control 5 servo with 5 button and 10 led. Is any body help me to add one more survo in my project layout. Again I am new in this field not knowing much.
Add a shift register to drive the LEDs instead of using individual IO pins.
Use two daisychained TPIC6C595 to sink current thru 8 LEDs.
Send data into them using shiftOut() command:
// create the two bytes however that hold the LED data, then send it out:
digitalWrite (latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, leds7to0);
shiftOut(dataPin, clockPin, MSBFIRST, leds15to8);
digitalWrite (latchPin, HIGH); // outputs update on this rising edge
Attached picture shows LED strings, single LED/resistor from 5V will work also.
vcjain:
I am new in the world of Arduino. I used Arduino Uno board and tried 6 servo motors with six button and 12 led for controlling turnouts in my N scale layout. but after adding 5 servo no pin left to connect another servo. I had succeed to control 5 servo with 5 button and 10 led. Is any body help me to add one more survo in my project layout. Again I am new in this field not knowing much.
How did you wire 5 servo and 10 led?
What sketcj did you use