really need help with 4 servos with the arduino

correct me if im wrong but they should go dim to bright or slow blink to fast blink when the analog gos up or down

You're wrong. (well, you did ask! :wink: )

If you're driving the LEDs with servo PPM, you'd be hard-pressed to see the difference in brightness between, say a 1/20 duty cycle and a 1.5/20 duty cycle.

have you tried decoupling caps?

I know its not a problem with the power.

I wish I had your certainty.

Amen. It's worth the try. If I can scavenge up 4 servos I'll try the setup myself... issue is, I dont have 4 potentiometers :frowning:

issue is, I dont have 4 potentiometers

You could just wire the pots wiper to four different analog inputs for just testing or modify you code so that one analog value goes to all four servos.

Lefty

or use the serial test code posted here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1247570790/6#6

afap, you may want to try using this test sktch to see if your problem is related to your sketch code.

^^ Good point mem. Now to find a single pot somewhere.... hmm... Time to take apart an old CD player....

Now to find a single pot somewhere.... hmm... Time to take apart an old CD player

you can usually find useful stuff on a discarded CD player PCB, but for doing this kind of servo test the serial test avoids the trouble of wiring things up :wink:

but theres no fun in typing things in when you can spin a knob ;D

Thank you jezuz for giving it a shot. Well i broke down and ran the servos off 2 battery packs and there was no change. and just for fun i ran the potentiometers and the servos of the battery packs (same problem) then i ran just the potentiometers on the battery packs (same problem) :-[ so im back looking at the code i tryed to rewrite it and i have not tested it yet but ill give it a go in an hour or 2

#include <MegaServo.h>

MegaServo servo1;
MegaServo servo2;
MegaServo servo3;
MegaServo servo4;

int potpin1 = 0;  // analog pin used to connect the potentiometer
int potpin2 = 1;
int potpin3 = 3;  
int potpin4 = 4;

int val;    // variable to read the value from the analog pin

void setup()
{
  servo1.attach(9);  // attaches the servo on pin 9 to the servo object
  servo2.attach(10);  // attaches the servo on pin 10 to the servo object
  servo3.attach(11);  // attaches the servo on pin 9 to the servo object
  servo4.attach(3);  // attaches the servo on pin 10 to the servo object
}

void loop()
{
  val = analogRead(potpin1);            
  val = map(val, 0, 1023, 0, 179);     
  servo1.write(val);      
              
  val = analogRead(potpin2);            
  val = map(val, 0, 1023, 179, 0);    
 servo2.write(val);      
  
  val = analogRead(potpin3);            
  val = map(val, 0, 1023, 179, 0);    
  servo3.write(val);      
  
  val = analogRead(potpin4);            
  val = map(val, 0, 1023, 179, 0);    
  servo4.write(val);      
  
  delay(15);                         
}

think im going to try testing just the signal on the out put pins with leds. correct me if im wrong but they should go dim to bright or slow blink to fast blink when the analog gos up or down. do you think that would work? they would not be using much power at all so if i still have the same problem then i will know for a fax that it is not the power.

here is why i thought that would work. when i first got my arduino i made a night light with it using 4 led of different colors. Each one faded in and out. one day i was hooking up a servo that i got off ebay and had for got that i had the light program uploading on the arduino. dont know why but i put power to it and the arduino ran the light program. The servo started to move all the way to the left (slow) then all the way to the right (slow). I really did not give it much thought at the time but now I was thinking that if i had no problem making led dim then why em i have trouble with the servos. it really should not be hard. anyways that were that came from. and thank you AWOL for saying

You're wrong. (well, you did ask! Wink )

that saves me time. ;D

Hmm, so still no answer huh? what do you mean by 2 battery packs by the way?

-Also, did anyone notice how the forum changes the Winking smiley to the word "Wink" when the smiley gets quoted?

I have to 6 volt batty that are in this kind of plastic pack. i used one to 2 of the servos and one for the other 2. more then enough for the test. here let me try that code i just posted and ill get back you

Oh, I see, alright then, good luck.

ok this should lay the power thing to rest i made this video showing all 4 servos running off the arduino what i did was only used the 2 out puts (9 and 10) put 2 of the signal wires to 9 then the other 2 singnal wires to 10. the servos all moved the same BUT they all moved fine showing that you can run 4 servos of the 5 volts on the arduino. now im sure that if i really started cranking the analogs back and forth real fast it would make them brown out but you can see in the video for the speed i use them they work really good. here is a link to the video. one of the cams is on one side of the house (seen on the tv) the other cam is just a shell and im getting a cam for in very soon ( seen out the window)

I really wish that was the problem,,,,, man i bet its something really dumb that i just over looked :stuck_out_tongue:

code in the video

#include <Servo.h>

Servo myservo1;  // create servo object to control a servo
Servo myservo2;

int potpin1 = 0;  // analog pin used to connect the potentiometer
int potpin2 = 1;
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
}

void loop()
{
  val = analogRead(potpin1);            // 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)
  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, 179, 0);     // scale it to use it with the servo (value between 0 and 180)
  myservo2.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
}

So running all 4 servos off of the +5 is possible. Alright, so the only thing that changed in setup was... the method of controlling the servos? Did you use the megaservo or normal servo library for that vid?

BTW: Very cool setup you have going on, too bad it still doesn't work... no worries - WE WILL GET THROUGH THIS! :wink:

