Hello,
I am trying to control a 12V motor using an Arduino by turning it ON and OFF. I am using a transistor and a relay to help me in that. Here is a picture of how I am doing that in a pdf format:
Arduino project.pdf (79.3 KB)
Please inform me if you can't open the pdf to see the schematic. I am powering my Arduino with a 7805 regulator since I need to use a 12V battery for the motor. The 5V pin of the Arduino is connected to the output of the regulator and two GPIO pins are used where one is used as an indicator of something and the other as a supply to the base of the NPN transistor. When I tried turning ON the transistor with GPIO pin of the Arduino, the relay was turning ON and OFF and it wasn't stable, so the motor wasn't running. Also the Arduino built in LED was switching ON and OFF. I then removed the regulator, powered the Arduino with a cable from my computer and used the 5V pin of the Arduino to power the relay coil. With this configuration it works ! Can someone help me in this please.
It appears to be an easy fix. The answer is on the first page of the data sheet. You need to install the correct size of capacitor and it must be within about 1/2" of the regulator or it will possibly oscillate, that varies between manufacturers. You can take the easy way out and use an inexpensive buck converter.
Why not use a proper transistor to turn the 12 volt motor On and Off?
Do you mean a MOSFET ?
Are you saying that by exchanging the 0.1uF capacitors it will work, or alternatively I can use buck buck converter instead of a voltage regulator ?
If so what is the capacitor that you suggest me to use ?
I do not know what brand of regulator you have, you need to check that manufacturers data sheet for a correct value, they are not all the same. The buck converter will work just fine and give you a longer battery life.
For the motor you can use a N-Channel MOSFET with the appropriate rating and replace both the transistor and relay. You will gain a lot less EMI (Electromagnetic Interference) when switching. I do not know what arduino you have, that will determine the maximum Vgs rating you will need.
By using just a MOSFET to turn on/off the load, wouldn't that burn the MOSFET because of back EMF that occurs with heavy loads ? and do you suggest a MOSFET that will work well with 12 V.
I am using an Uno right, but going to change to Nano later.
You can use a MOSFET with an adequate avalanche rating and or add a free wheeling diode. The data sheet will give you the MOSFETs UIS rating. If it is not a high frequency no problems. If you are doing PWM and want to calculate the thermal for an approximation use the (RDSon * 2) for the back EMF. Rise and fall times also figure into this. Hopefully this helps. I generally do not use heat sinks with MOSFETs, I just use lower RDSon devices. The thermal rise calculations will let you know what you need. For one or two systems the cost of the MOSFET is minor.
I have a 2N7000 MOSFET. I looked in its datasheet and I found that its drain-source breakdown voltage is 60V. What other information should I look for in the datasheet to check whether its suits my application ?
I am planning to make a PWM with it. Its RDSon is 6 ohm as a maximum value. Does it suits my application ?
Can you please help me.
@yousef_khamis
For your application, you can power the UNO with 12V through Vin or the barrel jack, so no need for the 5V regulator.
If you tell me how much current the motor needs I'll tell you what transistor to use.
... but not recommended, especially if his Uno is a clone. Using of external regulator is preferred.
@jim-p : this is not for the sake of arguing with you, but only a recommendation for OP.
That MOSFET would drive the relay with a 5V arduino but not the motor.
Next you want to look at its current rating of your motor and be sure it is well below the maximum of the MOSFET. Using a bigger MOSFET only costs a little bit more and saves heatsinks and toasted fingers. Check the Vgs, it should be below about 3.5V for your 5V Arduino. The Vgs rating is the turn on voltage, not the fully enhanced voltage, that is on a graph on the MOSFET data sheet. Heat may or may not be a problem I have no idea what the motor current is.
I have posted the classic image of a MOSFET driving a motor. You will see this a lot and it is Wrong. R18 belongs on the PWM Output side of R17 not the gate. The diode needs to be rated at the motor current. If you use an avalanche rated MOSFET it may not be needed.
Please do not power the motor with the Arduino that is asking for problems. Many do it and get away with it but not everyone. Use the buck regulator for the motor and feed the Arduino via the barrel jack with 12V. I have posted my Crispy Critter rules below, they do not guarantee you will not brake something but definitely help minimize that possibility.
Gil's Crispy Critter Rules, they apply to processor hardware:
Rule #1. A Power Supply the Arduino is NOT!
Rule #2. Never Connect Anything Inductive to an Arduino!
Rule #3 Don't connecting or disconnecting wires with power on.
Rule #4 Do not apply power to any pin unless you know what you are doing.
LaryD's Corollarys
Coro #1 when first starting out, add a 220R resistor in series with both Input and Output pins.
Coro #2 buy a DMM (Digital Multi-meter) to measure voltages, currents and resistance.
Violating these rules tends to make crispy critters out of Arduinos.
Now the most important thing is to relax and have fun with this.
Hello,
thank you for notifying me about the current rating and the Vgs of the MOSFET. However, I have some doubts:
- Can't I use the MOSFET to drive the motor directly and get rid of the relay ? since the MOSFET can handle the 12V easily.
- Why the schematic in the image is wrong ? is it because the MOSFET is driving the motor directly ?
- Regarding the motor, it's a 12V motor so I don't need a buck converter to reduce it. About its current, I haven't bought it yet and I am using another motor for testing which draw 300mA.
- I think I can't power the Arduino with a 12V based on what I have read, since the battery's voltage might increase when it is fully charged and this will put more stress on the on-board regulator.
Can you please help me clear these doubts.
When I try to turn ON the transistor with an Arduino's GPIO pin by supplying the transistor's base it doesn't work. However, when I do that with the 5V from the regulator it works ! any idea why is this happening.
Which Arduino are you using? The relay coil draws about 72 mA, after the regulator drops 7V from 12V and 72 mA is drawn through it, it will have to dissipate 0.5 Watts, half it's 1 Watt rating. Then it has to power the Arduino MCU and indicator LEDs, so the regulator is operating right at the verge of overload.
Since you have a 12V supply, why not use a 12V relay?
You have a 1000Ω resistor in the transistor's base circuit, that may not provide enough current to fully saturate it. A 390 to 560Ω might work.
Yes. You can also use a transistor.
Regarding the motor, it's a 12V motor so I don't need a buck converter to reduce it. About its current, I haven't bought it yet and I am using another motor for testing which draw 300mA.
Correct, no need for a buck
I think I can't power the Arduino with a 12V based on what I have read, since the battery's voltage might increase when it is fully charged and this will put more stress on the on-board regulator.
That is true
Yes, it's because the emitter of the transistor is not connected to the Arduino GND
This circuit will work:
Looking at how it is drawn R17 forms a resistor divider with R18. That drops the voltage applied to the gate thereby lowering the 'gain' of the MOSFET. Connecting R18 from the PWM output pin to ground eliminates the voltage and applies more voltage to the gate.
Most of the time it will work depending on the load etc. The MOSFET will directly drive the motor from 12V. You MUST have all the grounds connected together. The motor is inductive but is isolated from the Arduino by the MOSFET.
You can power the Arduino with 12V but there is not much left from its 5V regulator. Connecting anything more then maybe a LCD display and backpack will give you problems. If you decide to get the buck converter adjust its output to about 7.5 volts then use that to power Vin.
Mmm, it makes sense, a 12V relay will relax the regulator. The Arduino was drawing around 30-40mA and with the relay the total current becomes around 70-80mA (as the 12V power supply shows this mean that the regulator current is also into consideration). I was a bit wondering why is it not more than this since I know that the relay draws more.