The XY-MD02 is a versatile motor driver module designed to control the speed and direction of DC motors. It is commonly used in robotics, automation projects, and various DIY applications where precise motor control is required. The module typically supports features such as variable speed control, bidirectional control, and dynamic braking, making it an essential component for projects that require reliable and efficient motor management.
Pin Number | Pin Name | Description |
---|---|---|
1 | VCC | Power supply for the motor (6V-30V) |
2 | GND | Ground connection |
3 | AIN1 | Direction control input 1 |
4 | AIN2 | Direction control input 2 |
5 | PWMA | PWM input for speed control |
6 | STBY | Standby mode activation (active low) |
7 | BIN1 | Direction control input for second motor (if applicable) |
8 | BIN2 | Direction control input for second motor (if applicable) |
9 | PWMB | PWM input for second motor speed control (if applicable) |
// Define control pins
const int pwmPin = 3; // PWMA pin connected to Arduino pin 3
const int dirPin1 = 4; // AIN1 pin connected to Arduino pin 4
const int dirPin2 = 5; // AIN2 pin connected to Arduino pin 5
void setup() {
// Set control pins as outputs
pinMode(pwmPin, OUTPUT);
pinMode(dirPin1, OUTPUT);
pinMode(dirPin2, OUTPUT);
}
void loop() {
// Set motor direction to forward
digitalWrite(dirPin1, HIGH);
digitalWrite(dirPin2, LOW);
// Ramp up the speed
for (int speed = 0; speed <= 255; speed++) {
analogWrite(pwmPin, speed);
delay(10);
}
// Ramp down the speed
for (int speed = 255; speed >= 0; speed--) {
analogWrite(pwmPin, speed);
delay(10);
}
// Change motor direction to reverse
digitalWrite(dirPin1, LOW);
digitalWrite(dirPin2, HIGH);
// Repeat the ramp up and down for reverse direction
for (int speed = 0; speed <= 255; speed++) {
analogWrite(pwmPin, speed);
delay(10);
}
for (int speed = 255; speed >= 0; speed--) {
analogWrite(pwmPin, speed);
delay(10);
}
}
This example demonstrates basic forward and reverse control of a DC motor using the XY-MD02 motor driver module with an Arduino UNO. The analogWrite
function is used to control the speed of the motor through PWM, while the digitalWrite
functions set the direction. The motor speed is ramped up and down in both forward and reverse directions.