Controlling 4 or 5 servo motors using a push button

Hi,

This is my first post and i am new to electronics and i just started learning arduino.

I am working on a project in which i am trying to control 5 servo motors with a single push button. Is it possible to do that. If yes pls help me with the coding....... When the button is pressed the servo motors should rotate and upon the the release it should go back to original position.

Can any one help...?

Thanks in advance

Sisir

Servo library, 5 instances, should be fine. Make sure your servo power supply is up to the job.

Basic servo momentary button code. Add more servos as desired.

//zoomkat servo button test 7-30-2011

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;

void setup()
{
  pinMode(button1, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(160);
  }
  else {
    servo1.write(20);
  }
}

Thanks to MarkT and zoomkat

i tried to control 2 servos with my arduino it worked fine but if i try to control 5 servos with my arduino, it didnt work. i want to power up the servos externally but i dont know how to do it. im using 5 push buttons and a pot knob to control the servos. And what battery should i use. and how to connect it with servo and arduino.

the servo spec is..

Operating Voltage : 4.8-6.0V

PWM Input Range : Pulse Cycle 20±2ms, Positive Pulse 1~2ms

STD Direction : Counter Clockwise / Pulse Traveling 1500 to 1900µsec

Stall Torque : 3 Kgf.cm(41.3 oz/in) at 4.8V, 3.2 Kgf.cm(44 oz/in) at 6V

Operating Speed : 0.2 sec/ 60° at 4.8V, 0.18 sec/ 60° at 6V at no load

Weight : 38g (1.27 oz)

Size : 41.3*20.3*38.7*48.5*10

Plug Available : FUT, JR

Special Feature : Heavy Duty Plastic Gears, Economy Servo

what battery should i use to control 5 servos of above spec.

what should be spec of the battery... ? sry for my bad english pls help

thanks it advance.

A 4.8v to 6v power supply that can provide at least 1 amp per servo (5 amps if you want to use 5 servos) should be OK. More amps is better.

Battery choice is a little more complicated because it depends how long you want the servos to work for. Any decent sized NiMh or LiPo rechargeable battery should be able to provide enough short term current (for example 4xAA NiMh cells = 4.8v) but they won't drive 5 servos for very long between charges.

The servos will use more current if they have heavy loads to move and if they need to use power to hold a load in position.

Connect the positive of the power supply/battery to the positive wire for all the servos and connect the power supply/battery ground to the servo ground wires and to the Arduino ground. Connect the Arduino signal pins to the relevant servo signal wires.

....R

Robin2: A 4.8v to 6v power supply that can provide at least 1 amp per servo (5 amps if you want to use 5 servos) should be OK. More amps is better.

Battery choice is a little more complicated because it depends how long you want the servos to work for. Any decent sized NiMh or LiPo rechargeable battery should be able to provide enough short term current (for example 4xAA NiMh cells = 4.8v) but they won't drive 5 servos for very long between charges.

The servos will use more current if they have heavy loads to move and if they need to use power to hold a load in position.

Connect the positive of the power supply/battery to the positive wire for all the servos and connect the power supply/battery ground to the servo ground wires and to the Arduino ground. Connect the Arduino signal pins to the relevant servo signal wires.

....R

I tried it as u said

for testing i used only 2 servos. it works fine. im controlling servos with a push button. when the button is pressed servo rotates. when it is released servo comes back to original position. when i press the push button, 1 kohm resistors i used with the button gets heated up and upon the release of the button it gets cooled. if i press and hold it for a long time the resistor gets burned. what should i do to avoid heating up of the resistors. the battries im using are 4*AA (1.5V)EVEREADY batteries=6V

You must have something seriously wrong with your wiring if the resistors get hot, or noticeably change temperature at all.

Post a diagram of how you have everything connected. A photo of a clear pencil sketch will be fine.

...R

Robin2:
You must have something seriously wrong with your wiring if the resistors get hot, or noticeably change temperature at all.

Post a diagram of how you have everything connected. A photo of a clear pencil sketch will be fine.

…R

OK --- I should have said a clear photo of a clear pencil sketch :) More seriously reduce the size of the pictures to 640x480 - it makes them easier to view.

It's a good diagram, but very hard to see. If it is really wired up like that I can't see how the resistors get hot or even warm. Are you quite sure they are 1k resistors - check them with a multimeter.

Your diagram doesn't show how the Arduino is powered. Perhaps it's from the USB connector.

Alkaline batteries probably won't provide enough current. I mentioned rechargeable NiMh cells.

You have resistors to pull the switch lines LOW and the switch pulls them HIGH. The Arduino has internal pullup resistors - pinMode(12, INPUT_PULLUP) - and then you can wire the switch to pull them LOW. That way you won't need the 1k resistors.

I would avoid using PIN13 if you can because it is connected to the Arduino onboard LED.

...R

Basic servo external wiring setup.

antonpanofsky: Is it possible to manage a similar situation with Arduino ? Thank you in advance for your suggestions ! Feel free to ask for more details

Controlling 100 things with an Arduino is very different from 5 or 10. I think you would get better advice if you delete your post here and start your own Thread. Also the advice for you will just confuse this Thread.

...R

[quote author=Robin2 link=topic=209138.msg1664113#msg1664and 13 date=1396553522] OK --- I should have said a clear photo of a clear pencil sketch :) More seriously reduce the size of the pictures to 640x480 - it makes them easier to view.

It's a good diagram, but very hard to see. If it is really wired up like that I can't see how the resistors get hot or even warm. Are you quite sure they are 1k resistors - check them with a multimeter.

Your diagram doesn't show how the Arduino is powered. Perhaps it's from the USB connector.

Alkaline batteries probably won't provide enough current. I mentioned rechargeable NiMh cells.

You have resistors to pull the switch lines LOW and the switch pulls them HIGH. The Arduino has internal pullup resistors - pinMode(12, INPUT_PULLUP) - and then you can wire the switch to pull them LOW. That way you won't need the 1k resistors.

I would avoid using PIN13 if you can because it is connected to the Arduino onboard LED.

...R [/quote]

Hi R As u guessed those were not 1k resistors. I replaced them and im powering the arduino with usb connector. It doesn't work Even if I use 4×AA rechargeable NiMH batteries. At last I used 6V Rechargeable sealed lead acid battery. Its working fine. No heating up of resistors . The battery spec is 6v and 4.5 Ah/20Hr.will this battery damage the arduino and servo.?

6v should be fine for the servos.

If it is also powering the Arduino how is it connected to it?

...R

Robin2: 6v should be fine for the servos.

If it is also powering the Arduino how is it connected to it?

...R

im powering the arduino separately with usb connector. how to power up the servos and arduino with the same 6v battery

Connect the positive of the power supply/battery to the positive wire for all the servos and connect the power supply/battery ground to the servo ground wires and to the Arduino ground. Connect the Arduino signal pins to the relevant servo signal wires.

i've powered up the servos as u said in the above quote. how to power up the servos and arduino with the same 6v battery.

It's not easy to power an Arduino from a 6v battery. I think the power input jack needs a minimum of 7v and obviously the Arduino circuits need a carefully regulated 5v supply. And, generally, 7v is too high for the servos.

You could use a higher battery voltage (in the 7 - 12v range that the Arduino power jack accepts) and use a suitable voltage regulator to produce 5v or 6v for the servos.

However you need to be sure your power source can supply sufficient short term current so that loads on the servos don't cause the Arduino voltage to fall.

...R