Advertisement
microrobotics

MDDS30 Dual Motor Driver - 30A, 7-35V

Jul 24th, 2023
929
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Here's an example of using the PWM interface with an Arduino.
  3.  
  4. This code will make two motors go full speed forward, stop, full speed reverse, and stop, each for one second.
  5.  
  6. It uses digitalWrite to control the direction pins, which determine the direction of the motors. It uses analogWrite to control the speed of the motors. In the Arduino language, analogWrite values range from 0 (always off) to 255 (always on).
  7.  
  8. Please adapt the pin numbers and rest of the code according to your exact setup and requirements.
  9.  
  10. Also, remember to connect the GND of the driver to the GND of the Arduino, and to supply the driver with an appropriate power source.
  11. */
  12.  
  13. const int M1DIR = 8;  // Motor 1 Direction
  14. const int M1PWM = 9;  // Motor 1 PWM
  15. const int M2DIR = 12; // Motor 2 Direction
  16. const int M2PWM = 11; // Motor 2 PWM
  17.  
  18. void setup() {
  19.   pinMode(M1DIR, OUTPUT);
  20.   pinMode(M1PWM, OUTPUT);
  21.   pinMode(M2DIR, OUTPUT);
  22.   pinMode(M2PWM, OUTPUT);
  23. }
  24.  
  25. void loop() {
  26.   // Full speed forward
  27.   digitalWrite(M1DIR, HIGH);
  28.   analogWrite(M1PWM, 255);
  29.   digitalWrite(M2DIR, HIGH);
  30.   analogWrite(M2PWM, 255);
  31.   delay(1000);
  32.  
  33.   // Stop
  34.   analogWrite(M1PWM, 0);
  35.   analogWrite(M2PWM, 0);
  36.   delay(1000);
  37.  
  38.   // Full speed reverse
  39.   digitalWrite(M1DIR, LOW);
  40.   analogWrite(M1PWM, 255);
  41.   digitalWrite(M2DIR, LOW);
  42.   analogWrite(M2PWM, 255);
  43.   delay(1000);
  44.  
  45.   // Stop
  46.   analogWrite(M1PWM, 0);
  47.   analogWrite(M2PWM, 0);
  48.   delay(1000);
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement