Advertisement
microrobotics

Pololu Dual/Single Motor Driver Carrier 3.4A (TB67H420FTG)

Apr 22nd, 2023
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. The Pololu Dual/Single Motor Driver Carrier with TB67H420FTG from Toshiba is a versatile motor driver that can be configured to work either as a dual motor driver or a single motor driver with increased output current. The following example demonstrates how to use an Arduino to control two motors in dual motor driver configuration with the Pololu TB67H420FTG Motor Driver Carrier.
  3.  
  4. First, connect the Pololu TB67H420FTG Motor Driver Carrier to your Arduino as follows:
  5.  
  6. Connect the motor driver's VM pin to your motor power supply voltage (6-28V).
  7. Connect the motor driver's GND pin to both the Arduino ground and the motor power supply ground.
  8. Connect the motor driver's AIN1 pin to Arduino pin 2.
  9. Connect the motor driver's AIN2 pin to Arduino pin 3.
  10. Connect the motor driver's BIN1 pin to Arduino pin 4.
  11. Connect the motor driver's BIN2 pin to Arduino pin 5.
  12. Connect the motor driver's PWMA pin to Arduino pin 9.
  13. Connect the motor driver's PWMB pin to Arduino pin 10.
  14. Note: Make sure to connect the motors to the motor driver carrier following the instructions in the motor driver's user guide.
  15.  
  16. Next, upload the following code to your Arduino:
  17.  
  18. This code sets the appropriate control pins for the two motors (Motor A and Motor B) and initializes them as outputs. In the loop(), both motors are controlled to move forward, brake, move in reverse, and brake again in a repeating cycle.
  19.  
  20. Make sure you have the motors connected correctly to the motor driver carrier and have the appropriate power supply connected. After uploading the code to your Arduino, both motors should start moving as per the commands in the loop().
  21.  
  22. You can modify the code to control the motor speed and direction based on other inputs or events according to your project requirements. To control the motor speed, adjust the PWM values (0 to 255) passed to the analogWrite() function.
  23. */
  24.  
  25. // Motor A pins
  26. const int AIN1 = 2;
  27. const int AIN2 = 3;
  28. const int PWMA = 9;
  29.  
  30. // Motor B pins
  31. const int BIN1 = 4;
  32. const int BIN2 = 5;
  33. const int PWMB = 10;
  34.  
  35. void setup() {
  36.   // Set motor control pins as outputs
  37.   pinMode(AIN1, OUTPUT);
  38.   pinMode(AIN2, OUTPUT);
  39.   pinMode(PWMA, OUTPUT);
  40.   pinMode(BIN1, OUTPUT);
  41.   pinMode(BIN2, OUTPUT);
  42.   pinMode(PWMB, OUTPUT);
  43. }
  44.  
  45. void loop() {
  46.   // Move both motors forward at full speed
  47.   digitalWrite(AIN1, HIGH);
  48.   digitalWrite(AIN2, LOW);
  49.   analogWrite(PWMA, 255);
  50.  
  51.   digitalWrite(BIN1, HIGH);
  52.   digitalWrite(BIN2, LOW);
  53.   analogWrite(PWMB, 255);
  54.  
  55.   delay(2000);
  56.  
  57.   // Stop both motors (brake)
  58.   digitalWrite(AIN1, LOW);
  59.   digitalWrite(AIN2, LOW);
  60.   digitalWrite(BIN1, LOW);
  61.   digitalWrite(BIN2, LOW);
  62.  
  63.   delay(1000);
  64.  
  65.   // Move both motors in reverse at full speed
  66.   digitalWrite(AIN1, LOW);
  67.   digitalWrite(AIN2, HIGH);
  68.   analogWrite(PWMA, 255);
  69.  
  70.   digitalWrite(BIN1, LOW);
  71.   digitalWrite(BIN2, HIGH);
  72.   analogWrite(PWMB, 255);
  73.  
  74.   delay(2000);
  75.  
  76.   // Stop both motors (brake)
  77.   digitalWrite(AIN1, LOW);
  78.   digitalWrite(AIN2, LOW);
  79.   digitalWrite(BIN1, LOW);
  80.   digitalWrite(BIN2, LOW);
  81.  
  82.   delay(1000);
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement