Advertisement
microrobotics

Pololu MP6550 DC Motor Controller

Apr 3rd, 2023
1,122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. The Pololu MP6550 DC Motor Controller is a compact, single-channel motor driver that can control one brushed DC motor. It is designed to work with a wide range of input voltages and has a peak output current of 2.5A.
  3.  
  4. Here's an example code for controlling a DC motor using an Arduino and the Pololu MP6550 DC Motor Controller:
  5.  
  6. In this example, we define the direction (DIR) and pulse-width modulation (PWM) pins connected to the Arduino. The setMotorSpeed function controls the motor speed and direction by setting the DIR pin and sending a PWM signal to the PWM pin.
  7.  
  8. The loop function runs the motor at half speed forward, stops the motor, runs the motor at half speed in reverse, and stops the motor again. This sequence repeats indefinitely.
  9.  
  10. To use this code, connect the Pololu MP6550 DC Motor Controller to an Arduino as follows:
  11.  
  12. DIR_pin (Arduino) -> DIR (Pololu MP6550)
  13. PWM_pin (Arduino) -> PWM (Pololu MP6550)
  14. GND (Arduino) -> GND (Pololu MP6550)
  15. VM (Pololu MP6550) -> Power supply positive terminal
  16. GND (Pololu MP6550) -> Power supply negative terminal
  17. OUTA (Pololu MP6550) -> Motor terminal A
  18. OUTB (Pololu MP6550) -> Motor terminal B
  19. Upload the code to the Arduino and observe the motor's behavior.
  20. */
  21.  
  22. #include <Arduino.h>
  23.  
  24. const int DIR_pin = 2; // Direction Pin
  25. const int PWM_pin = 3; // PWM Pin
  26.  
  27. void setup() {
  28.   pinMode(DIR_pin, OUTPUT);
  29.   pinMode(PWM_pin, OUTPUT);
  30.   Serial.begin(9600);
  31. }
  32.  
  33. void setMotorSpeed(int speed) {
  34.   if (speed > 0) {
  35.     digitalWrite(DIR_pin, HIGH);
  36.   } else {
  37.     digitalWrite(DIR_pin, LOW);
  38.     speed = -speed;
  39.   }
  40.   analogWrite(PWM_pin, speed);
  41. }
  42.  
  43. void loop() {
  44.   int speed;
  45.  
  46.   // Run the motor at half speed forward
  47.   speed = 128;
  48.   Serial.println("Forward at half speed");
  49.   setMotorSpeed(speed);
  50.   delay(3000);
  51.  
  52.   // Stop the motor
  53.   speed = 0;
  54.   Serial.println("Stop");
  55.   setMotorSpeed(speed);
  56.   delay(1000);
  57.  
  58.   // Run the motor at half speed reverse
  59.   speed = -128;
  60.   Serial.println("Reverse at half speed");
  61.   setMotorSpeed(speed);
  62.   delay(3000);
  63.  
  64.   // Stop the motor
  65.   speed = 0;
  66.   Serial.println("Stop");
  67.   setMotorSpeed(speed);
  68.   delay(1000);
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement