Advertisement
microrobotics

Makerbase H-Bridge Motor Controller 36V 15A

Jul 24th, 2023
1,148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. The Makerbase H-Bridge Motor Controller is a common motor controller that can be used to control the direction and speed of a DC motor using PWM. Here's an example of how you can use it with an Arduino:
  3.  
  4. This script will make the motor turn in one direction for a second, stop for a second, then turn in the opposite direction for a second, and then stop again. This cycle repeats indefinitely.
  5.  
  6. Please adjust the pin numbers and rest of the code according to your exact setup and requirements. Also, remember to connect the GND of the motor driver to the GND of the Arduino, and to supply the driver with an appropriate power source.
  7. */
  8.  
  9. // Define pin connections & motor's states
  10. const int motorPin1 = 9;  // Pin connected to Motor Driver's Input 1
  11. const int motorPin2 = 10; // Pin connected to Motor Driver's Input 2
  12.  
  13. void setup() {
  14.   // Sets the two pins as Outputs
  15.   pinMode(motorPin1, OUTPUT);
  16.   pinMode(motorPin2, OUTPUT);
  17. }
  18.  
  19. void loop(){
  20.   // Drive the motor clockwise
  21.   digitalWrite(motorPin1, HIGH);
  22.   digitalWrite(motorPin2, LOW);
  23.   delay(1000); // Wait for 1 second
  24.  
  25.   // Stop the motor when motorPin1 & motorPin2 are HIGH or LOW
  26.   digitalWrite(motorPin1, HIGH);
  27.   digitalWrite(motorPin2, HIGH);
  28.   delay(1000); // Wait for 1 second
  29.  
  30.   // Drive the motor counterclockwise
  31.   digitalWrite(motorPin1, LOW);
  32.   digitalWrite(motorPin2, HIGH);
  33.   delay(1000); // Wait for 1 second
  34.  
  35.   // Stop the motor when motorPin1 & motorPin2 are HIGH or LOW
  36.   digitalWrite(motorPin1, HIGH);
  37.   digitalWrite(motorPin2, HIGH);
  38.   delay(1000); // Wait for 1 second
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement