Hello there! First and foremost, I am totally new to circuitry and coding. I wanted to see if what I have is, firstly, plausible, and secondly, able to be modified to control the speed of the motors. I have searched around and I have found that I may need a Motor Drive Controller Board? Would that mean I need to have three boards connected to 1 or more Arduinos?
Thank you for your help in advance.
Here is my code: I purposely have it set to have the three motors run at different times when the switch is activated.
You should not power motors from the Arduino (USB or 5V regulator). Unless the motors are very small the motors will pull enough current to cause the voltage to sag and the Arduino to reset or the voltage regulator to shut down. Power the motors with an external supply of the motors rated voltage and enough current capacity to supply the motor stall current times 3.
It looks like your flyback diodes are backwards. The banded end goes to V+.
Though not strictly necessary, a resistor (around 220 Ohms) between the MOSFET gate and Arduino output will protect the output pin and a 10K from the Arduino output to ground will prevent the MOSFETs from turning on, unexpectedly, after a reset or restart.
So... What you have is working as expected, right? I'm assuming those are MOSFETS? You should add a couple of resistors. [u]Here is a MOSFET motor driver schematic[/u] with an explanation.
You can reduce the speed with [u]analogWrite()[/u] and you don't have to change the hardware setup, but I would recommend adding the resistors. (You will to make sure you're connected to analog-capable pins.)
An H-bridge motor driver would allow both speed-control and motor reversal, but you don't need that if you don't need to reverse.
analogWrite() isn't true analog... It's [u]PWM[/u] which is actually better for DC motor-speed control.
If you want to set a certain RPM, you need some kind of speed-sensor & feedback. That gets trickier, especially if you have multiple motors.
That was the first code I tried that worked. I thought it looked a bit bulky.
groundFungus:
You should not power motors from the Arduino (USB or 5V regulator). Unless the motors are very small the motors will pull enough current to cause the voltage to sag and the Arduino to reset or the voltage regulator to shut down. Power the motors with an external supply of the motors rated voltage and enough current capacity to supply the motor stall current times 3.
So are you saying use an outside power source, not connected to the Arduino, for the motors? Sorry. Like I said I'm new, so I'm not quite understanding what you're saying. To specify the motors, I am using motors from an airsoft gearbox to power the gearbox alone (not the airsoft rifle). I'm not sure whether they are small from your perspective...
DVDdoug:
So... What you have is working as expected, right?
It is working exactly as expected. I will add resistors and I will look into adding the analogWrite() code.
GazeIntoTheOven:
So are you saying use an outside power source, not connected to the Arduino, for the motors?
Almost: you must share the grounds between the two.
Ground is the shared reference, if you don't share this the PWM won't work.
Don't share the positive supply voltage, even if both are nominally the same, because they're never really the same.
wvmarle:
Almost: you must share the grounds between the two.
I've run into a problem. Either the motors don't have enough power or my code isn't working in real life. I've set up my Arduino/breadbox the exact same as my picture above and the code is the same, but my motors aren't running how they should. They ran once but never ran again and sometimes I can hear the motors clicking to try to run. I chose 220 resistors between the Arduino output and MOSFET gate and 4001 diodes. Are those completely wrong to use? I also used a 9V for the Arduino and a 9.6 for the motors. Should I have one battery for each motor?
wvmarle:
What kind of battery? You sure that's a kind that can supply sufficient power for the motors?
Have you tried running it off a wall power supply?
The motors are from an airsoft gearbox so I used my airsoft battery. Its a 9.6V/2200mAh. I think I should try to connect all three to three different sufficient batteries. If that does not work, I will try to run it from a wall power supply.
If you fry your Arduino, what does that mean in this specific case? I connected the batteries each separately to their respective unit (one to arduino, one to each of the motors) and the ground of each to the breadbox. Is there something I am doing wrong? Plz save a fellow nerd
GazeIntoTheOven:
If you fry your Arduino, what does that mean in this specific case?
Usually that it doesn't work any more.
I connected the batteries each separately to their respective unit (one to arduino, one to each of the motors) and the ground of each to the breadbox. Is there something I am doing wrong? Plz save a fellow nerd
Nothing obviously wrong in the very little information given.
Mind that breadboards can in general not carry much current, as a rule of thumb 500 mA is the maximum. That's a small number for motors.
The picture above does show them backwards but I corrected them before trying.
TomGeorge:
Hi,
Do you have a DMM?
Tom...
I do not. I see that it checks the power between two connections. Should I use it before I try to complete the project?
wvmarle:
Usually that it doesn't work any more.
Nothing obviously wrong in the very little information given.
Mind that breadboards can in general not carry much current, as a rule of thumb 500 mA is the maximum. That's a small number for motors.
So are you saying the breadboard might have been one of the reasons it didn't work?
A multimeter is an essential tool for this hobby. Measure voltages, resistance, continuity... lots of things you need to verify a circuit, and find faults.
GazeIntoTheOven:
So are you saying the breadboard might have been one of the reasons it didn't work?
Absolutely.
They're very convenient to quickly try out stuff, but you have to be very aware of their limitations, which include current limitations (couple hundred mA), sometimes poor connections (especially when using thin wires after using thick wires in a hole - try another hole), and high stray capacitance (something you may run into with more advanced projects - at other times you have to make sure to keep a free row between two rows).