From the video it looks like that MegaServo was not used in that test. Why not run the same test sketch but change the include to and see if it is any different. If the problem returns make sure you are running the current version of MegaServo (release 2). If you don't see a reference to release 2 in the .cpp and .h files then a fresh download from the playground will get you the correct version. Remember that you must delete MegaServo.o after a download to get the new files recognized and used.

I haven't run any servos with an arduino before, so I figured I'd give this a try.

I started by modifying the sketch to this:

#include <MegaServo.h>

MegaServo servo1;
MegaServo servo2;
MegaServo servo3;
MegaServo servo4;

void setup()
{
  Serial.begin(115200);
  servo1.attach(8);  
  servo2.attach(9);  
  servo3.attach(10);  
  servo4.attach(11); 
}

int analogIn = 0;

void loop()
{
  // Read serial input to set the analog input to read.
  if (Serial.available() > 0)
  {
    // read and convert the ASCII values '0'-'5'
    byte in = Serial.read()-48;
    analogIn = constrain( in, 0, 5);
  }
    
  Serial.print("Input: A");
  Serial.println(analogIn);
  int a = analogRead(analogIn);
  Serial.print("Value: ");
  Serial.println(a);
  int val = map(a, 0, 1023, 0, 179);    
  val = constrain(val,70,120);
  Serial.print("S1: ");
  Serial.print(val);
  servo1.write(val);
  Serial.print(", ");
  Serial.println(servo1.read());
  
  val = 70;              
  Serial.print("S2: ");
  Serial.print(val);
  servo2.write(val);
  Serial.print(", ");
  Serial.println(servo2.read());
  
  val = 90;
  Serial.print("S3: ");
  Serial.print(val);
  servo3.write(val);
  Serial.print(", ");
  Serial.println(servo3.read());
  
  val = 120;
  Serial.print("S4: ");
  Serial.print(val);
  servo4.write(val);
  Serial.print(", ");
  Serial.println(servo4.read());

  Serial.println();  
  delay(100);
}

This checks the serial port for a digit to specify when analog input to use, then reads analog pin, maps the value, and uses that value for the first servo. The remaining servos are given constant values. Additionally, it prints the analog input it is using and the current value, the value it is sending to each servo and the value it reads from each servo.

I attached the pot to A0 and the one servo that I have handy to each of the four digital outputs in turn and adjusted the pot each time. This all works as expected, the servo adjust to the correct setting for each output. The pot only effects the first output.

Next I moved the pot to each of the analog inputs and commanded the program to read from the appropriate input, then repeated the test again. Each time it did exactly as it was supposed to.

I would recommend trying this sketch on your hardware, and repeat the tests I've described as closely as possible. if that works, connect four pots and adjust the sketch to read from them instead of using constant values.

wow you really put some work into it, Thank you. The code you wrote and told me to mod is a little over my head. Now if i were to run this program would i have to have it plugged into the usb? My set up is i can keep it plugged into the usb for more then testing. Also when you tell me to mod the code,, i look at it and dont really have a clue on what to change. If you could tell me what to do or make the code have 4 inputs and 4 outs that would help. Sorry i just started this "code" thing less then 3 mounts in my spare time.

BTW: Very cool setup you have going on, too bad it still doesn't work.

Thanks jezuz

I cant get this to verify

#include <MegaServo.h>

MegaServo servo1;
MegaServo servo2;
MegaServo servo3;
MegaServo servo4;

int potpin1 = 0;  // analog pin used to connect the potentiometer
int potpin2 = 1;
int potpin3 = 2;  
int potpin4 = 3;

int val;    // variable to read the value from the analog pin

void setup()
{
  servo1.attach(9);  
  servo2.attach(10);  
  servo3.attach(11);  
  servo4.attach(3);  

void loop()

  val= analogRead(potpin1);            
  val = map(val, 0, 1023, 0, 179);     
  servo1.write(val);      
              
  val = analogRead(potpin2);            
  val = map(val, 0, 1023, 179, 0);    
 servo2.write(val);      
  
  val = analogRead(potpin3);            
  val = map(val, 0, 1023, 179, 0);    
  servo3.write(val);      
  
  val = analogRead(potpin4);            
  val = map(val, 0, 1023, 179, 0);    
  servo4.write(val);      
  
  delay(15);                         
}

And the error message is... ?

You're missing a closing brace on "setup ()".

And an opening one on "loop".

this code runs 3 of the servos like a champ but when i add in the 4th one i got all the same problems, so i chained the code to work the other servo and not the first one i tryed and those 3 ran like a champ. man 1, 2, 3 servos ok, but 4 no way

#include <MegaServo.h>



MegaServo servo1;
MegaServo servo2;
\\ see i cut servo3 
MegaServo servo4; // the frist time i cut servo 4 and left in 3
int potpin1 = 0;  // analog pin used to connect the potentiometer
int potpin2 = 1;

int potpin4 = 3;
int val;    // variable to read the value from the analog pin

void setup()
{
  servo1.attach(9);  // attaches the servo on pin 9 to the servo object
  servo2.attach(10);  // attaches the servo on pin 10 to the servo object
  
  servo4.attach(11);
}

void loop()
{
  val = analogRead(potpin1);            // 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)
  servo1.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, 179, 0);     // scale it to use it with the servo (value between 0 and 180)
  servo2.write(val);      
      
  val = analogRead(potpin4);            // 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)
  servo4.write(val);                        // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
}

Don't forget to check and make sure you are using the latest MegaServo library.