So im building a model battleship. and i have 4 cannons 2 before the main tower and 2 after the main tower. Im using 2 servos per cannon 1 to swing vertically from side to side and 1 to raise and lower horizontally. I have been able to write a simple sketch to get 2 servos to swing back and forth but i cant get the up and down to work.
They wiggle and shake but it seems like one action over rides the other. The idea is for the cannons to swing port side stop raise the cannon fire come back to front position and lower 30 deg then swing starboard side raise 30 deg fire and go back to front position and repeat action.
I tried hiring an online service to write a sketch for me but of no avail People..something also Job Guru all kinds of Software Engineers and programmers but it was a waste of time and money.
I need some help writing a sketch that will run the servos off the arduino.
Thanks 
nagato analog.txt (2.4 KB)
How are you powering the servos? 99% of all servo problems come from improper power.
Don't use the arduino 5v pin. The voltage regulator will shut down and cause problems.
Use a proper source. Even 4 AA's for bench work. When you go to put them in your model you can see what fits.
Thanks, yes I am using a dedicated 2 amp power supply on a breadboard
Is it possible to send commands for separate servos and movements with a delay in the command to prevent overload?
Or will I have to program an arduino just for the swinging action and another for the raising action?
Welcome to the Arduino forums. And do not run the power to your servos through any breadboard. Signals are fine and a few milliamps are fine. Wire power to the servos directly.
Build the program on the idea of -when do I want something to happen, when do I want it to stop. All your servo controls should be in functions that can be called using an Arduino pin number index pointing to the pin number in an array of pin numbers. Make functions for rotation servos and a function for elevation servos And corresponding functions to return the servo to it's resting position. Only one function for each operation, using the pin number pointed to by the index value.
Paul
Thanks Paul. Im going to hardwire the power to the leads. I have the concept for the commands its just the codes and symbols that im unfamiliar with.
the attached sketch is a modification of the previous one, it uses pwm pins 3569
I need for the cannons to swing 90 to the left from zero facing forward then 180 back to right (90) past zero. meanwhile the servo for the cannon elevation will raise the cannon when it reaches the end of travel, so i guess its calculating the timing. I also would like for the movement to be gradual, more realistic and less servo like robotic swing.
servo loop.txt (1.11 KB)
I have not used servos, except for the one in the beginners kit a couple of years ago. Play with sample programs till you get the action you want, then add it to your final program.
When posting code use the code tags so what have shows like this. They are above your text when you use a regular reply.
//Creating for loop
//Add the servo library. This library is standart library
#include <Servo.h>
//Define our servos
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;
//servo position in degrees
int servoPos = 0;
void setup()
{
//Define serco signal inputs (Digital PWM 3-5-6-9-11)
servo1.attach(3);
servo2.attach(5);
servo3.attach(6);
servo4.attach(9);
servo5.attach(10);
servo6.attach(11);
}
void loop()
{
//scan from 0 to 180 degrees
for(servoPos = 0; servoPos < 180; servoPos++)
{
servo1.write(servoPos);
servo2.write(servoPos);
delay(100);
}
//now scan back from 180 to 0 degrees
for(servoPos =180; servoPos > 0; servoPos--)
{
servo1.write(servoPos);
servo2.write(servoPos);
delay(100);
}
//scan from 0 to 180 degrees
for(servoPos = 0; servoPos < 180; servoPos++)
{
servo1.write(servoPos);
servo2.write(servoPos);
delay(100);
}
//now scan back from 180 to 0 degrees
for(servoPos =180; servoPos > 0; servoPos--)
{
servo1.write(servoPos);
servo2.write(servoPos);
delay(100);
}
}
Hi,
Welcome to the forum.
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Thanks.. Tom... 