Arduino DC Motor Speed and Direction Control using Relays and MOSFET
In this project we control direction and speed of a 24v high current motor using Arduino and two relays. No power switches are needed for this circuit, just two push buttons and in Potentiometer to control the direction and speed of DC Motor. One push button will rotate motor clockwise and other will rotate it counter clockwise. One n-channel MOSFET is required to control speed of motor. Relays are used to switch the directions of Motor. It resembles with H-Bridge circuit.
- Arduino Uno
- Two 12v relay( 5v relay can also be used)
- Two transistors; BC547
- Two pushbuttons
- 10k resistor
- 24 volt source
- 10K potentiometer
- Three diodes 1N4007
- Connecting wires
Circuit Diagram and Explanations:
Circuit Diagram of this Bidirectional Motor Control Project is shown in image below. Make the connections according to it:
- Connect normally closed terminal of both relays to positive terminal of battery.
- Connect normally open terminal of both relay to drain terminal of MOSFET.
- Connect source of MOSFET to negative terminal of battery and to Ground pin of Arduino UNO.
- Gate terminal to PWM pin 6 of Arduino.
- Connect 10k resistor from gate to source and 1N4007 diode from source to drain.
- Connect motor in between the middle terminal of relays.
- Out of two remaining terminals, one goes to the Vin pin of Arduino Uno and other to the collector terminal of transistor (for each relay).
- Connect emitter terminal of both transistor to GND pin of Arduino.
- Digital pin 2 and 3 of Arduino, each one in series with pushbutton, goes to base of transistors.
- Connect diode across relay exactly as shown in figure.
- Connect Potentiometer’s end terminal to 5v pin and Gnd pin of Arduino respectively. And wiper terminal to A0 pin.
- ** if you have two separate 12 v battery then connect one battery’s positive terminal to the negative terminal of another battery and use remaining two terminals as positive and negative.
Purpose of Transistors:
Digital pins of Arduino cannot supply the amount of current needed to turn on a normal 5v relay. Besides we are using 12v relay in this project. Vin pin of Arduino cannot easily supply this much current for both relay. Hence transistors are used to conduct current from Vin pin of Arduino to relay which is controlled using a push-button connected from digital pin to base terminal of transistor.
Purpose of Arduino:
- To provide the amount of current required to turn on relay.
- To turn on transistor.
- To control the Speed of DC Motors with Potentiometer using Programming. Check the complete Arduino Code at the end.
Purpose of MOSFET:
MOSFET is required to control the speed of motor. MOSFET is switched on and off at high frequency voltage and since motor is connected in series with the drain of MOSFET, PWM value of voltage determines the speed of motor.
Resistance of relay coil is measured using a multimeter which turn out to be = 400 ohms
Vin pin of Arduino gives = 12v
So current need to turn on the relay = 12/400 Amps = 30 mA
If both relays are energized, current= 30*2=60 mA
**Vin pin of Arduino can supply maximum current = 200mA.
Thus there is no over current problem in Arduino.
Working of Arduino Controlled Bi-directional Motor:
Operation of this 2-way Motor Control circuit is simple. Both pins( 2 , 3 ) of Arduino will remain always high.
When no pushbutton is pressed:
In this case no current flows to the base of transistor, hence transistor remains off ( acts like an open switch) due to which no current flows to relay coil from Vin pin of Arduino.
When one push button is pressed:
In this case some current flows to the base of transistor through pressed push button which turns it on. Now current easily flows to relay coil from Vin pin through this transistor which turn this relay (RELAY A) on and switch of this relay is thrown to NO position. While other relay (RELAY B) is still in NC position. So current flows from positive terminal of battery to negative terminal through motor i.e., current flows from relay A to relay B .This causes clockwise rotation of motor.
When other push button is pressed:
This time another relay turns on. Now current easily flows to relay coil from Vin pin through transistor which turn this relay (RELAY B) on and switch of this relay is thrown to NO position. While other relay (RELAY A) remains in NC position. So current flows from positive terminal of battery to negative terminal of battery through motor. But this time current flows from relay B to relay A. This causes anticlockwise rotation of motor.
When both push buttons are pressed:
In this case current flows to the base of both transistors due to which both transistor turns on (acts like an closed switch). And thus both relay is now in NO position. So current do not flow from positive terminal of battery to negative terminal through motor and thus it does not rotate.
Controlling the Speed of DC Motor:
Gate of MOSFET is connected to PWM pin 6 of Arduino UNO. Mosfet is switched on and off at high PWM frequency voltage and since motor is connected in series with the drain of mosfet, PWM value of voltage determines the speed of motor. Now the voltage between the wiper terminal of potentiometer and Gnd determines the PWM voltage at pin no 6 and as wiper terminal is rotated, voltage at analog pin A0 changes causing change in speed of motor.
This Post / Project can also be found using search terms:
- motor using relay and potentiometer resistor
- Arduino motor control with relay and switches
- arduino motor control with relays and switches to reverse direction
- arduino motot rotating clockwise and anticlockwise with 3 seconds between directional changes and PWM