Motorsteuerung mit einem H-Bridge IC

Made with Fritzing.org

Made with Fritzing.org

H-Bridge steuert einen Motor

H-Bridge steuert einen Motor

Da eine selbst gebaute H-Bridge relativ viele Teile benötigt, bietet es sich an, einen IC zu verwenden. Gängiges Modell ist der L293D, der zwei Motoren unabhängig von einander steuern kann. Es handelt sich um einen IC im DIL16 Gehäuse, d.h. er hat 16 Beinchen.

Auf einer Platine werden die inneren Beinchen (Pin 4,5,12,13) mit dem GND verbunden und dienen der Wärmeableitung. Auf dem Breadboard muss nur eines der vier mit dem GND verbunden werden.

Im Beispiel werden zwei Motoren vom Arduino gesteuert. Der Strom kommt aus einer Batterie. Natürlich kann hier auch Netzteil verwendet werden. Wenn es sich um kleine Motoren handelt (z.B. Vibrationsmotoren), können diese auch direkt vom Arduino mit Strom versorgt werden. Hierfür muss in der Schaltung lediglich das orange Kabel an der H-Brigde mit dem 5V+ verbunden werden.

Die H-Bridge L293D hält einen kurzzeitigen Strom von 1,2 A und einen dauerhaften Storm von 600 mA pro Kanal aus.

Ein großer Vorteil der L293D sind die integrierten Dioden, die Induktionsströme abfangen, die beim Nachdrehen des Motors entstehen.

Sollten höhere Ströme erreicht werden, sollte man auf die Verwendung eines alternativen ICs zurückgreifen. Hier bietet sich z.B. der L6205N an.

Ein Beispielcode:


int motor1_A=11;
int motor1_B=10;
int motor1_Speed=9;

int motor2_A=5;
int motor2_B=4;
int motor2_Speed=3;

void setup(){
pinMode(motor1_A,OUTPUT);
pinMode(motor1_B,OUTPUT);

pinMode(motor2_A,OUTPUT);
pinMode(motor2_B,OUTPUT);
}

void loop(){
// motor1
for (int i=0; i<256; i+=5){
digitalWrite(motor1_A,HIGH); // A = HIGH and B = LOW means the motor will turn right
digitalWrite(motor1_B,LOW);
analogWrite(motor1_Speed,i); // speed counts from 0 to 255
delay(20);
}
for (int i=255; i>0; i-=5){
digitalWrite(motor1_A,HIGH); // A = HIGH and B = LOW means the motor will turn right
digitalWrite(motor1_B,LOW);
analogWrite(motor1_Speed,i); // speed counts from 0 to 255
delay(20);
}
// motor2
for (int i=0; i<256; i+=5){
digitalWrite(motor2_A,HIGH); // A = HIGH and B = LOW means the motor will turn right
digitalWrite(motor2_B,LOW);
analogWrite(motor2_Speed,i); // speed counts from 0 to 255
delay(20);
}
for (int i=255; i>0; i-=5){
digitalWrite(motor2_A,HIGH); // A = HIGH and B = LOW means the motor will turn right
digitalWrite(motor2_B,LOW);
analogWrite(motor2_Speed,i); // speed counts from 0 to 255
delay(20);
}

// turn vice versa

// motor1
for (int i=0; i<256; i+=5){
digitalWrite(motor1_A,LOW); // A = LOW and B = HIGH means the motor will turn left
digitalWrite(motor1_B,HIGH);
analogWrite(motor1_Speed,i); // speed counts from 0 to 255
delay(20);
}
for (int i=255; i>0; i-=5){
digitalWrite(motor1_A,LOW); // A = LOW and B = HIGH means the motor will turn left
digitalWrite(motor1_B,HIGH);
analogWrite(motor1_Speed,i); // speed counts from 0 to 255
delay(20);
}
// motor2
for (int i=0; i<256; i+=5){
digitalWrite(motor2_A,LOW); // A = LOW and B = HIGH means the motor will turn left
digitalWrite(motor2_B,HIGH);
analogWrite(motor2_Speed,i); // speed counts from 0 to 255
delay(20);
}
for (int i=255; i>0; i-=5){
digitalWrite(motor2_A,LOW); // A = LOW and B = HIGH means the motor will turn left
digitalWrite(motor2_B,HIGH);
analogWrite(motor2_Speed,i); // speed counts from 0 to 255
delay(20);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>