Hi. I'm struggling with a DC Motor. (I'm new at this).
No matter what I do, my DC motor only turns CW - and not when it's supposed to. See my comments on actual results inside my code.
Hardware setup:
Arduino Mega R3 with power from USB.
DBH-12V Motor controller.
Small 12V DC motor.
Currently 100% of the power is coming from the USB. (5V+/- jumpers from Mega to Motor controller. Then motor plugged into Motor A on the controller).
Ultimately this will all be setup on a 12V battery but am still troubleshooting.
It seems like maybe the controller is misunderstanding the HIGH/LOW signals from the controller? Can (or should) I somehow redefine the outputs from the Arduino? I'm super confused.
I'm especially struggling because I can't find any documentation on this motor controller. (But I needed to select it because it had a higher amp rating which I need for my project).
See my test code below.
//Outputs for my motor.
int motor1pin1 = 5;
int motor1pin2 = 6;
int enA = 4;
void setup() {
// put your setup code here, to run once:
pinMode(motor1pin1, OUTPUT);
pinMode(motor1pin2, OUTPUT);
pinMode(enA, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
//Actual result from code below: Motor turns CW slow for longer duration.
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
analogWrite(enA, 125);
delay(1000);
//Actual result from code below: Motor stops.
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, HIGH);
analogWrite(enA, 250);
delay(1000);
//Actual result from code below: Motor turns CW fast for short duration.
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, LOW);
analogWrite(enA, 250);
delay(250);
//Actual result from code below: Motor stops.
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, HIGH);
analogWrite(enA, 150);
delay(1000);
}