Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- The Pololu Dual VNH5019 Motor Driver Shield for Arduino allows you to control two high-power DC motors using an Arduino Uno or compatible board. The following example demonstrates how to use an Arduino to control two motors with the Pololu Dual VNH5019 Motor Driver Shield.
- First, stack the Pololu Dual VNH5019 Motor Driver Shield on top of your Arduino Uno or compatible board, making sure that the pins are correctly aligned.
- Next, upload the following code to your Arduino:
- 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.
- Make sure you have the motors connected correctly to the motor driver shield 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().
- 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.
- */
- // Motor A pins
- const int AIN1 = 2;
- const int AIN2 = 4;
- const int PWMA = 9;
- // Motor B pins
- const int BIN1 = 7;
- const int BIN2 = 8;
- const int PWMB = 10;
- void setup() {
- // Set motor control pins as outputs
- pinMode(AIN1, OUTPUT);
- pinMode(AIN2, OUTPUT);
- pinMode(PWMA, OUTPUT);
- pinMode(BIN1, OUTPUT);
- pinMode(BIN2, OUTPUT);
- pinMode(PWMB, OUTPUT);
- }
- void loop() {
- // Move both motors forward at full speed
- digitalWrite(AIN1, HIGH);
- digitalWrite(AIN2, LOW);
- analogWrite(PWMA, 255);
- digitalWrite(BIN1, HIGH);
- digitalWrite(BIN2, LOW);
- analogWrite(PWMB, 255);
- delay(2000);
- // Stop both motors (brake)
- digitalWrite(AIN1, LOW);
- digitalWrite(AIN2, LOW);
- digitalWrite(BIN1, LOW);
- digitalWrite(BIN2, LOW);
- delay(1000);
- // Move both motors in reverse at full speed
- digitalWrite(AIN1, LOW);
- digitalWrite(AIN2, HIGH);
- analogWrite(PWMA, 255);
- digitalWrite(BIN1, LOW);
- digitalWrite(BIN2, HIGH);
- analogWrite(PWMB, 255);
- delay(2000);
- // Stop both motors (brake)
- digitalWrite(AIN1, LOW);
- digitalWrite(AIN2, LOW);
- digitalWrite(BIN1, LOW);
- digitalWrite(BIN2, LOW);
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement