Hi, so for a project I'm trying to drive two HS-322HD servos using a L293 H-bridge.
I have an Arduino to power the chip with 5V, and am using another 5V power supply to power the motors through the H-bridge. My servos (broken, so they can spin continuously) are barely turning; if they turn at all.
I was wondering if there is a voltage drop or something on the H-bridge that is causing the servos to not get enough power?
Thanks in advance.
My code (if needed):
#define trigPin 13
#define motor1Pin1 4
#define motor1Pin2 3
#define motor2Pin1 6
#define motor2Pin2 5
#define enablePin 9
#define echoPin 12
#define button 7
#define ledPin 8
long duration, distance, light, average1=0, average2=0, average3=0;
double buttonState, Value1, Value2, Value3, Value4, Value5;
int JohnDon=0;
void setup()
{ Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(motor2Pin1, OUTPUT);
pinMode(motor2Pin2, OUTPUT);
pinMode(enablePin, OUTPUT);
pinMode(A4, INPUT);
pinMode(7, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
digitalWrite(ledPin, LOW);
buttonState = digitalRead(button);
int ldrStatus=analogRead(A4);
if (JohnDon==0){ //This part is for calibration
while (buttonState == LOW) {
buttonState = digitalRead(button);
}
digitalWrite(ledPin, HIGH);
delay(3000);
Value1 = analogRead(A4);
delay(5);
Value2 = analogRead(A4);
delay(5);
Value3 = analogRead(A4);
delay(5);
Value4 = analogRead(A4);
delay(5);
Value5 = analogRead(A4);
digitalWrite(ledPin, LOW);
average1 = (Value1+Value2+Value3+Value4+Value5)/5;
delay(1000);
digitalWrite(ledPin, HIGH);
delay(3000);
Value1 = analogRead(A4);
delay(5);
Value2 = analogRead(A4);
delay(5);
Value3 = analogRead(A4);
delay(5);
Value4 = analogRead(A4);
delay(5);
Value5 = analogRead(A4);
digitalWrite(ledPin, LOW);
average2 = (Value1+Value2+Value3+Value4+Value5)/5;
average3 = (average1 + average2)/2;
delay(1000);
JohnDon=1;
}
if (ldrStatus <= average3){
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor1Pin2, LOW);
digitalWrite(motor2Pin2, LOW);
}
else{
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
digitalWrite(enablePin, HIGH);
if (distance < 20)
{ digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor2Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
digitalWrite(motor2Pin2, LOW);
Serial.print("Wheels: Reverse ");
}
else if (distance > 25) {
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor1Pin2, HIGH);
digitalWrite(motor2Pin2, HIGH);
Serial.print("Wheels: Forward ");
}
else{
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, LOW);
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, LOW);
Serial.print("Wheels: Stopped ");
}
delay(500);
}
}