How to connect more that 16 servo motors in arduino mega 2560?

I saw that we can connect 15 servo motors directly to PWM channels. But after going through the material found that timer0 is used for delay. Which pins can I attach the servo motors to? Which pin I cannot access after connnecting more that 16 servos? I case I want to go for 32 servos or more how is the interfacing done? Please let me know soon....thanks

Search for servo library - I think it allows for up to 45 or 48 servos on a Mega.

I did search for the library. It allows 48 but i wanted to know on what pins and how to utilize the library. Do we need to make any changes in the library. If we use more than 12 servos we can't use certain pins. So I wanted to know which pins. Also i wanted to control 4 motors simultaneously so is it possible using the library?

You may want to use a stand alone servo controller controlled by the mega.

rahulshah99999: I did search for the library. It allows 48 but i wanted to know on what pins and how to utilize the library. Do we need to make any changes in the library. If we use more than 12 servos we can't use certain pins. So I wanted to know which pins. Also i wanted to control 4 motors simultaneously so is it possible using the library?

Any pin whatsoever. No difference in use from the Uno. The only side effect is certain timers are used, so the PWM pins associated with those timers can no longer be used for analogWrite(). Read the Servo library source code to find out which timers are used in which order.

If the servos are just used to position things and once in place will stay there without power just using their own internal friction you could arrange for the Arduino only to switch on power to the servo it needs to move. That way a single servo output could control many servos.

...R

But don't you need to refresh the servos after some amount of time to hold the values???

Servos don't need to be refreshed unless there is a force on the arm big enough to overcome the internal friction. This is only true, of course, if the power has been disconnected from them.

...R

Robin2: If the servos are just used to position things and once in place will stay there without power just using their own internal friction you could arrange for the Arduino only to switch on power to the servo it needs to move. That way a single servo output could control many servos.

...R

Apart from all the pins controlling MOSFETs or whatever that power on and off individual servos?

Could power them all in bulk, only making power available when you needed a position change? I don't if the servo's would all jitter a lot or something when the power came back and they each resynced to the control signal.

As I recall when I experimented with this they didn't jitter - but I was careful to remember the position and output it again when (before?) power was reconnected. It would only take a few minutes for the OP to test this.

You could switch power for 256 servos with 8 Arduino pins and a de-multiplexer. And as this is only a solution for low power situations a cheap transistor should be sufficient to amplify the switching power.

...R

Why bother demuxing? If you just need to have the output pulse going before you apply power, just use 1 MOSFET and power all of them up/down together. I suppose breaking them into groups would allow lower current draw & prevent all moving at once. Depends on the use I suppose.

As frequently happens I haven't been clear enough.

What I have in mind is that the signal lines of all the servos are connected together and to a single Arduino pin from which the servo.write() signal emerges. Then you can select whichever servo is to respond to the signal by switching on it's power only. It's just a way to operate lots of servos if you only have a few Arduino pins available.

For example I have a servo to move an electrical contact arm up and down. When down it is available to make contact with a moving table and act as a limit switch. If the table needs to move further the servo can lift the arm out of the way. There is no load on the servo in either position so it doesn't need power or signal to hold position - and it doesn't need to move very often.

...R

I would think that approach would require 48 sets of fairly hefty current switching transistors, MOSFETs, whatever, depending on the servo needed. Vs 1 really hefty switch and a simple set of logic level demux chips. Either way could be made to work.

If I understand you correctly you are thinking of switching power on and off for all servos with a single switch and using a demux to route the servo control signal to a particular servo.

The problem I foresee with that is that all the other servos will feel like moving (because they are powered up) but won't know what to do because they have no signal.

If the servos have very little load on them they will only draw a small current and won't need hefty switches.

...R

CrossRoads: Vs 1 really hefty switch and a simple set of logic level demux chips.

That's why I was asking about jitter as they powered up earlier. I think try with one two both ways with representative components and see how it works.