Multiple L293D and DC motors on one arduino mega

Hello hello everyone,

I working on a project to control 30 DC motors with encoders at the same time, on the same computer.
I'm projecting to use 3 arduino mega connected through I2C (1 master and 2 slaves), and connect 5 L293D on each, each one controlling 2 DC Motors ( 50:1 FIT0482 Motoréducteur 50:1 FIT0482 DFRobot - Motoréducteurs + encodeurs | GO TRONIC).

My first question is, is this the best way to control this number of motors with the smaller number possible of arduino ? I did a lot of research and I didn't found a lot of project with this amount of motor at the same time. I allready tested motor shields but it seems that you can control 4 motors max with this option, so I would have to buy a lot more arduino (but it's still an option knowing that I2C is really incredible).

Second question is, how exactly would I power up all this ? The motors are 6Vcc 170mA (when charged), and I don't know if I would have to power each arduino separatly or if there is a way to connect all that stuff.

Just to specify, I also know that I will have to protect all with diodes if I don't want to start a fire.

Thanks for your help ! To be honest finding that it could work would relieve a lot of stress :slight_smile:

I forgot to add that I was thinking at first to power up 5 L293D (so 10 6Vcc motors) with this kind of power supply : https://www.amazon.fr/Aihasd-Breadboard-d-alimentation-Arduino-soudure/dp/B01H2YKXBC/ref=sr_1_6?__mk_fr_FR=ÅMÅŽÕÑ&crid=21D5TBD60D5YD&keywords=module+alimentation+5v+breadboard&qid=1667565911&sprefix=module+alimentation+5v+breadbord%2Caps%2C70&sr=8-6

I'm just realizing maybe it may not be enough...

Start by counting the number of Arduino pins required. To control one motor, on/off in one direction = 1 pin. Both directions, 2 pins. Read encoder, 2 pins.

Power the motors completely separately from the Arduinos, but connect all the grounds.

The power supply you linked (700 mA maximum current) may handle ONE motor, but certainly not two or more. The motor start/stall current is typically 10x or more times the free running current.

1 Like

Why? a Mega or even a Uno could control all the motors with I2C control.

The L2293 is a really rubbish very old chip, please find a better one.

Nothing to do with fires, it is to suppress the interference that a DC brushed motor would generate when turning it off. Fires are when you try and draw too much current somewhere.

As far as I have ever seen you do not charge a motor!

With a large external power supply.
However you need to know the stall current of the motors, the running current tells you not very much useful. Measure the resistance of the windings and then use the voltage you plan to run them from with ohms law to find the stall current.

Adding processors because you need more pins is a rookie mistake. There are better ways. For instance I2C IO expanders like MCP23008 ( each adds 8 GPIO) or the MCP23017 (each adds 16 GPIO) or the 74HC595 SPI shift register make more sense than multiple Megas.

The starting current (stall current) of a motor can be up to 10 times, or more, the running current of the motor. You should base your current calculations on stall current if you want reliability.

The L293 motor drivers are ancient and very inefficient drivers. They will drop from 2V to over 4V of the motor supply voltage and dissipate that power as heat. With 30 motors that is a lot of wasted power. There are more efficient modern motor drivers available at reasonable prices.

1 Like

In therm of pin connection if my calculations are correct it can work :

1 motor with encoder = 2 digital pins on the arduino (for the encoder)

1 L293D = 6 digital pin

1 L293D + 2 motors = 10 digital pin connections (including 2 PWM) = "A"

5 x "A" = 50 digital pin connections (including 10 PWM)

An arduino Mega 2650 has 54 digital pins whereas 15 supports PWM so I chose this one.

You do not seem to be not counting pins correctly.

To control one motor in two directions, plus read the encoder = 4 pins

30 motors => 120 pins

But yes, three Mega2560 could in principle do this, except that one Mega will not be able to keep up with 10 rotary encoders.

Thanks to all of you, it's very comforting to have experimented people "showing the way" for a rookie like me.

Following your advices I changed the initial list to :

30 motors (each 4pin for control and encoder) = 120 pins
An Arduino mega = 54 digital pins
A MCP23017 = 16 digital pins
An arduino mega + 5 x MCP23017 = 134 digital pins

As motor driver I found the L298N, it has better comments than the previous one and has a full equipped version (with diode,ect..) : L298N pdf, L298N Description, L298N Fiches technique, L298N view ::: ALLDATASHEET :::

I'm working on the power supply.

No it is still as old and decrepit as your original choice.

This thread is devolving into design by forum committee, which is surely a recipe for disaster for the OP, and frustration for the helpers.
@absent666 You really need a reality check here. Please specify what you're doing, in detail, with the 30 motors, including what they are doing, expected feedback loop response times, interactions between the motors, etc. Anybody can 'specify' a 'smear' of IO pins that will give you the number of pins you desire on one, 2, 4 or 100 Megas or Nanos, but from what I see in this thread NOBODY knows whether the things connected to those IO pins will do what you want, including you, I suspect. So please 'fess up' - what's the application? Describe it in English, show a block diagram of the system (a schematic is too much to ask for at this point, but give us a hint).
Without a deep breath and careful thought right now, you're headed into the weeds.

