For a DC motor with a motor driver (e.g., L298N), the pin configuration is as follows:
Pin Name | Description |
---|---|
IN1 | Input pin 1 for controlling motor direction (connect to microcontroller GPIO). |
IN2 | Input pin 2 for controlling motor direction (connect to microcontroller GPIO). |
ENA | Enable pin for motor (can be connected to PWM for speed control). |
VCC | Power supply for the motor (typically 5V or 12V). |
GND | Ground connection. |
OUT1 | Output pin connected to one terminal of the motor. |
OUT2 | Output pin connected to the other terminal of the motor. |
Connecting the Motor and Wheels:
Wiring the Motor to a Driver:
Controlling the Motor with Arduino:
// Define motor driver pins
const int IN1 = 9; // Motor direction control pin 1
const int IN2 = 10; // Motor direction control pin 2
const int ENA = 5; // PWM pin for speed control
void setup() {
// Set motor driver pins as outputs
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(ENA, OUTPUT);
}
void loop() {
// Rotate motor forward at 50% speed
digitalWrite(IN1, HIGH); // Set IN1 high
digitalWrite(IN2, LOW); // Set IN2 low
analogWrite(ENA, 128); // Set speed (0-255, 128 = 50%)
delay(2000); // Run for 2 seconds
// Rotate motor backward at 75% speed
digitalWrite(IN1, LOW); // Set IN1 low
digitalWrite(IN2, HIGH); // Set IN2 high
analogWrite(ENA, 192); // Set speed (0-255, 192 = 75%)
delay(2000); // Run for 2 seconds
// Stop the motor
digitalWrite(IN1, LOW); // Set IN1 low
digitalWrite(IN2, LOW); // Set IN2 low
analogWrite(ENA, 0); // Set speed to 0
delay(2000); // Wait for 2 seconds
}
Motor not spinning:
Motor spins in the wrong direction:
Motor speed is inconsistent:
Motor overheats:
Can I use this motor and wheels with a Raspberry Pi? Yes, but you will need a motor driver or H-bridge circuit to interface the motor with the Raspberry Pi's GPIO pins.
What type of power supply should I use? Use a power supply that matches the motor's voltage rating and provides sufficient current (e.g., 12V, 2A for a typical DC motor).
How do I calculate the required torque for my application?
Torque depends on the load and wheel size. Use the formula:Torque (Nm) = Force (N) × Radius (m)
where Force is the weight or resistance the motor needs to overcome.
Can I control multiple motors with one Arduino? Yes, you can control multiple motors using a multi-channel motor driver (e.g., L298N or L293D). Ensure the Arduino has enough GPIO pins for all motor control signals.