Battery: 12v
Adafruit DRV8871 motor drive
Arduino uno
Problem:
When i run this code, it only runs a single direction. and when i switch the HIGH to LOW, it doesnt move anything even though i want it to move it the other direction.
#define MOTOR_IN1 10
#define MOTOR_IN2 9
void setup() {
Serial.begin(9600);
Serial.println("DRV8871 test");
pinMode(MOTOR_IN1, OUTPUT);
pinMode(MOTOR_IN2, OUTPUT);
}
void loop() {
int time = 1000;
int initial = 255;
digitalWrite(MOTOR_IN1, LOW);
analogWrite(MOTOR_IN2, initial);
delay(time);
analogWrite(MOTOR_IN2, 0);
for(int i = 255; i >= 0; i--){
analogWrite(MOTOR_IN2, i);
delay(5);
}
delay(100000);
}
A pencil drawing is good. Start with a box representing the Arduino, write the pins you are using, draw wires to other devices and show which pins the other devices are using. Take a photo. Post the photo.
You have only half the code from the Adafruit example sketch. If you use the complete code the motor speed will ramp up in one direction, pause for one second, ramp down to zero speed, pause for ten seconds and then ramp up and down in the opposite direction.
I am not sure what this means. Is it a question or a statement? Did you get your motor running in both directions?
For further information, the use of the Uno 5 volts out to provide power to the motor driver, as shown in the Adafruit documentation, is not advisable. A DC motor draws too much current and the Uno cannot supply it.
Looking at your photo of your layout it appears that you have the motor driver connected properly. Are you using the coaxial connector to provide power to the Uno when not powered by the USB power?
The part I cannot understand is at the lower left of the photo. What are the wires from the Uno to the black plug going to?
when i am actually powering it,i have the 12 v batteries connected to the circular plug, after i put to code into the arduino with the usb. (also no, it doesnt go the other direction sadly :C) The circular black plug is going into the arduino to power it. if u are talking about the other rectangular looking ones, they are going into the motor.