Advertisement
microrobotics

BTS7960 Power H-bridge 43 Amp Module

Apr 26th, 2023
2,499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. The BTS7960 is a high-current H-bridge module that can be used to control motors or other high-current loads with an Arduino. Here's an example code that demonstrates how to control a motor using a BTS7960 H-bridge module and an Arduino:
  3.  
  4. Hardware Setup:
  5.  
  6. Connect the BTS7960 module's R_EN (Right Enable) pin to digital pin 9 on the Arduino.
  7. Connect the BTS7960 module's L_EN (Left Enable) pin to digital pin 10 on the Arduino.
  8. Connect the BTS7960 module's RPWM (Right PWM) pin to digital pin 6 on the Arduino.
  9. Connect the BTS7960 module's LPWM (Left PWM) pin to digital pin 5 on the Arduino.
  10. Connect the BTS7960 module's Vcc pin to the Arduino's 5V pin.
  11. Connect the BTS7960 module's GND pin to the Arduino's GND pin.
  12. Connect the motor to the M+ and M- terminals of the BTS7960 module.
  13. Connect a suitable power supply to the BTS7960 module's B+ and B- terminals. Make sure the power supply voltage and current ratings are appropriate for the motor.
  14.  
  15. This code controls a motor using a BTS7960 H-bridge module and an Arduino. The motor will move forward for 2 seconds, stop for 1 second, move backward for 2 seconds, and then stop for 1 second. This sequence will repeat indefinitely. You can adjust the speed of the motor by changing the values passed to the analogWrite() function.
  16. */
  17.  
  18. const int rightEnablePin = 9;
  19. const int leftEnablePin = 10;
  20. const int rightPWMPin = 6;
  21. const int leftPWMPin = 5;
  22.  
  23. void setup() {
  24.   pinMode(rightEnablePin, OUTPUT);
  25.   pinMode(leftEnablePin, OUTPUT);
  26.   pinMode(rightPWMPin, OUTPUT);
  27.   pinMode(leftPWMPin, OUTPUT);
  28. }
  29.  
  30. void loop() {
  31.   // Move the motor forward
  32.   digitalWrite(rightEnablePin, HIGH);
  33.   digitalWrite(leftEnablePin, LOW);
  34.   analogWrite(rightPWMPin, 255); // Full speed (change this value for different speeds)
  35.   analogWrite(leftPWMPin, 0);
  36.   delay(2000); // Move forward for 2 seconds
  37.  
  38.   // Stop the motor
  39.   digitalWrite(rightEnablePin, LOW);
  40.   digitalWrite(leftEnablePin, LOW);
  41.   delay(1000); // Stop for 1 second
  42.  
  43.   // Move the motor backward
  44.   digitalWrite(rightEnablePin, LOW);
  45.   digitalWrite(leftEnablePin, HIGH);
  46.   analogWrite(rightPWMPin, 0);
  47.   analogWrite(leftPWMPin, 255); // Full speed (change this value for different speeds)
  48.   delay(2000); // Move backward for 2 seconds
  49.  
  50.   // Stop the motor
  51.   digitalWrite(rightEnablePin, LOW);
  52.   digitalWrite(leftEnablePin, LOW);
  53.   delay(1000); // Stop for 1 second
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement