Advertisement
microrobotics

MDD20A Dual Channel 20A Motor Driver

Jul 24th, 2023
995
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. The MDD20A Dual Channel 20A Motor Driver from Cytron supports multiple communication interfaces including PWM, Analog, UART, I2C, and RC.
  3.  
  4. In this script, the motors will move forward at full speed for 2 seconds, stop for 2 seconds, move backward at full speed for 2 seconds, and then stop for 2 seconds. This cycle repeats indefinitely.
  5.  
  6. Remember to connect the GND of the driver to the GND of the Arduino, and to supply the driver with an appropriate power source.
  7.  
  8. The pin numbers in the script are placeholders, so ensure to replace them with the actual numbers according to your setup.
  9.  
  10. Let's provide an example of how to control the MDD20A motor driver using PWM with an Arduino.
  11. */
  12.  
  13. // Motor 1
  14. const int M1PWM = 9;  // PWM Pin
  15. const int M1DIR = 8;  // Direction Pin
  16.  
  17. // Motor 2
  18. const int M2PWM = 10;  // PWM Pin
  19. const int M2DIR = 7;  // Direction Pin
  20.  
  21. void setup() {
  22.   // Set all the motor control pins as outputs
  23.   pinMode(M1DIR, OUTPUT);
  24.   pinMode(M1PWM, OUTPUT);
  25.   pinMode(M2DIR, OUTPUT);
  26.   pinMode(M2PWM, OUTPUT);
  27. }
  28.  
  29. void loop() {
  30.   // Move motors forward at full speed
  31.   digitalWrite(M1DIR, HIGH);
  32.   analogWrite(M1PWM, 255);
  33.   digitalWrite(M2DIR, HIGH);
  34.   analogWrite(M2PWM, 255);
  35.  
  36.   delay(2000);  // Wait for 2 seconds
  37.  
  38.   // Stop motors
  39.   analogWrite(M1PWM, 0);
  40.   analogWrite(M2PWM, 0);
  41.  
  42.   delay(2000);  // Wait for 2 seconds
  43.  
  44.   // Move motors backwards at full speed
  45.   digitalWrite(M1DIR, LOW);
  46.   analogWrite(M1PWM, 255);
  47.   digitalWrite(M2DIR, LOW);
  48.   analogWrite(M2PWM, 255);
  49.  
  50.   delay(2000);  // Wait for 2 seconds
  51.  
  52.   // Stop motors
  53.   analogWrite(M1PWM, 0);
  54.   analogWrite(M2PWM, 0);
  55.  
  56.   delay(2000);  // Wait for 2 seconds
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement