Home > Basics > How to Connect a Motor to Arduino?

How to Connect a Motor to Arduino?

How to Connect a Motor to Arduino? To achieve this analytical purposes,you need to use additional components since most motors require more direct current rating and voltage than the Arduino can supply directly. Below are common methods for connecting common type of motor:

Components You Might Need

Arduino ( Arduino Uno, Nano, etc.)

Motor (DC motor, stepper motor, or servo)

motor driver (e.g., L298N module, L293D) or transistor (e.g., TIP120, mosfet)

Diode (e.g., 1N4007) for back-EMF protection (for DC motors)

External power supply (for DC motors requiring >5V/500mA)

Breadboard and jumper wires.

 L298N

1. Connecting a Small DC Motor (Simple On/Off or Max Speed Control)

Circuit diagram:

Use a transistor (TIP120) or MOSFET to switch the DC motor on/off.

Add a flyback diode across the DC motor to protect the electronic circuit from voltage spikes.

Wiring:

1.Connect the DC motor between the transistor’s collector (drain) and the external power supply (+).

2.Connect the transistor’s emitter (source) to ground.

3.Connect the transistor’s base (gate) to an Arduino PWM pin (e.g., Pin 9) via a 1kΩ resistor.

4.Connect the diode in reverse bias across the motor (cathode to +ve side).

5.Link the external power supply’s ground to the Arduino’s GND.

Code Example (Motor Speed Control):

int motor to Pin = 9;  // PWM pinvoid setup() {  pinMode(motorPin, OUTPUT);}void loop() {  analogWrite(motorPin, 128);  // 50% speed (PWM value 0-255)  delay(3000);  analogWrite(motorPin, 0);    // Turn off  delay(1000);}

 

2. Connecting a DC Motor with Bidirectional Control

Circuit:

Use an H-bridge motor driver (e.g., L298N or L293D) to control motor direction and current speed.

Wiring (L298N):

1.Connect Motor Terminals to the driver’s output pins (OUT1/OUT2 for Motor A).

2.Connect the driver’s IN1 and IN2 to Arduino digital pins (e.g., Pin 8 and Pin 7).

3.Connect the driver’s ENA (Enable A) to an Arduino PWM pin (e.g., Pin 9) for motor speed controller.

4.Power the driver with an external supply (e.g., 9V battery) via the 12V and GND terminals.

5.Link the driver’s ground to the Arduino’s GND.

Complete Code Example (Direction control + Speed):

int enA = 9;   // PWM pinint in1 = 8;int in2 = 7;void setup() {  pinMode(enA, OUTPUT);  pinMode(in1, OUTPUT);  pinMode(in2, OUTPUT);}void loop() {  // Rotate clockwise at 75% speed  digitalWrite(in1, HIGH);  digitalWrite(in2, LOW);  analogWrite(enA, 191);  // 75% of 255 ≈ 191  delay(3000);  // Rotate counter-clockwise at full speed  digitalWrite(in1, LOW);  digitalWrite(in2, HIGH);  analogWrite(enA, 255);  delay(3000);}

 

3. Connecting a Servo Motor

Wiring:

1.Servo’s negative wire and positive wire (usually orange/yellow) to an Arduino PWM input pin (e.g., Pin 9).

2.Power (red) to Arduino 5V (for small servos) or an external supply.

3.Ground (brown/black) to Arduino GND.

How to Connect a Motor to Arduino? To achieve this analytical purposes,you need to use additional components since most motors require more direct current rating and voltage than the Arduino can supply directly. Below are common methods for connecting common type of motor:

Complete Code Example:

#include Servo myServo;void setup() {  myServo.attach(9);  // Pin 9}void loop() {  myServo.write(0);    // 0° position  delay(1000);  myServo.write(180);  // 180° position  delay(1000);}

Key Considerations

Power Supply: Use an external power source for motors drawing >200mA.

Ground Connection Diagram: Always link the Arduino ground to the motor driver/external supply ground.

Voltage Matching: Ensure the motor’s voltage matches the power supply.

Heat Dissipation: Use heat sinks for high-current motors/drivers.

By following these steps, you can safely control motors with an Arduino!

Prev:  What is a MAP Sensor?
Next:  Effect of Miller Capacitance:An Invisible Challenge in High-Frequency Circuit Design
Would you like more details or pricing on the components mentioned above? Please complete the form below.
Submit Inquiry / Request Info