The idea is doing this :

But with 30 motors silmutaneously, with a different "target" (rotation distance with the encoder) for each one of them.

The steps are : send a value manually to each motor (integer) to be their target (for each motor approximately at the same time, can be one by one relatively fast), wait for the motors to turn to their targets (it doesn't have to be really fast), stop at this point untill I send 0 as new target to all the motors, so they rotate back to 0.

I'm sincerely sorry if i'm not clear enough to describe the project. There are many reasons (I'm a newbie, never had class or people to explain, only coded for pleasure, not the best with english...) but the major one is that this project is not for me but for work, and because I don't find any references or similar projects I don't feel good fully explain it on internet.
If you can't help me because of that reason I understand, I was just hopping someone could just show me the good direction, and you already did a lot !

If the code part can help you understand I already posted something about it :

Happy?
Did you get any new information? Because I didn't.

Ok I see thanks, I'm just wondering where can I find this kind of information ? Like why is it this bad ? What is a good one ? What are the ameliorations, or the changes compare to a more recent one ? And is a recent one better juste because it is recent ??

Because it tells us nothing new. Specifically why you want to do this and what effect are you hoping to get. What are the motors going to drive?

You seem to have no idea even what sort of motor you want to use. Or rather no awareness of the limitations of each motor type. You can't control a normal DC motor with an encoder on the end to precisely position that motor. You don't even say what sort of encoder is on the end of this motor. Is it an absolute encoder or is it an incremental encoder?

You need either a stepping motor or a servo motor to control the absolute position. And if it is a stepping motor you need some way of calibration the position of each motor on startup.

Also while you may wish to control 30 motors, things in electronics do not simply scale and it is not just a case of doing the same thing 30 times. The power supplies require more current, there is more EMI (Electro Magnetic Interference ) affecting the overall running of the processor, and the code you need to use is a step above the code you are used to using. It has to follow a state machine of the type blink without delay IDE example.

So while we try and help you, I can't help but feel you are way out of your depth trying this project at your current state of knowledge. I would advise you get a lot more experience before you tackle such a huge project.

I'm really glad of your answer I understand better your point of view and in a way, mine. :slight_smile:

I know what motor I want to use, I already have one, and it's this one (the one I told you in the first comment) : 50:1 FIT0482 Motoréducteur 50:1 FIT0482 DFRobot - Motoréducteurs + encodeurs | GO TRONIC

Unfortunatly the data sheet of this motor with integrated encoder does not stipulate what kind of encoder it is, but I know (because I tried) that it work with the code I shared to you, with enough precision for my project.

For the power supplies and code part, I completely agree with you : it is for now out of my league. But this is the reason I'm searching for help here : I believed you could just show me the resources and the steps I have to pass by to achieve my goal. I know there is a lot of work and to learn for me, but that's what I enjoy about my work !

Oh also my last questions were about your answer for the L298N. I can't find a clear explanation about the different motor drivers.

Either the L293D or the L298N can handle the current required by the tiny motor linked in post #15.

But the Mega probably does not have enough computing power to control 10 of them with encoders. Maybe not even four.

Start small and get one motor working exactly as you want, then add another, etc.

It is an incremental encoder, that means that while you can control the relative position of the motor you can't control the absolute position of the motor, that is it will be different each time you power it up. You said that you tried this and it worked, did you not notice this?

In that tutorial the encoder is read in a rather naive way. And is not scalable. That means it is not suitable for making 30 of these because you will never be able to read each encoder quickly enough to catch the transitions.

You still haven't said what you want the motor to drive and why you want to do this.

The choice of motor driver will depend on what motor you eventually end up using. Don't assume it is the motor you have at the moment.

At this moment I am thinking that a servo would be the simplest to use and control.

@Grumpy_Mike Yes, actually. I confirmed to myself that the OP is swimming bravely in the deeps, eyes fixed on the island ahead, totally unaware of the sharks in the water around him. I only hope that this comment, and yours, will help to make him aware that this isn't an "well, I slept at Holiday Inn last night, so I will prevail" kind of moment.
@absent666 You are in so far over your head with this that explaining just how deep the waters are, particularly in an industrial/employment environment, is beyond the scope of this forum. You may, indeed, consume the forum oxygen for quite some time pumping out question after question, answering question after question, until at some point your project self-destructs, the 'ears' of the forum become deaf, or your employer runs out of rope for you.
This is just my opinion, take it for what you paid for it as you wish. I'm checking out now.

thanks you two again for your time @Grumpy_Mike @camsysca. I answer a last time and I promise I will stop consuming the forum oxygen and yours.

Yes I noticed this, that why I find important to tell the motors to go back to 0 each time I use them. I chose this model for their size and their price, and I don't know if it's because I'm in France but I can't find similar model with absolute encoder.

The motors are used to spin 3D printed screws (about 1cm diamter), one for each motors, with no real weight on them (only the plastic screw itself) or resistance. They need to be able to make multiple full rotations. Think of it like an art project if it helps you.