Hi.
I posted questions regarding a motor driver 18v15 a couple of days ago and I got problems solved.
However, I ran into another problem using this motor driver.
I had 2 motors running fine with switches and these are connected to motor driver boards (6-24VDC Brush Motor
6A continuous 25A peak) . The motors do not turn unless a switch is activated through Arduino.
I added a third motor using the motor driver (18v15) from Pololu.
I did not add any switches on this one and programmed it so that it constantly runs, changing directions every 5 seconds.
The 2 motors that were working stopped responding. I looked at the Serial Monitor and I found out that Arduino is reading too slow. I see four 0s maybe in 30-40 secs. and then it stops for a minute or two. I had the switches read analog values so I changed it to digitalRead and it does not change the speed that Arduino reads the input pins.
Can you tell me why this is happening? I can’t tell if it is a programming issue or a hardware issue.
Thank you so much for your help in advance.
int Unit1switchPin = 4;
int Unit1switchPin2 = 5;
int Unit2switchPin = 2;
int Unit2switchPin2 = 3;
int Unit1switchVal = 0;
int Unit1switchVal2 = 0;
int Unit2switchVal = 0;
int Unit2switchVal2 = 0;
int pwmPin = 9 ;
int dirPin = 8;
// output pins
#define U1L1 10
#define U1H2 10
#define U1L2 11
#define U1H1 11
#define U2L1 12
#define U2H2 12
#define U2L2 13
#define U2H1 13
void setup(){
pinMode(Unit1switchPin, INPUT);
pinMode(Unit1switchPin2, INPUT);
pinMode(Unit2switchPin, INPUT);
pinMode(Unit2switchPin2, INPUT);
// motor stuff
pinMode(U1L1,OUTPUT);
pinMode(U1L2,OUTPUT);
pinMode(U1H1,OUTPUT);
pinMode(U1H2,OUTPUT);
pinMode(U2L1,OUTPUT);
pinMode(U2L2,OUTPUT);
pinMode(U2H1,OUTPUT);
pinMode(U2H2,OUTPUT);
pinMode(pwmPin, OUTPUT);
pinMode(dirPin, OUTPUT);
digitalWrite(pwmPin, HIGH);
Serial.begin(9600);
}
void loop(){
Unit1switchVal = digitalRead(Unit1switchPin);
Unit1switchVal2 = digitalRead(Unit1switchPin2);
Unit2switchVal = analogRead(Unit2switchPin);
Unit2switchVal2 = analogRead(Unit2switchPin2);
Serial.println(Unit1switchVal);
Serial.println(Unit1switchVal2);
Serial.println(Unit2switchVal);
Serial.println(Unit2switchVal2);
if(Unit1switchVal == 1){
motor_forward();
}
if(Unit1switchVal2 == 1){
motor_reverse();
}
if(Unit1switchVal == 0 && Unit1switchVal == 0){
motor_stop();
}
if(Unit2switchVal > 500 && Unit2switchVal2 < 500){
Unit2_motor_forward();
}
if(Unit2switchVal2 > 500 && Unit2switchVal < 500){
Unit2_motor_reverse();
}
if(Unit2switchVal > 500 && Unit2switchVal2 >500){
Unit2_motor_stop();
}
digitalWrite(dirPin, LOW);
delay(5000);
digitalWrite(dirPin, HIGH);
delay(5000);
}
// motor movement - self explained function names
void motor_forward () {
digitalWrite(U1H2,HIGH);
digitalWrite(U1L1,HIGH);
digitalWrite(U1H1,LOW);
digitalWrite(U1L2,LOW);
}
void motor_stop () {
digitalWrite(U1H2,LOW);
digitalWrite(U1L1,LOW);
digitalWrite(U1H1,LOW);
digitalWrite(U1L2,LOW);
}
void motor_reverse () {
digitalWrite(U1H2,LOW);
digitalWrite(U1L1,LOW);
digitalWrite(U1H1,HIGH);
digitalWrite(U1L2,HIGH);
}
void Unit2_motor_forward () {
digitalWrite(U2H2,HIGH);
digitalWrite(U2L1,HIGH);
digitalWrite(U2H1,LOW);
digitalWrite(U2L2,LOW);
}
void Unit2_motor_stop () {
digitalWrite(U2H2,LOW);
digitalWrite(U2L1,LOW);
digitalWrite(U2H1,LOW);
digitalWrite(U2L2,LOW);
}
void Unit2_motor_reverse () {
digitalWrite(U2H2,LOW);
digitalWrite(U2L1,LOW);
digitalWrite(U2H1,HIGH);
digitalWrite(U2L2,HIGH);
}