Advertisement
microrobotics

BTS7960 High Power H-Bridge motor driver 43A

Apr 17th, 2023
1,414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Here's a basic example code for using an Arduino to control the Motor Driver 43A BTS7960. This code assumes that you have already connected the motor driver to the Arduino board as per the appropriate wiring. The code will make the motor run forward and backward with a 2-second delay between each movement.
  3.  
  4. Upload this code to your Arduino board and adjust the motorSpeed variable as necessary to control the motor speed. Make sure your connections and power supply are appropriate for the motor you're using.
  5. */
  6.  
  7. #include <Arduino.h>
  8.  
  9. // Pin assignments for the Arduino
  10. const int RPWM = 3; // Right PWM control, connected to Arduino pin 3
  11. const int LPWM = 5; // Left PWM control, connected to Arduino pin 5
  12. const int R_EN = 7; // Right enable, connected to Arduino pin 7
  13. const int L_EN = 8; // Left enable, connected to Arduino pin 8
  14.  
  15. void setup() {
  16.   pinMode(RPWM, OUTPUT); // Set RPWM pin as output
  17.   pinMode(LPWM, OUTPUT); // Set LPWM pin as output
  18.   pinMode(R_EN, OUTPUT); // Set R_EN pin as output
  19.   pinMode(L_EN, OUTPUT); // Set L_EN pin as output
  20.  
  21.   // Enable both sides of the H-bridge
  22.   digitalWrite(R_EN, HIGH);
  23.   digitalWrite(L_EN, HIGH);
  24. }
  25.  
  26. void loop() {
  27.   // Set motor speed
  28.   int motorSpeed = 200; // Adjust this value (0-255) to control the motor speed
  29.  
  30.   // Move motor forward
  31.   analogWrite(RPWM, motorSpeed);
  32.   analogWrite(LPWM, 0);
  33.   delay(2000); // Run the motor for 2 seconds
  34.  
  35.   // Stop motor
  36.   analogWrite(RPWM, 0);
  37.   analogWrite(LPWM, 0);
  38.   delay(1000); // Wait for 1 second
  39.  
  40.   // Move motor backward
  41.   analogWrite(RPWM, 0);
  42.   analogWrite(LPWM, motorSpeed);
  43.   delay(2000); // Run the motor for 2 seconds
  44.  
  45.   // Stop motor
  46.   analogWrite(RPWM, 0);
  47.   analogWrite(LPWM, 0);
  48.   delay(1000); // Wait for 1 second
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement