Hello, with my arduino UNO, I want to control a DC motor. It’s pretty basic, I want it to reverse and go forward at certain points in time. I used this useful tutorial on how to do it with an H-Bridge: http://itp.nyu.edu/physcomp/Labs/DCMotorControl
For the most part, it kinda works. I have encountered a couple of problems.
First of all, my enablePin doesn’t influence anything. I tried to make 2 speeds, slow and fast. I saw online that you can do this with analogWrite and the enable pin. But with whatever value I put to my enable pin (0, 400, 500, 1000…), the motor always spins full speed.
Which brings me to me second problem, the reverse and forward doesn’t have the same speed. My reverse goes faster than my forward (with the same enablePin value). Which makes everything more complicated.
Do you have any idea why I have those 2 problems? Here’s my code if it helps understand my problem:
int motorPin1=5;
int motorPin2=4;
int enablePin=6;
void setup() {
//setup everything with everything off
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(enablePin, LOW);
}
void loop() {
//go forward slowly
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
analogWrite(enablePin, 450);
delay(3000);
//go reverse fast
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
analogWrite(enablePin, 1000);
delay(3000);
//go reverse slowly
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
analogWrite(enablePin, 450);
delay(3000);
//go forward fast
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
analogWrite(enablePin, 1000);
delay(3000);
//STOP
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
delay(3000);
//repeat
}